@dxos/react-ui-table 0.8.2-staging.7ac8446 → 0.8.2

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 (97) hide show
  1. package/dist/lib/browser/chunk-U6LL2AVU.mjs +26 -0
  2. package/dist/lib/browser/chunk-U6LL2AVU.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1115 -905
  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-TGG6OZ54.cjs → chunk-CXDGXPM6.cjs} +12 -12
  8. package/dist/lib/node/chunk-CXDGXPM6.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +1113 -906
  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-KKLP54L3.mjs → chunk-EFSM52KQ.mjs} +10 -10
  15. package/dist/lib/node-esm/chunk-EFSM52KQ.mjs.map +7 -0
  16. package/dist/lib/node-esm/index.mjs +1115 -905
  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/CreateRefPanel.d.ts.map +1 -1
  23. package/dist/types/src/components/Table/DynamicTable.d.ts +3 -4
  24. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
  25. package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
  26. package/dist/types/src/components/Table/Table.d.ts +2 -0
  27. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  28. package/dist/types/src/components/Table/Table.stories.d.ts +1 -0
  29. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  30. package/dist/types/src/components/Table/relations.stories.d.ts.map +1 -1
  31. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +13 -0
  32. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -0
  33. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +3 -0
  34. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  35. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  36. package/dist/types/src/components/TableCellEditor/extension.d.ts.map +1 -1
  37. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +6 -3
  38. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
  39. package/dist/types/src/components/testing.d.ts +40 -40
  40. package/dist/types/src/components/testing.d.ts.map +1 -1
  41. package/dist/types/src/hooks/useTableModel.d.ts +2 -2
  42. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  43. package/dist/types/src/model/modal-controller.d.ts +3 -3
  44. package/dist/types/src/model/modal-controller.d.ts.map +1 -1
  45. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  46. package/dist/types/src/model/table-model.d.ts.map +1 -1
  47. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  48. package/dist/types/src/types/table.d.ts +46 -45
  49. package/dist/types/src/types/table.d.ts.map +1 -1
  50. package/dist/types/src/util/dynamic-table.d.ts +4 -3
  51. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  52. package/dist/types/src/util/index.d.ts +1 -0
  53. package/dist/types/src/util/index.d.ts.map +1 -1
  54. package/dist/types/src/util/schema.d.ts +12 -0
  55. package/dist/types/src/util/schema.d.ts.map +1 -0
  56. package/dist/types/src/util/signals.d.ts.map +1 -1
  57. package/dist/types/src/util/table-buttons.d.ts +0 -14
  58. package/dist/types/src/util/table-buttons.d.ts.map +1 -1
  59. package/dist/types/src/util/table-controls.d.ts.map +1 -1
  60. package/dist/types/src/util/table.d.ts +2 -2
  61. package/dist/types/src/util/table.d.ts.map +1 -1
  62. package/dist/types/src/util/tag.d.ts +11 -0
  63. package/dist/types/src/util/tag.d.ts.map +1 -0
  64. package/dist/types/tsconfig.tsbuildinfo +1 -1
  65. package/package.json +41 -34
  66. package/src/components/Table/CreateRefPanel.tsx +5 -5
  67. package/src/components/Table/DynamicTable.stories.tsx +4 -4
  68. package/src/components/Table/DynamicTable.tsx +4 -5
  69. package/src/components/Table/Table.stories.tsx +84 -50
  70. package/src/components/Table/Table.tsx +25 -28
  71. package/src/components/Table/relations.stories.tsx +38 -32
  72. package/src/components/TableCellEditor/FormCellEditor.tsx +94 -0
  73. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +13 -11
  74. package/src/components/TableCellEditor/TableCellEditor.tsx +45 -4
  75. package/src/components/TableToolbar/TableToolbar.tsx +65 -35
  76. package/src/components/testing.ts +10 -9
  77. package/src/hooks/useTableModel.ts +6 -4
  78. package/src/model/modal-controller.ts +3 -3
  79. package/src/model/selection-model.ts +1 -1
  80. package/src/model/table-model.test.ts +7 -6
  81. package/src/model/table-model.ts +20 -3
  82. package/src/model/table-presentation.test.ts +7 -6
  83. package/src/model/table-presentation.ts +54 -10
  84. package/src/types/table.ts +16 -11
  85. package/src/util/dynamic-table.ts +9 -6
  86. package/src/util/index.ts +1 -0
  87. package/src/util/schema.ts +36 -0
  88. package/src/util/table-buttons.ts +1 -24
  89. package/src/util/table.ts +13 -16
  90. package/src/util/tag.ts +33 -0
  91. package/dist/lib/browser/chunk-YWNRUF4J.mjs +0 -26
  92. package/dist/lib/browser/chunk-YWNRUF4J.mjs.map +0 -7
  93. package/dist/lib/node/chunk-TGG6OZ54.cjs.map +0 -7
  94. package/dist/lib/node-esm/chunk-KKLP54L3.mjs.map +0 -7
  95. package/dist/types/src/components/Table/RefPanel.d.ts +0 -9
  96. package/dist/types/src/components/Table/RefPanel.d.ts.map +0 -1
  97. package/src/components/Table/RefPanel.tsx +0 -52
@@ -2,7 +2,7 @@ import { createRequire } from 'node:module';const require = createRequire(import
2
2
  import {
3
3
  TableSchema,
4
4
  TableType
5
- } from "./chunk-KKLP54L3.mjs";
5
+ } from "./chunk-EFSM52KQ.mjs";
6
6
 
7
7
  // packages/ui/react-ui-table/src/translations.ts
8
8
  var translationKey = "table";
@@ -37,258 +37,245 @@ var translations_default = [
37
37
  ];
38
38
 
39
39
  // packages/ui/react-ui-table/src/components/Table/Table.tsx
40
- import React7, { forwardRef, useCallback as useCallback4, useImperativeHandle, useState as useState2, useMemo as useMemo4, useEffect as useEffect2 } from "react";
40
+ import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
41
+ import React7, { forwardRef, useCallback as useCallback5, useImperativeHandle, useState as useState2, useMemo as useMemo5, useEffect as useEffect3 } from "react";
41
42
  import { getValue as getValue4 } from "@dxos/echo-schema";
42
- import { invariant as invariant3 } from "@dxos/invariant";
43
+ import { invariant as invariant4 } from "@dxos/invariant";
43
44
  import { Filter } from "@dxos/react-client/echo";
44
45
  import { useTranslation as useTranslation3 } from "@dxos/react-ui";
45
46
  import { useAttention } from "@dxos/react-ui-attention";
46
- import { closestCell, Grid } from "@dxos/react-ui-grid";
47
+ import { closestCell, Grid, gridSeparatorInlineEnd, gridSeparatorBlockEnd } from "@dxos/react-ui-grid";
47
48
  import { mx as mx2 } from "@dxos/react-ui-theme";
48
49
  import { isNotFalsy, safeParseInt } from "@dxos/util";
49
50
 
50
51
  // packages/ui/react-ui-table/src/components/Table/ColumnActionsMenu.tsx
52
+ import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
51
53
  import React from "react";
52
54
  import { DropdownMenu, useTranslation } from "@dxos/react-ui";
53
55
  var ColumnActionsMenu = ({ model, modals }) => {
54
- const { t } = useTranslation(translationKey);
55
- const state = modals.state.value;
56
- if (state?.type !== "column") {
57
- return null;
58
- }
59
- const currentSort = model.sorting?.sorting;
60
- const isCurrentColumnSorted = currentSort?.fieldId === state.fieldId;
61
- return /* @__PURE__ */ React.createElement(DropdownMenu.Root, {
62
- modal: false,
63
- open: true,
64
- onOpenChange: modals.close
65
- }, /* @__PURE__ */ React.createElement(DropdownMenu.VirtualTrigger, {
66
- virtualRef: modals.trigger
67
- }), /* @__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, {
68
- "data-testid": "column-sort-descending",
69
- onClick: () => model.sorting?.setSort(state.fieldId, "desc")
70
- }, t("column action sort descending")), (!isCurrentColumnSorted || currentSort?.direction === "desc") && /* @__PURE__ */ React.createElement(DropdownMenu.Item, {
71
- "data-testid": "column-sort-ascending",
72
- onClick: () => model.sorting?.setSort(state.fieldId, "asc")
73
- }, t("column action sort ascending")), isCurrentColumnSorted && /* @__PURE__ */ React.createElement(DropdownMenu.Item, {
74
- "data-testid": "column-clear-sort",
75
- onClick: () => model.sorting?.clearSort()
76
- }, t("column action clear sorting")), model.getColumnCount() > 1 && model.features.schemaEditable && /* @__PURE__ */ React.createElement(DropdownMenu.Item, {
77
- "data-testid": "column-delete",
78
- onClick: () => model.deleteColumn(state.fieldId)
79
- }, t("column action delete")), model.features.schemaEditable && /* @__PURE__ */ React.createElement(DropdownMenu.Item, {
80
- "data-testid": "column-settings",
81
- onClick: () => modals.openColumnSettings()
82
- }, t("column action settings"))), /* @__PURE__ */ React.createElement(DropdownMenu.Arrow, null))));
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
+ }
83
90
  };
84
91
 
85
92
  // packages/ui/react-ui-table/src/components/Table/ColumnSettings.tsx
93
+ import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
86
94
  import React2, { useCallback, useEffect, useMemo, useState } from "react";
87
95
  import { DropdownMenu as DropdownMenu2 } from "@dxos/react-ui";
88
96
  import { FieldEditor } from "@dxos/react-ui-form";
89
97
  var ColumnSettings = ({ model, modals, onNewColumn }) => {
90
- const [newField, setNewField] = useState();
91
- const state = modals.state.value;
92
- const space = model?.space;
93
- useEffect(() => {
94
- if (state?.type === "columnSettings" && state.mode.type === "create" && model?.projection) {
95
- setNewField(model.projection.createFieldProjection());
96
- requestAnimationFrame(() => {
97
- onNewColumn();
98
- });
99
- } else {
100
- setNewField(void 0);
101
- }
102
- }, [
103
- model?.projection,
104
- state
105
- ]);
106
- const existingField = useMemo(() => {
107
- if (state?.type === "columnSettings") {
108
- const { mode } = state;
109
- if (mode.type === "edit") {
110
- return model?.view?.fields.find((f) => f.id === mode.fieldId);
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
111
  }
112
- }
113
- return void 0;
114
- }, [
115
- model?.view?.fields,
116
- state
117
- ]);
118
- const field = existingField ?? newField;
119
- const handleSave = useCallback(() => {
120
- modals.close();
121
- }, [
122
- modals
123
- ]);
124
- const handleCancel = useCallback(() => {
125
- if (state?.type === "columnSettings" && state.mode.type === "create" && newField) {
126
- model?.projection?.deleteFieldProjection(newField.id);
127
- }
128
- }, [
129
- model?.projection,
130
- state,
131
- newField
132
- ]);
133
- if (!model?.view || !model.projection || !field) {
134
- return null;
135
- }
136
- return /* @__PURE__ */ React2.createElement(DropdownMenu2.Root, {
137
- modal: false,
138
- open: state?.type === "columnSettings"
139
- }, /* @__PURE__ */ React2.createElement(DropdownMenu2.VirtualTrigger, {
140
- virtualRef: modals.trigger
141
- }), /* @__PURE__ */ React2.createElement(DropdownMenu2.Portal, null, /* @__PURE__ */ React2.createElement(DropdownMenu2.Content, {
142
- classNames: "md:is-64"
143
- }, /* @__PURE__ */ React2.createElement(DropdownMenu2.Viewport, null, /* @__PURE__ */ React2.createElement(FieldEditor, {
144
- view: model.view,
145
- projection: model.projection,
146
- field,
147
- registry: space?.db.schemaRegistry,
148
- onSave: handleSave,
149
- onCancel: handleCancel
150
- })), /* @__PURE__ */ React2.createElement(DropdownMenu2.Arrow, null))));
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(DropdownMenu2.Root, {
147
+ modal: false,
148
+ open: state?.type === "columnSettings"
149
+ }, /* @__PURE__ */ React2.createElement(DropdownMenu2.VirtualTrigger, {
150
+ virtualRef: modals.trigger
151
+ }), /* @__PURE__ */ React2.createElement(DropdownMenu2.Portal, null, /* @__PURE__ */ React2.createElement(DropdownMenu2.Content, {
152
+ classNames: "md:is-64"
153
+ }, /* @__PURE__ */ React2.createElement(DropdownMenu2.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(DropdownMenu2.Arrow, null))));
161
+ } finally {
162
+ _effect.f();
163
+ }
151
164
  };
152
165
 
153
166
  // packages/ui/react-ui-table/src/components/Table/CreateRefPanel.tsx
167
+ import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
168
+ import { Schema } from "effect";
154
169
  import React3, { useCallback as useCallback2, useMemo as useMemo2 } from "react";
155
- import { S } from "@dxos/echo-schema";
156
- import { create } from "@dxos/react-client/echo";
170
+ import { live } from "@dxos/react-client/echo";
157
171
  import { Popover } from "@dxos/react-ui";
158
172
  import { Form } from "@dxos/react-ui-form";
159
173
  import { useGridContext } from "@dxos/react-ui-grid";
160
174
  var CreateRefPanel = ({ model, modals, __gridScope }) => {
161
- const { id: gridId } = useGridContext("TableCellEditor", __gridScope);
162
- const space = model?.space;
163
- const state = modals.state.value;
164
- const schema = useMemo2(() => {
165
- if (!space || state?.type !== "createRefPanel") {
166
- return;
167
- }
168
- const [schema2] = space.db.schemaRegistry.query({
169
- typename: state.typename
170
- }).runSync();
171
- if (schema2) {
172
- const omit = S.omit("id");
173
- return omit(schema2);
174
- }
175
- }, [
176
- space,
177
- state
178
- ]);
179
- const handleSave = useCallback2((values) => {
180
- if (!model || !space || state?.type !== "createRefPanel") {
181
- return;
182
- }
183
- const [schema2] = space.db.schemaRegistry.query({
184
- typename: state.typename
185
- }).runSync();
186
- if (schema2) {
187
- const obj = space.db.add(create(schema2, values));
188
- state.onCreate?.(obj);
189
- }
190
- void modals.close();
191
- }, [
192
- modals,
193
- space,
194
- state
195
- ]);
196
- const handleCancel = useCallback2(() => {
197
- if (model) {
198
- modals.close();
199
- }
200
- }, [
201
- modals
202
- ]);
203
- if (!model?.view || !model.projection) {
204
- return null;
205
- }
206
- return /* @__PURE__ */ React3.createElement(Popover.Root, {
207
- modal: false,
208
- open: state?.type === "createRefPanel" && !!schema,
209
- onOpenChange: (nextOpen) => {
210
- if (model && !nextOpen) {
211
- return modals.close();
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;
212
183
  }
213
- }
214
- }, /* @__PURE__ */ React3.createElement(Popover.VirtualTrigger, {
215
- virtualRef: modals.trigger
216
- }), /* @__PURE__ */ React3.createElement(Popover.Portal, null, /* @__PURE__ */ React3.createElement(Popover.Content, {
217
- classNames: "md:is-64",
218
- "data-grid": gridId
219
- }, state?.type === "createRefPanel" && schema && /* @__PURE__ */ React3.createElement(Form, {
220
- schema,
221
- values: state.initialValues ?? {},
222
- onSave: handleSave,
223
- onCancel: handleCancel
224
- }), /* @__PURE__ */ React3.createElement(Popover.Arrow, null))));
225
- };
226
-
227
- // packages/ui/react-ui-table/src/components/Table/RefPanel.tsx
228
- import React4 from "react";
229
- import { Popover as Popover2 } from "@dxos/react-ui";
230
- import { Form as Form2 } from "@dxos/react-ui-form";
231
- var getRefTargetObj = (space, id) => {
232
- if (space && id) {
233
- return space?.db.getObjectById(id);
234
- } else {
235
- return void 0;
236
- }
237
- };
238
- var RefPanel = ({ model, modals }) => {
239
- const state = modals.state.value;
240
- const space = model?.space;
241
- const targetObj = getRefTargetObj(space, state?.type === "refPanel" ? state.targetId : void 0);
242
- const schema = space && state?.type === "refPanel" ? space.db.schemaRegistry.getSchema(state.typename) : void 0;
243
- if (!model.view || !model.projection) {
244
- return null;
245
- }
246
- return /* @__PURE__ */ React4.createElement(Popover2.Root, {
247
- modal: false,
248
- open: state?.type === "refPanel" && !!targetObj && !!schema,
249
- onOpenChange: (nextOpen) => {
250
- if (!nextOpen) {
251
- return modals.close();
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);
252
190
  }
253
- }
254
- }, /* @__PURE__ */ React4.createElement(Popover2.VirtualTrigger, {
255
- virtualRef: modals.trigger
256
- }), /* @__PURE__ */ React4.createElement(Popover2.Portal, null, /* @__PURE__ */ React4.createElement(Popover2.Content, {
257
- classNames: "md:is-64"
258
- }, targetObj && schema && /* @__PURE__ */ React4.createElement(Form2, {
259
- readonly: true,
260
- values: targetObj,
261
- schema
262
- }), /* @__PURE__ */ React4.createElement(Popover2.Arrow, null))));
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(Popover.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(Popover.VirtualTrigger, {
231
+ virtualRef: modals.trigger
232
+ }), /* @__PURE__ */ React3.createElement(Popover.Portal, null, /* @__PURE__ */ React3.createElement(Popover.Content, {
233
+ classNames: "md:is-64",
234
+ "data-grid": gridId
235
+ }, state?.type === "createRefPanel" && schema && /* @__PURE__ */ React3.createElement(Form, {
236
+ schema,
237
+ values: state.initialValues ?? {},
238
+ onSave: handleSave,
239
+ onCancel: handleCancel
240
+ }), /* @__PURE__ */ React3.createElement(Popover.Arrow, null))));
241
+ } finally {
242
+ _effect.f();
243
+ }
263
244
  };
264
245
 
265
246
  // packages/ui/react-ui-table/src/components/Table/RowActionsMenu.tsx
266
- import React5 from "react";
247
+ import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
248
+ import React4 from "react";
267
249
  import { DropdownMenu as DropdownMenu3, useTranslation as useTranslation2 } from "@dxos/react-ui";
268
250
  var RowActionsMenu = ({ model, modals }) => {
269
- const { t } = useTranslation2(translationKey);
270
- const hasSelection = model.selection.hasSelection.value;
271
- const state = modals.state.value;
272
- if (state?.type !== "row") {
273
- return null;
274
- }
275
- return /* @__PURE__ */ React5.createElement(DropdownMenu3.Root, {
276
- modal: false,
277
- open: true,
278
- onOpenChange: modals.close
279
- }, /* @__PURE__ */ React5.createElement(DropdownMenu3.VirtualTrigger, {
280
- virtualRef: modals.trigger
281
- }), /* @__PURE__ */ React5.createElement(DropdownMenu3.Content, null, /* @__PURE__ */ React5.createElement(DropdownMenu3.Viewport, null, model.features.dataEditable !== false && /* @__PURE__ */ React5.createElement(DropdownMenu3.Item, {
282
- "data-testid": "row-menu-delete",
283
- onClick: () => model.deleteRow(state.rowIndex)
284
- }, t(hasSelection ? "bulk delete row label" : "delete row label")), model.rowActions?.map((action) => /* @__PURE__ */ React5.createElement(DropdownMenu3.Item, {
285
- key: action.id,
286
- "data-testid": `row-action-${action.id}`,
287
- onClick: () => {
288
- modals.close();
289
- model.handleRowAction(action.id, state.rowIndex);
290
- }
291
- }, t(action.translationKey)))), /* @__PURE__ */ React5.createElement(DropdownMenu3.Arrow, null)));
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(DropdownMenu3.Root, {
260
+ modal: false,
261
+ open: true,
262
+ onOpenChange: modals.close
263
+ }, /* @__PURE__ */ React4.createElement(DropdownMenu3.VirtualTrigger, {
264
+ virtualRef: modals.trigger
265
+ }), /* @__PURE__ */ React4.createElement(DropdownMenu3.Content, null, /* @__PURE__ */ React4.createElement(DropdownMenu3.Viewport, null, model.features.dataEditable !== false && /* @__PURE__ */ React4.createElement(DropdownMenu3.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(DropdownMenu3.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(DropdownMenu3.Arrow, null)));
276
+ } finally {
277
+ _effect.f();
278
+ }
292
279
  };
293
280
 
294
281
  // packages/ui/react-ui-table/src/model/table-model.ts
@@ -296,7 +283,7 @@ import { computed as computed3, effect as effect2, signal as signal3 } from "@pr
296
283
  import { Resource as Resource2 } from "@dxos/context";
297
284
  import { FormatEnum as FormatEnum3, getValue as getValue2, setValue } from "@dxos/echo-schema";
298
285
  import { invariant } from "@dxos/invariant";
299
- import { isReactiveObject, makeRef as makeRef3 } from "@dxos/live-object";
286
+ import { isLiveObject, makeRef as makeRef2 } from "@dxos/live-object";
300
287
  import { formatForEditing, parseValue } from "@dxos/react-ui-form";
301
288
 
302
289
  // packages/ui/react-ui-table/src/model/selection-model.ts
@@ -304,9 +291,10 @@ import { computed, effect, signal } from "@preact/signals-core";
304
291
  import { Resource } from "@dxos/context";
305
292
 
306
293
  // packages/ui/react-ui-table/src/util/dynamic-table.ts
307
- import { create as create2, makeRef } from "@dxos/live-object";
294
+ import { getTypename, toJsonSchema } from "@dxos/echo-schema";
295
+ import { live as live2, makeRef } from "@dxos/live-object";
308
296
  import { createView, getSchemaFromPropertyDefinitions, ViewProjection } from "@dxos/schema";
309
- var getBaseSchems = ({ typename, properties, jsonSchema, schema }) => {
297
+ var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
310
298
  if (typename && properties) {
311
299
  const schema2 = getSchemaFromPropertyDefinitions(typename, properties);
312
300
  return {
@@ -315,8 +303,8 @@ var getBaseSchems = ({ typename, properties, jsonSchema, schema }) => {
315
303
  };
316
304
  } else if (schema) {
317
305
  return {
318
- typename: schema.typename,
319
- jsonSchema: schema.jsonSchema
306
+ typename: getTypename(schema),
307
+ jsonSchema: toJsonSchema(schema)
320
308
  };
321
309
  } else if (typename && jsonSchema) {
322
310
  return {
@@ -336,7 +324,7 @@ var makeDynamicTable = ({ typename, jsonSchema, properties }) => {
336
324
  fields: properties.map((property) => property.name)
337
325
  }
338
326
  });
339
- const table = create2(TableType, {
327
+ const table = live2(TableType, {
340
328
  name: "dynamic-table",
341
329
  view: makeRef(view)
342
330
  });
@@ -383,9 +371,10 @@ var setProperties = (view, projection, properties) => {
383
371
  var touch = (value) => value;
384
372
 
385
373
  // packages/ui/react-ui-table/src/util/table.ts
386
- import { AST, Format, FormatEnum, S as S2, TypedObject, TypeEnum } from "@dxos/echo-schema";
374
+ import { Schema as Schema2 } from "effect";
375
+ import { Format, FormatEnum, Ref, TypedObject, TypeEnum } from "@dxos/echo-schema";
387
376
  import { PublicKey } from "@dxos/react-client";
388
- import { create as create3, makeRef as makeRef2 } from "@dxos/react-client/echo";
377
+ import { live as live3 } from "@dxos/react-client/echo";
389
378
  import { createFieldId, createView as createView2, getSchemaProperties, ViewProjection as ViewProjection2 } from "@dxos/schema";
390
379
  var initializeTable = async ({ client, space, table, typename, initialRow = true }) => {
391
380
  if (typename) {
@@ -393,8 +382,8 @@ var initializeTable = async ({ client, space, table, typename, initialRow = true
393
382
  if (!schema) {
394
383
  throw new Error(`Schema not found: ${typename}`);
395
384
  }
396
- const fields = getSchemaProperties(schema.ast).filter((prop) => prop.format !== FormatEnum.Ref).map((prop) => prop.name);
397
- table.view = makeRef2(createView2({
385
+ const fields = getSchemaProperties(schema.ast).map((prop) => prop.name);
386
+ table.view = Ref.make(createView2({
398
387
  // TODO(ZaymonFC): Don't hardcode name?
399
388
  name: "View",
400
389
  typename: schema.typename,
@@ -407,7 +396,7 @@ var initializeTable = async ({ client, space, table, typename, initialRow = true
407
396
  ContactSchema
408
397
  ]);
409
398
  const fields = ContactFields;
410
- table.view = makeRef2(createView2({
399
+ table.view = Ref.make(createView2({
411
400
  name: "View",
412
401
  typename: schema.typename,
413
402
  jsonSchema: schema.jsonSchema,
@@ -415,7 +404,7 @@ var initializeTable = async ({ client, space, table, typename, initialRow = true
415
404
  }));
416
405
  createProjection(schema, table.view.target);
417
406
  if (initialRow) {
418
- space.db.add(create3(schema, {}));
407
+ space.db.add(live3(schema, {}));
419
408
  }
420
409
  return schema;
421
410
  }
@@ -424,13 +413,13 @@ var ContactSchema = TypedObject({
424
413
  typename: `example.com/type/${PublicKey.random().truncate()}`,
425
414
  version: "0.1.0"
426
415
  })({
427
- name: S2.optional(S2.String).annotations({
428
- [AST.TitleAnnotationId]: "Name"
416
+ name: Schema2.optional(Schema2.String).annotations({
417
+ title: "Name"
429
418
  }),
430
- active: S2.optional(S2.Boolean),
431
- email: S2.optional(Format.Email),
432
- salary: S2.optional(Format.Currency()).annotations({
433
- [AST.TitleAnnotationId]: "Salary"
419
+ active: Schema2.optional(Schema2.Boolean),
420
+ email: Schema2.optional(Format.Email),
421
+ salary: Schema2.optional(Format.Currency()).annotations({
422
+ title: "Salary"
434
423
  })
435
424
  });
436
425
  var ContactFields = [
@@ -483,7 +472,7 @@ var BUTTON_IDENTIFIERS = {
483
472
  var createButton = ({ attr, data, disabled = false, icon, testId, type = "primary" }) => {
484
473
  const dataAttrs = Object.entries(data).map(([k, v]) => `${k}="${v}"`).join(" ");
485
474
  const positionClass = type === "primary" ? "inline-end-2" : "inline-end-9";
486
- 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><use href="/icons.svg#${icon}"/></svg></button>`;
475
+ 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>`;
487
476
  };
488
477
  var addColumnButton = {
489
478
  attr: BUTTON_IDENTIFIERS.newColumn,
@@ -519,26 +508,6 @@ var columnSettingsButton = {
519
508
  fieldId: el.getAttribute("data-field-id")
520
509
  })
521
510
  };
522
- var referencedCellButton = {
523
- attr: BUTTON_IDENTIFIERS.referencedCell,
524
- icon: "ph--link-simple-horizontal--regular",
525
- render: ({ targetId, schemaId }) => {
526
- return createButton({
527
- attr: BUTTON_IDENTIFIERS.referencedCell,
528
- icon: referencedCellButton.icon,
529
- data: {
530
- "data-target-id": targetId,
531
- "data-schema-id": schemaId
532
- },
533
- testId: "table-ref-cell-button"
534
- });
535
- },
536
- getData: (el) => ({
537
- type: "referencedCell",
538
- targetId: el.getAttribute("data-target-id"),
539
- schemaId: el.getAttribute("data-schema-id")
540
- })
541
- };
542
511
  var rowMenuButton = {
543
512
  attr: BUTTON_IDENTIFIERS.rowMenu,
544
513
  icon: "ph--dots-three--regular",
@@ -583,7 +552,6 @@ var sortButton = {
583
552
  var tableButtons = {
584
553
  addColumn: addColumnButton,
585
554
  columnSettings: columnSettingsButton,
586
- referencedCell: referencedCellButton,
587
555
  rowMenu: rowMenuButton,
588
556
  sort: sortButton
589
557
  };
@@ -642,15 +610,25 @@ var tableControls = {
642
610
  }
643
611
  };
644
612
 
613
+ // packages/ui/react-ui-table/src/util/schema.ts
614
+ import { Schema as Schema3 } from "effect";
615
+ import { isTypeLiteral, TypeLiteral } from "effect/SchemaAST";
616
+ var narrowSchema = (schema, paths) => {
617
+ const ast = schema?.ast;
618
+ if (isTypeLiteral(ast)) {
619
+ const propertySignatures = ast.propertySignatures.filter((signature) => paths.includes(signature.name.toString()));
620
+ if (propertySignatures.length > 0) {
621
+ const narrowType = new TypeLiteral(propertySignatures, []);
622
+ return Schema3.make(narrowType);
623
+ }
624
+ }
625
+ return void 0;
626
+ };
627
+
645
628
  // packages/ui/react-ui-table/src/model/selection-model.ts
646
629
  var SelectionModel = class extends Resource {
647
630
  constructor(_rows, _selectionMode, _onSelectionChanged) {
648
- super();
649
- this._rows = _rows;
650
- this._selectionMode = _selectionMode;
651
- this._onSelectionChanged = _onSelectionChanged;
652
- this._selection = signal(/* @__PURE__ */ new Set());
653
- this._validSelectedIds = computed(() => {
631
+ super(), this._rows = _rows, this._selectionMode = _selectionMode, this._onSelectionChanged = _onSelectionChanged, this._selection = signal(/* @__PURE__ */ new Set()), this._validSelectedIds = computed(() => {
654
632
  const rows = this._rows.value;
655
633
  if (!rows) {
656
634
  return /* @__PURE__ */ new Set();
@@ -659,27 +637,21 @@ var SelectionModel = class extends Resource {
659
637
  return new Set([
660
638
  ...this._selection.value
661
639
  ].filter((id) => validIds.has(id)));
662
- });
663
- this._hasSelection = computed(() => this._validSelectedIds.value.size > 0);
664
- this._allSelected = computed(() => {
640
+ }), this._hasSelection = computed(() => this._validSelectedIds.value.size > 0), this._allSelected = computed(() => {
665
641
  const rows = this._rows.value;
666
642
  if (rows.length === 0) {
667
643
  return false;
668
644
  }
669
645
  return rows.every((row) => this._selection.value.has(row.id));
670
- });
671
- this.getSelectedRows = () => {
646
+ }), this.getSelectedRows = () => {
672
647
  const selectedIds = this._validSelectedIds.value;
673
648
  return this._rows.value.filter((row) => selectedIds.has(row.id));
674
- };
675
- this.isRowIndexSelected = (rowIndex) => {
649
+ }, this.isRowIndexSelected = (rowIndex) => {
676
650
  const row = this._rows.value[rowIndex];
677
651
  return this._selection.value.has(row.id);
678
- };
679
- this.isObjectSelected = (object) => {
652
+ }, this.isObjectSelected = (object) => {
680
653
  return this._selection.value.has(object.id);
681
- };
682
- this.toggleSelectionForRowIndex = (rowIndex) => {
654
+ }, this.toggleSelectionForRowIndex = (rowIndex) => {
683
655
  const row = this._rows.value[rowIndex];
684
656
  const newSelection = new Set(this._selection.value);
685
657
  if (newSelection.has(row.id)) {
@@ -691,8 +663,7 @@ var SelectionModel = class extends Resource {
691
663
  newSelection.add(row.id);
692
664
  }
693
665
  this._selection.value = newSelection;
694
- };
695
- this.setSelection = (mode) => {
666
+ }, this.setSelection = (mode) => {
696
667
  switch (mode) {
697
668
  case "all": {
698
669
  this._selection.value = new Set(this._rows.value.map((row) => row.id));
@@ -894,6 +865,22 @@ var TableSorting = class {
894
865
  }
895
866
  };
896
867
 
868
+ // packages/ui/react-ui-table/src/util/tag.ts
869
+ var TAG_PATTERN_REGEX = /\[([^\]]+)\]\(([^)]+)\)/g;
870
+ var extractTagIds = (value) => {
871
+ if (typeof value !== "string") {
872
+ return void 0;
873
+ }
874
+ const ids = [];
875
+ let match;
876
+ while ((match = TAG_PATTERN_REGEX.exec(value)) !== null) {
877
+ if (match[2]) {
878
+ ids.push(match[2]);
879
+ }
880
+ }
881
+ return ids.length > 0 ? ids : void 0;
882
+ };
883
+
897
884
  // packages/ui/react-ui-table/src/model/table-model.ts
898
885
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/model/table-model.ts";
899
886
  var defaultFeatures = {
@@ -993,8 +980,22 @@ var TableModel = class extends Resource2 {
993
980
  const { props } = this._projection.getFieldProjection(field.id);
994
981
  switch (props.format) {
995
982
  case FormatEnum3.Ref: {
996
- if (isReactiveObject(value)) {
997
- setValue(this._rows.value[rowIdx], field.path, makeRef3(value));
983
+ if (isLiveObject(value)) {
984
+ setValue(this._rows.value[rowIdx], field.path, makeRef2(value));
985
+ }
986
+ break;
987
+ }
988
+ case FormatEnum3.SingleSelect: {
989
+ const ids = extractTagIds(value);
990
+ if (ids && ids.length > 0) {
991
+ setValue(this._rows.value[rowIdx], field.path, ids[0]);
992
+ }
993
+ break;
994
+ }
995
+ case FormatEnum3.MultiSelect: {
996
+ const ids = extractTagIds(value);
997
+ if (ids) {
998
+ setValue(this._rows.value[rowIdx], field.path, ids);
998
999
  }
999
1000
  break;
1000
1001
  }
@@ -1018,7 +1019,7 @@ var TableModel = class extends Resource2 {
1018
1019
  };
1019
1020
  invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
1020
1021
  F: __dxlog_file,
1021
- L: 114,
1022
+ L: 115,
1022
1023
  S: this,
1023
1024
  A: [
1024
1025
  "!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
@@ -1078,7 +1079,7 @@ var TableModel = class extends Resource2 {
1078
1079
  get columnMeta() {
1079
1080
  invariant(this._columnMeta, void 0, {
1080
1081
  F: __dxlog_file,
1081
- L: 183,
1082
+ L: 184,
1082
1083
  S: this,
1083
1084
  A: [
1084
1085
  "this._columnMeta",
@@ -1304,7 +1305,8 @@ var ModalController = class {
1304
1305
 
1305
1306
  // packages/ui/react-ui-table/src/model/table-presentation.ts
1306
1307
  import { signal as signal5 } from "@preact/signals-core";
1307
- import { FormatEnum as FormatEnum4, getValue as getValue3 } from "@dxos/echo-schema";
1308
+ import { isNotNullable } from "effect/Predicate";
1309
+ import { FormatEnum as FormatEnum4, getDXN, getValue as getValue3, TypeEnum as TypeEnum3 } from "@dxos/echo-schema";
1308
1310
  import { cellClassesForFieldType, formatForDisplay as formatForDisplay2 } from "@dxos/react-ui-form";
1309
1311
  import { toPlaneCellIndex } from "@dxos/react-ui-grid";
1310
1312
  import { mx } from "@dxos/react-ui-theme";
@@ -1366,6 +1368,9 @@ var TablePresentation = class {
1366
1368
  if (value == null) {
1367
1369
  return "";
1368
1370
  }
1371
+ if (props.type === "array") {
1372
+ return "";
1373
+ }
1369
1374
  switch (props.format) {
1370
1375
  case FormatEnum4.Boolean:
1371
1376
  case FormatEnum4.SingleSelect:
@@ -1403,13 +1408,38 @@ var TablePresentation = class {
1403
1408
  if (classes.length > 0) {
1404
1409
  cell.className = mx(classes.flat());
1405
1410
  }
1411
+ if (props.type === TypeEnum3.Array) {
1412
+ const targetArray = getValue3(obj, field.path);
1413
+ if (targetArray && Array.isArray(targetArray)) {
1414
+ const getLabel = (value) => {
1415
+ if (!value) {
1416
+ return void 0;
1417
+ }
1418
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1419
+ return String(value);
1420
+ }
1421
+ if (Array.isArray(value)) {
1422
+ return "Array";
1423
+ }
1424
+ if (typeof value === "object" && value.name) {
1425
+ return value.name;
1426
+ }
1427
+ if (typeof value === "object" && value.value) {
1428
+ return `${value.value}`;
1429
+ }
1430
+ return "Object";
1431
+ };
1432
+ const tags = targetArray.map(getLabel).filter(isNotNullable).map((title) => {
1433
+ return `<span class="dx-tag rounded-xl" data-hue="neutral">${title}</span>`;
1434
+ }).join("");
1435
+ cell.accessoryHtml = `<div role='none' class="flex flex-row gap-1 overflow-x-auto">${tags}</div>`;
1436
+ }
1437
+ }
1406
1438
  if (props.format === FormatEnum4.Ref && props.referenceSchema) {
1407
1439
  const targetObj = getValue3(obj, field.path)?.target;
1408
1440
  if (targetObj) {
1409
- cell.accessoryHtml = tableButtons.referencedCell.render({
1410
- targetId: targetObj.id,
1411
- schemaId: props.referenceSchema
1412
- });
1441
+ const dxn = getDXN(targetObj)?.toString();
1442
+ cell.accessoryHtml = `<dx-ref-tag refId=${dxn} class="dx-button block is-6 pli-[3px] plb-[3px] pbe-[2px] min-bs-0 absolute inline-end-1"><dx-icon icon="ph--link-simple--regular"/></dx-ref-tag>`;
1413
1443
  }
1414
1444
  }
1415
1445
  if (props.format === FormatEnum4.Boolean) {
@@ -1443,7 +1473,7 @@ var TablePresentation = class {
1443
1473
  return null;
1444
1474
  }).filter(Boolean).join(" ");
1445
1475
  if (tags) {
1446
- cell.accessoryHtml = tags;
1476
+ cell.accessoryHtml = `<div role='none' class="flex flex-row gap-1">${tags}</div>`;
1447
1477
  }
1448
1478
  }
1449
1479
  }
@@ -1488,7 +1518,7 @@ var TablePresentation = class {
1488
1518
  fieldId: field.id
1489
1519
  })}
1490
1520
  `,
1491
- className: "!bg-gridHeader"
1521
+ className: "!bg-toolbarSurface"
1492
1522
  };
1493
1523
  }
1494
1524
  return cells;
@@ -1539,7 +1569,7 @@ var TablePresentation = class {
1539
1569
  col: 0,
1540
1570
  row: 0
1541
1571
  })]: {
1542
- className: "!bg-gridHeader",
1572
+ className: "!bg-toolbarSurface",
1543
1573
  readonly: true,
1544
1574
  value: ""
1545
1575
  }
@@ -1555,7 +1585,7 @@ var TablePresentation = class {
1555
1585
  header: true,
1556
1586
  checked: this.model.selection.allRowsSeleted.value
1557
1587
  }),
1558
- className: "!bg-gridHeader",
1588
+ className: "!bg-toolbarSurface",
1559
1589
  readonly: true,
1560
1590
  value: ""
1561
1591
  }
@@ -1570,7 +1600,7 @@ var TablePresentation = class {
1570
1600
  accessoryHtml: this.model.features.schemaEditable ? tableButtons.addColumn.render({
1571
1601
  disabled: (this.model.view?.fields?.length ?? 0) >= VIEW_FIELD_LIMIT
1572
1602
  }) : void 0,
1573
- className: "!bg-gridHeader",
1603
+ className: "!bg-toolbarSurface",
1574
1604
  readonly: true,
1575
1605
  value: ""
1576
1606
  }
@@ -1601,14 +1631,116 @@ var cellClassesForRowSelection = (selected, selectionMode) => {
1601
1631
  };
1602
1632
 
1603
1633
  // packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx
1604
- import React6, { useCallback as useCallback3, useMemo as useMemo3, useRef } from "react";
1605
- import { FormatEnum as FormatEnum5 } from "@dxos/echo-schema";
1606
- import { invariant as invariant2 } from "@dxos/invariant";
1634
+ import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
1635
+ import React6, { useCallback as useCallback4, useMemo as useMemo4, useRef as useRef2 } from "react";
1636
+ import { FormatEnum as FormatEnum5, TypeEnum as TypeEnum4 } from "@dxos/echo-schema";
1637
+ import { invariant as invariant3 } from "@dxos/invariant";
1607
1638
  import { useThemeContext } from "@dxos/react-ui";
1608
1639
  import { createMarkdownExtensions } from "@dxos/react-ui-editor";
1609
- import { cellQuery, editorKeys, parseCellIndex, useGridContext as useGridContext2, GridCellEditor } from "@dxos/react-ui-grid";
1640
+ import { cellQuery, editorKeys, parseCellIndex as parseCellIndex2, useGridContext as useGridContext3, GridCellEditor } from "@dxos/react-ui-grid";
1610
1641
  import { tagPickerExtension, createLinks } from "@dxos/react-ui-tag-picker";
1611
1642
 
1643
+ // packages/ui/react-ui-table/src/components/TableCellEditor/FormCellEditor.tsx
1644
+ import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
1645
+ import React5, { useCallback as useCallback3, useEffect as useEffect2, useMemo as useMemo3, useRef } from "react";
1646
+ import { getSnapshot } from "@dxos/echo-schema";
1647
+ import { invariant as invariant2 } from "@dxos/invariant";
1648
+ import { Popover as Popover2 } from "@dxos/react-ui";
1649
+ import { Form as Form2 } from "@dxos/react-ui-form";
1650
+ import { parseCellIndex, useGridContext as useGridContext2 } from "@dxos/react-ui-grid";
1651
+ import { getDeep, setDeep } from "@dxos/util";
1652
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/FormCellEditor.tsx";
1653
+ var FormCellEditor = ({ fieldProjection, model, schema, __gridScope }) => {
1654
+ var _effect = _useSignals5();
1655
+ try {
1656
+ const { editing, setEditing } = useGridContext2("ArrayEditor", __gridScope);
1657
+ const cellRef = useRef(null);
1658
+ useEffect2(() => {
1659
+ if (editing && editing.cellElement) {
1660
+ cellRef.current = editing.cellElement;
1661
+ }
1662
+ }, [
1663
+ editing?.cellElement
1664
+ ]);
1665
+ const narrowedSchema = useMemo3(() => {
1666
+ if (!schema) {
1667
+ return void 0;
1668
+ }
1669
+ return narrowSchema(schema, [
1670
+ fieldProjection.field.path
1671
+ ]);
1672
+ }, [
1673
+ JSON.stringify(schema),
1674
+ fieldProjection.field.path
1675
+ ]);
1676
+ const originalRow = useMemo3(() => {
1677
+ if (model && editing) {
1678
+ const cell = parseCellIndex(editing.index);
1679
+ const row = model.getRowAt(cell.row);
1680
+ invariant2(row, void 0, {
1681
+ F: __dxlog_file3,
1682
+ L: 47,
1683
+ S: void 0,
1684
+ A: [
1685
+ "row",
1686
+ ""
1687
+ ]
1688
+ });
1689
+ return row;
1690
+ }
1691
+ return void 0;
1692
+ }, [
1693
+ model,
1694
+ editing
1695
+ ]);
1696
+ const formValues = useMemo3(() => {
1697
+ if (originalRow) {
1698
+ return getSnapshot(originalRow);
1699
+ }
1700
+ }, [
1701
+ originalRow
1702
+ ]);
1703
+ const handleSave = useCallback3((values) => {
1704
+ const path = fieldProjection.field.path;
1705
+ const value = getDeep(values, [
1706
+ path
1707
+ ]);
1708
+ setDeep(originalRow, [
1709
+ path
1710
+ ], value);
1711
+ setEditing(null);
1712
+ }, [
1713
+ fieldProjection.field.path,
1714
+ originalRow
1715
+ ]);
1716
+ const handleOpenChange = useCallback3((nextOpen) => {
1717
+ if (nextOpen === false) {
1718
+ setEditing(null);
1719
+ }
1720
+ }, [
1721
+ setEditing
1722
+ ]);
1723
+ if (!editing) {
1724
+ return null;
1725
+ }
1726
+ return /* @__PURE__ */ React5.createElement(Popover2.Root, {
1727
+ open: editing !== null,
1728
+ onOpenChange: handleOpenChange
1729
+ }, /* @__PURE__ */ React5.createElement(Popover2.VirtualTrigger, {
1730
+ virtualRef: cellRef
1731
+ }), /* @__PURE__ */ React5.createElement(Popover2.Content, {
1732
+ tabIndex: -1,
1733
+ classNames: "popover-card-width"
1734
+ }, /* @__PURE__ */ React5.createElement(Popover2.Arrow, null), /* @__PURE__ */ React5.createElement(Form2, {
1735
+ values: formValues,
1736
+ schema: narrowedSchema,
1737
+ onSave: handleSave
1738
+ })));
1739
+ } finally {
1740
+ _effect.f();
1741
+ }
1742
+ };
1743
+
1612
1744
  // packages/ui/react-ui-table/src/components/TableCellEditor/extension.ts
1613
1745
  import { autocompletion, pickedCompletion } from "@codemirror/autocomplete";
1614
1746
  import { EditorView } from "@codemirror/view";
@@ -1649,218 +1781,268 @@ var completion = ({ debug, onQuery, onMatch }) => {
1649
1781
  };
1650
1782
 
1651
1783
  // packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx
1652
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx";
1784
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx";
1653
1785
  var newValue = Symbol.for("newValue");
1654
1786
  var createOption = (text) => ({
1655
1787
  [newValue]: true,
1656
1788
  text
1657
1789
  });
1658
1790
  var isCreateOption = (data) => typeof data === "object" && data[newValue];
1659
- var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }) => {
1660
- const { id: gridId, editing, setEditing } = useGridContext2("TableCellEditor", __gridScope);
1661
- const suppressNextBlur = useRef(false);
1662
- const { themeMode } = useThemeContext();
1663
- const fieldProjection = useMemo3(() => {
1664
- if (!model || !editing) {
1665
- return;
1791
+ var TableValueEditor = ({ model, modals, schema, onEnter, onFocus, onQuery, __gridScope }) => {
1792
+ var _effect = _useSignals6();
1793
+ try {
1794
+ const { editing } = useGridContext3("TableValueEditor", __gridScope);
1795
+ const fieldProjection = useMemo4(() => {
1796
+ if (!model || !editing) {
1797
+ return;
1798
+ }
1799
+ const { col } = parseCellIndex2(editing.index);
1800
+ const field = model.projection.view.fields[col];
1801
+ const fieldProjection2 = model.projection.getFieldProjection(field.id);
1802
+ invariant3(fieldProjection2, void 0, {
1803
+ F: __dxlog_file4,
1804
+ L: 73,
1805
+ S: void 0,
1806
+ A: [
1807
+ "fieldProjection",
1808
+ ""
1809
+ ]
1810
+ });
1811
+ return fieldProjection2;
1812
+ }, [
1813
+ model,
1814
+ editing
1815
+ ]);
1816
+ if (fieldProjection?.props.type === TypeEnum4.Array) {
1817
+ return /* @__PURE__ */ React6.createElement(FormCellEditor, {
1818
+ fieldProjection,
1819
+ model,
1820
+ schema,
1821
+ __gridScope
1822
+ });
1666
1823
  }
1667
- const { col } = parseCellIndex(editing.index);
1668
- const field = model.projection.view.fields[col];
1669
- const fieldProjection2 = model.projection.getFieldProjection(field.id);
1670
- invariant2(fieldProjection2, void 0, {
1671
- F: __dxlog_file3,
1672
- L: 71,
1673
- S: void 0,
1674
- A: [
1675
- "fieldProjection",
1676
- ""
1677
- ]
1824
+ return /* @__PURE__ */ React6.createElement(TableCellEditor, {
1825
+ model,
1826
+ modals,
1827
+ onEnter,
1828
+ onFocus,
1829
+ onQuery,
1830
+ __gridScope
1678
1831
  });
1679
- return fieldProjection2;
1680
- }, [
1681
- model,
1682
- editing
1683
- ]);
1684
- const handleEnter = useCallback3((value) => {
1685
- if (!model || !editing) {
1686
- return;
1687
- }
1688
- const cell = parseCellIndex(editing.index);
1689
- model.setCellData(cell, value);
1690
- onEnter?.(cell);
1691
- onFocus?.();
1692
- setEditing(null);
1693
- }, [
1694
- model,
1695
- editing,
1696
- onEnter,
1697
- onFocus,
1698
- setEditing
1699
- ]);
1700
- const handleBlur = useCallback3((value) => {
1701
- if (!model || !editing) {
1702
- return;
1703
- }
1704
- if (suppressNextBlur.current) {
1705
- suppressNextBlur.current = false;
1706
- return;
1707
- }
1708
- const cell = parseCellIndex(editing.index);
1709
- if (value !== void 0) {
1832
+ } finally {
1833
+ _effect.f();
1834
+ }
1835
+ };
1836
+ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }) => {
1837
+ var _effect = _useSignals6();
1838
+ try {
1839
+ const { id: gridId, editing, setEditing } = useGridContext3("TableCellEditor", __gridScope);
1840
+ const suppressNextBlur = useRef2(false);
1841
+ const { themeMode } = useThemeContext();
1842
+ const fieldProjection = useMemo4(() => {
1843
+ if (!model || !editing) {
1844
+ return;
1845
+ }
1846
+ const { col } = parseCellIndex2(editing.index);
1847
+ const field = model.projection.view.fields[col];
1848
+ const fieldProjection2 = model.projection.getFieldProjection(field.id);
1849
+ invariant3(fieldProjection2, void 0, {
1850
+ F: __dxlog_file4,
1851
+ L: 114,
1852
+ S: void 0,
1853
+ A: [
1854
+ "fieldProjection",
1855
+ ""
1856
+ ]
1857
+ });
1858
+ return fieldProjection2;
1859
+ }, [
1860
+ model,
1861
+ editing
1862
+ ]);
1863
+ const handleEnter = useCallback4((value) => {
1864
+ if (!model || !editing) {
1865
+ return;
1866
+ }
1867
+ const cell = parseCellIndex2(editing.index);
1710
1868
  model.setCellData(cell, value);
1711
- }
1712
- }, [
1713
- model,
1714
- editing
1715
- ]);
1716
- const handleClose = useCallback3((value, event) => {
1717
- if (!model || !editing || !fieldProjection) {
1718
- return;
1719
- }
1720
- const cell = parseCellIndex(editing.index);
1721
- onEnter?.(cell);
1722
- if (event && onFocus) {
1723
- onFocus(determineNavigationAxis(event), determineNavigationDelta(event));
1724
- }
1725
- }, [
1726
- model,
1727
- editing,
1728
- onFocus,
1729
- onEnter,
1730
- fieldProjection
1731
- ]);
1732
- const extension = useMemo3(() => {
1733
- if (!fieldProjection) {
1734
- return [];
1735
- }
1736
- const extension2 = [
1737
- editorKeys({
1738
- onClose: handleClose,
1739
- ...editing?.initialContent && {
1740
- onNav: handleClose
1741
- }
1742
- })
1743
- ];
1744
- const format = fieldProjection.props.format;
1745
- if (format === FormatEnum5.SingleSelect || format === FormatEnum5.MultiSelect) {
1746
- extension2.push(createMarkdownExtensions({
1747
- themeMode
1748
- }));
1749
- const options = fieldProjection.props.options || [];
1750
- const mode = format === FormatEnum5.SingleSelect ? "single-select" : "multi-select";
1751
- extension2.push(tagPickerExtension({
1752
- mode,
1753
- inGrid: true,
1754
- onSearch: (text, selectedIds) => {
1755
- return options.filter((option) => selectedIds.indexOf(option.id) === -1 && (text.length === 0 || option.title.toLowerCase().includes(text.toLowerCase()))).map((option) => ({
1756
- id: option.id,
1757
- label: option.title,
1758
- hue: option.color
1759
- }));
1760
- },
1761
- onUpdate: (ids) => {
1762
- if (model && editing) {
1763
- if (ids.length === 0) {
1764
- return;
1765
- }
1766
- if (mode === "single-select") {
1767
- handleEnter(ids[0]);
1768
- } else {
1769
- handleEnter(ids);
1869
+ onEnter?.(cell);
1870
+ onFocus?.();
1871
+ setEditing(null);
1872
+ }, [
1873
+ model,
1874
+ editing,
1875
+ onEnter,
1876
+ onFocus,
1877
+ setEditing
1878
+ ]);
1879
+ const handleBlur = useCallback4((value) => {
1880
+ if (!model || !editing) {
1881
+ return;
1882
+ }
1883
+ if (suppressNextBlur.current) {
1884
+ suppressNextBlur.current = false;
1885
+ return;
1886
+ }
1887
+ const cell = parseCellIndex2(editing.index);
1888
+ if (value !== void 0) {
1889
+ model.setCellData(cell, value);
1890
+ }
1891
+ }, [
1892
+ model,
1893
+ editing
1894
+ ]);
1895
+ const handleClose = useCallback4((value, event) => {
1896
+ if (!model || !editing || !fieldProjection) {
1897
+ return;
1898
+ }
1899
+ const cell = parseCellIndex2(editing.index);
1900
+ onEnter?.(cell);
1901
+ if (event && onFocus) {
1902
+ onFocus(determineNavigationAxis(event), determineNavigationDelta(event));
1903
+ }
1904
+ }, [
1905
+ model,
1906
+ editing,
1907
+ onFocus,
1908
+ onEnter,
1909
+ fieldProjection
1910
+ ]);
1911
+ const extension = useMemo4(() => {
1912
+ if (!fieldProjection) {
1913
+ return [];
1914
+ }
1915
+ const extension2 = [
1916
+ editorKeys({
1917
+ onClose: handleClose,
1918
+ ...editing?.initialContent && {
1919
+ onNav: handleClose
1920
+ }
1921
+ })
1922
+ ];
1923
+ const format = fieldProjection.props.format;
1924
+ if (format === FormatEnum5.SingleSelect || format === FormatEnum5.MultiSelect) {
1925
+ extension2.push(createMarkdownExtensions({
1926
+ themeMode
1927
+ }));
1928
+ const options = fieldProjection.props.options || [];
1929
+ const mode = format === FormatEnum5.SingleSelect ? "single-select" : "multi-select";
1930
+ extension2.push(tagPickerExtension({
1931
+ mode,
1932
+ inGrid: true,
1933
+ onSearch: (text, selectedIds) => {
1934
+ return options.filter((option) => selectedIds.indexOf(option.id) === -1 && (text.length === 0 || option.title.toLowerCase().includes(text.toLowerCase()))).map((option) => ({
1935
+ id: option.id,
1936
+ label: option.title,
1937
+ hue: option.color
1938
+ }));
1939
+ },
1940
+ onUpdate: (ids) => {
1941
+ if (model && editing) {
1942
+ if (ids.length === 0) {
1943
+ return;
1944
+ }
1945
+ if (mode === "single-select") {
1946
+ handleEnter(ids[0]);
1947
+ } else {
1948
+ handleEnter(ids);
1949
+ }
1770
1950
  }
1771
1951
  }
1772
- }
1773
- }));
1774
- }
1775
- if (onQuery) {
1776
- switch (fieldProjection.props.format) {
1777
- case FormatEnum5.Ref: {
1778
- extension2.push([
1779
- completion({
1780
- onQuery: (text) => onQuery(fieldProjection, text),
1781
- onMatch: (data) => {
1782
- if (model && editing && modals) {
1783
- if (isCreateOption(data)) {
1784
- const { field, props } = fieldProjection;
1785
- if (props.referenceSchema) {
1786
- suppressNextBlur.current = true;
1787
- modals.openCreateRef(props.referenceSchema, document.querySelector(cellQuery(editing.index, gridId)), {
1788
- [field.referencePath]: data.text
1789
- }, (data2) => {
1790
- handleEnter(data2);
1791
- });
1952
+ }));
1953
+ }
1954
+ if (onQuery) {
1955
+ switch (fieldProjection.props.format) {
1956
+ case FormatEnum5.Ref: {
1957
+ extension2.push([
1958
+ completion({
1959
+ onQuery: (text) => onQuery(fieldProjection, text),
1960
+ onMatch: (data) => {
1961
+ if (model && editing && modals) {
1962
+ if (isCreateOption(data)) {
1963
+ const { field, props } = fieldProjection;
1964
+ if (props.referenceSchema) {
1965
+ suppressNextBlur.current = true;
1966
+ modals.openCreateRef(props.referenceSchema, document.querySelector(cellQuery(editing.index, gridId)), {
1967
+ [field.referencePath]: data.text
1968
+ }, (data2) => {
1969
+ handleEnter(data2);
1970
+ });
1971
+ }
1972
+ } else {
1973
+ handleEnter(data);
1792
1974
  }
1793
- } else {
1794
- handleEnter(data);
1795
1975
  }
1796
1976
  }
1797
- }
1798
- })
1799
- ]);
1800
- break;
1977
+ })
1978
+ ]);
1979
+ break;
1980
+ }
1801
1981
  }
1802
1982
  }
1803
- }
1804
- return extension2;
1805
- }, [
1806
- model,
1807
- modals,
1808
- editing,
1809
- fieldProjection,
1810
- handleClose,
1811
- themeMode
1812
- ]);
1813
- const getCellContent = useCallback3(() => {
1814
- if (model && editing) {
1815
- const cell = parseCellIndex(editing.index);
1816
- const { col } = cell;
1817
- const field = model.projection.view.fields[col];
1818
- const fieldProjection2 = model.projection.getFieldProjection(field.id);
1819
- if (fieldProjection2?.props.format === FormatEnum5.SingleSelect || fieldProjection2?.props.format === FormatEnum5.MultiSelect) {
1820
- const value2 = model.getCellData(cell);
1821
- if (value2 !== void 0) {
1822
- const options = fieldProjection2.props.options || [];
1823
- if (fieldProjection2.props.format === FormatEnum5.MultiSelect && Array.isArray(value2)) {
1824
- const tagItems = value2.map((id) => {
1825
- const option = options.find((o) => o.id === id);
1983
+ return extension2;
1984
+ }, [
1985
+ model,
1986
+ modals,
1987
+ editing,
1988
+ fieldProjection,
1989
+ handleClose,
1990
+ themeMode
1991
+ ]);
1992
+ const getCellContent = useCallback4(() => {
1993
+ if (model && editing) {
1994
+ const cell = parseCellIndex2(editing.index);
1995
+ const { col } = cell;
1996
+ const field = model.projection.view.fields[col];
1997
+ const fieldProjection2 = model.projection.getFieldProjection(field.id);
1998
+ if (fieldProjection2?.props.format === FormatEnum5.SingleSelect || fieldProjection2?.props.format === FormatEnum5.MultiSelect) {
1999
+ const value2 = model.getCellData(cell);
2000
+ if (value2 !== void 0) {
2001
+ const options = fieldProjection2.props.options || [];
2002
+ if (fieldProjection2.props.format === FormatEnum5.MultiSelect && Array.isArray(value2)) {
2003
+ const tagItems = value2.map((id) => {
2004
+ const option = options.find((o) => o.id === id);
2005
+ if (option) {
2006
+ return {
2007
+ id,
2008
+ label: option.title,
2009
+ hue: option.color
2010
+ };
2011
+ }
2012
+ return void 0;
2013
+ }).filter((item) => item !== void 0);
2014
+ return createLinks(tagItems);
2015
+ } else {
2016
+ const option = options.find((o) => o.id === value2);
1826
2017
  if (option) {
1827
- return {
1828
- id,
2018
+ const tagItem = {
2019
+ id: value2,
1829
2020
  label: option.title,
1830
2021
  hue: option.color
1831
2022
  };
2023
+ return createLinks([
2024
+ tagItem
2025
+ ]);
1832
2026
  }
1833
- return void 0;
1834
- }).filter((item) => item !== void 0);
1835
- return createLinks(tagItems);
1836
- } else {
1837
- const option = options.find((o) => o.id === value2);
1838
- if (option) {
1839
- const tagItem = {
1840
- id: value2,
1841
- label: option.title,
1842
- hue: option.color
1843
- };
1844
- return createLinks([
1845
- tagItem
1846
- ]);
1847
2027
  }
1848
2028
  }
2029
+ return "";
1849
2030
  }
1850
- return "";
2031
+ const value = model.getCellData(cell);
2032
+ return value !== void 0 ? String(value) : "";
1851
2033
  }
1852
- const value = model.getCellData(cell);
1853
- return value !== void 0 ? String(value) : "";
1854
- }
1855
- }, [
1856
- model,
1857
- editing
1858
- ]);
1859
- return /* @__PURE__ */ React6.createElement(GridCellEditor, {
1860
- extension,
1861
- getCellContent,
1862
- onBlur: handleBlur
1863
- });
2034
+ }, [
2035
+ model,
2036
+ editing
2037
+ ]);
2038
+ return /* @__PURE__ */ React6.createElement(GridCellEditor, {
2039
+ extension,
2040
+ getCellContent,
2041
+ onBlur: handleBlur
2042
+ });
2043
+ } finally {
2044
+ _effect.f();
2045
+ }
1864
2046
  };
1865
2047
  var determineNavigationAxis = ({ key }) => {
1866
2048
  switch (key) {
@@ -1888,288 +2070,294 @@ var determineNavigationDelta = ({ key, shift }) => {
1888
2070
  };
1889
2071
 
1890
2072
  // packages/ui/react-ui-table/src/components/Table/Table.tsx
1891
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/Table/Table.tsx";
1892
- 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";
1893
- 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";
2073
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/Table/Table.tsx";
1894
2074
  var TableRoot = ({ children, role }) => {
1895
- return /* @__PURE__ */ React7.createElement("div", {
1896
- role: "none",
1897
- 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]")
1898
- }, children);
2075
+ var _effect = _useSignals7();
2076
+ try {
2077
+ return /* @__PURE__ */ React7.createElement("div", {
2078
+ role: "none",
2079
+ 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]")
2080
+ }, children);
2081
+ } finally {
2082
+ _effect.f();
2083
+ }
1899
2084
  };
1900
- var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention, onRowClick }, forwardedRef) => {
1901
- const [dxGrid, setDxGrid] = useState2(null);
1902
- const { hasAttention } = useAttention(model?.id ?? "table");
1903
- const { t } = useTranslation3(translationKey);
1904
- const modals = useMemo4(() => new ModalController(), []);
1905
- const frozen = useMemo4(() => {
1906
- const noActionColumn = model?.features.dataEditable === false && model?.features.schemaEditable === false && model.rowActions.length === 0;
1907
- return {
1908
- frozenRowsStart: 1,
1909
- frozenColsStart: model?.features.selection.enabled ? 1 : 0,
1910
- frozenColsEnd: noActionColumn ? 0 : 1
1911
- };
1912
- }, [
1913
- model
1914
- ]);
1915
- useEffect2(() => {
1916
- if (!presentation || !dxGrid) {
1917
- return;
1918
- }
1919
- dxGrid.getCells = (range, plane) => presentation.getCells(range, plane);
1920
- }, [
1921
- presentation,
1922
- dxGrid
1923
- ]);
1924
- useImperativeHandle(forwardedRef, () => {
1925
- if (!presentation || !dxGrid) {
1926
- return {};
1927
- }
1928
- return {
1929
- update: (cell) => {
1930
- if (cell) {
1931
- dxGrid.updateIfWithinBounds(cell);
1932
- } else {
1933
- dxGrid.updateCells(true);
1934
- dxGrid.requestUpdate();
1935
- }
2085
+ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention, schema, onRowClick }, forwardedRef) => {
2086
+ var _effect = _useSignals7();
2087
+ try {
2088
+ const [dxGrid, setDxGrid] = useState2(null);
2089
+ const { hasAttention } = useAttention(model?.id ?? "table");
2090
+ const { t } = useTranslation3(translationKey);
2091
+ const modals = useMemo5(() => new ModalController(), []);
2092
+ const frozen = useMemo5(() => {
2093
+ const noActionColumn = model?.features.dataEditable === false && model?.features.schemaEditable === false && model.rowActions.length === 0;
2094
+ return {
2095
+ frozenRowsStart: 1,
2096
+ frozenColsStart: model?.features.selection.enabled ? 1 : 0,
2097
+ frozenColsEnd: noActionColumn ? 0 : 1
2098
+ };
2099
+ }, [
2100
+ model
2101
+ ]);
2102
+ const getCells = useCallback5((range, plane) => presentation?.getCells(range, plane) ?? {}, [
2103
+ presentation
2104
+ ]);
2105
+ useEffect3(() => {
2106
+ if (!presentation || !dxGrid) {
2107
+ return;
1936
2108
  }
1937
- };
1938
- }, [
1939
- presentation,
1940
- dxGrid
1941
- ]);
1942
- const handleGridClick = useCallback4((event) => {
1943
- const rowIndex = safeParseInt(event.target.ariaRowIndex ?? "");
1944
- if (rowIndex != null) {
1945
- if (onRowClick) {
1946
- const row = model?.getRowAt(rowIndex);
1947
- row && onRowClick(row);
1948
- }
1949
- if (model?.features.selection.enabled && model?.selection.selectionMode === "single") {
1950
- model.selection.toggleSelectionForRowIndex(rowIndex);
2109
+ dxGrid.getCells = getCells;
2110
+ }, [
2111
+ presentation,
2112
+ dxGrid,
2113
+ getCells
2114
+ ]);
2115
+ useImperativeHandle(forwardedRef, () => {
2116
+ if (!presentation || !dxGrid) {
2117
+ return {};
1951
2118
  }
1952
- }
1953
- if (!modals) {
1954
- return;
1955
- }
1956
- const buttonSelector = Object.values(tableButtons).map((button) => `button[${button.attr}]`).join(",");
1957
- const tableButtonElement = event.target.closest(buttonSelector);
1958
- if (tableButtonElement) {
1959
- const button = Object.values(tableButtons).find((btn) => tableButtonElement.hasAttribute(btn.attr));
1960
- if (!button) {
2119
+ return {
2120
+ update: (cell) => {
2121
+ if (cell) {
2122
+ dxGrid.updateIfWithinBounds(cell);
2123
+ } else {
2124
+ dxGrid.updateCells(true);
2125
+ dxGrid.requestUpdate();
2126
+ }
2127
+ }
2128
+ };
2129
+ }, [
2130
+ presentation,
2131
+ dxGrid
2132
+ ]);
2133
+ const handleGridClick = useCallback5((event) => {
2134
+ const rowIndex = safeParseInt(event.target.ariaRowIndex ?? "");
2135
+ if (rowIndex != null) {
2136
+ if (onRowClick) {
2137
+ const row = model?.getRowAt(rowIndex);
2138
+ row && onRowClick(row);
2139
+ }
2140
+ if (model?.features.selection.enabled && model?.selection.selectionMode === "single") {
2141
+ model.selection.toggleSelectionForRowIndex(rowIndex);
2142
+ }
2143
+ }
2144
+ if (!modals) {
1961
2145
  return;
1962
2146
  }
1963
- modals.setTrigger(tableButtonElement);
1964
- const data = button.getData(tableButtonElement);
1965
- switch (data.type) {
1966
- case "rowMenu": {
1967
- modals.showRowMenu(data.rowIndex);
1968
- break;
2147
+ const buttonSelector = Object.values(tableButtons).map((button) => `button[${button.attr}]`).join(",");
2148
+ const tableButtonElement = event.target.closest(buttonSelector);
2149
+ if (tableButtonElement) {
2150
+ const button = Object.values(tableButtons).find((btn) => tableButtonElement.hasAttribute(btn.attr));
2151
+ if (!button) {
2152
+ return;
1969
2153
  }
1970
- case "columnSettings": {
1971
- modals.showColumnMenu(data.fieldId);
1972
- break;
1973
- }
1974
- case "newColumn": {
1975
- modals.showColumnCreator();
1976
- break;
2154
+ modals.setTrigger(tableButtonElement);
2155
+ const data = button.getData(tableButtonElement);
2156
+ switch (data.type) {
2157
+ case "rowMenu": {
2158
+ modals.showRowMenu(data.rowIndex);
2159
+ break;
2160
+ }
2161
+ case "columnSettings": {
2162
+ modals.showColumnMenu(data.fieldId);
2163
+ break;
2164
+ }
2165
+ case "newColumn": {
2166
+ modals.showColumnCreator();
2167
+ break;
2168
+ }
2169
+ case "sort": {
2170
+ model?.sorting?.toggleSort(data.fieldId);
2171
+ break;
2172
+ }
1977
2173
  }
1978
- case "referencedCell": {
1979
- modals.showReferencePanel(data.targetId, data.schemaId);
1980
- break;
2174
+ return;
2175
+ }
2176
+ const controlSelector = Object.values(tableControls).map((control) => `input[${control.attr}]`).join(",");
2177
+ const controlElement = event.target.closest(controlSelector);
2178
+ if (controlElement) {
2179
+ const control = Object.values(tableControls).find((ctrl) => controlElement.hasAttribute(ctrl.attr));
2180
+ if (!control) {
2181
+ return;
1981
2182
  }
1982
- case "sort": {
1983
- model?.sorting?.toggleSort(data.fieldId);
1984
- break;
2183
+ const data = control.getData(controlElement);
2184
+ switch (data.type) {
2185
+ case "checkbox": {
2186
+ if (data.header) {
2187
+ model?.selection.setSelection(model.selection.allRowsSeleted.value ? "none" : "all");
2188
+ } else {
2189
+ model?.selection.toggleSelectionForRowIndex(data.rowIndex);
2190
+ }
2191
+ break;
2192
+ }
2193
+ case "switch": {
2194
+ if (model) {
2195
+ model.updateCellData({
2196
+ row: data.rowIndex,
2197
+ col: data.colIndex
2198
+ }, (value) => !value);
2199
+ }
2200
+ break;
2201
+ }
1985
2202
  }
1986
2203
  }
1987
- return;
1988
- }
1989
- const controlSelector = Object.values(tableControls).map((control) => `input[${control.attr}]`).join(",");
1990
- const controlElement = event.target.closest(controlSelector);
1991
- if (controlElement) {
1992
- const control = Object.values(tableControls).find((ctrl) => controlElement.hasAttribute(ctrl.attr));
1993
- if (!control) {
2204
+ }, [
2205
+ model,
2206
+ modals
2207
+ ]);
2208
+ const handleFocus = useCallback5((increment, delta) => {
2209
+ if (dxGrid) {
2210
+ dxGrid.refocus(increment, delta);
2211
+ }
2212
+ }, [
2213
+ dxGrid
2214
+ ]);
2215
+ const handleEnter = useCallback5((cell) => {
2216
+ if (!model?.features.dataEditable) {
1994
2217
  return;
1995
2218
  }
1996
- const data = control.getData(controlElement);
1997
- switch (data.type) {
1998
- case "checkbox": {
1999
- if (data.header) {
2000
- model?.selection.setSelection(model.selection.allRowsSeleted.value ? "none" : "all");
2001
- } else {
2002
- model?.selection.toggleSelectionForRowIndex(data.rowIndex);
2003
- }
2004
- break;
2219
+ if (model && cell.row === model.getRowCount() - 1) {
2220
+ model.insertRow(cell.row);
2221
+ if (dxGrid) {
2222
+ requestAnimationFrame(() => {
2223
+ dxGrid?.scrollToRow(cell.row + 1);
2224
+ dxGrid?.refocus("row", 1);
2225
+ });
2005
2226
  }
2006
- case "switch": {
2007
- if (model) {
2008
- model.updateCellData({
2009
- row: data.rowIndex,
2010
- col: data.colIndex
2011
- }, (value) => !value);
2012
- }
2227
+ }
2228
+ }, [
2229
+ model,
2230
+ dxGrid
2231
+ ]);
2232
+ const handleKeyDown = useCallback5((event) => {
2233
+ if (!model?.features.dataEditable) {
2234
+ return;
2235
+ }
2236
+ const cell = closestCell(event.target);
2237
+ if (!model || !cell) {
2238
+ return;
2239
+ }
2240
+ switch (event.key) {
2241
+ case "Backspace":
2242
+ case "Delete": {
2243
+ model.setCellData(cell, void 0);
2013
2244
  break;
2014
2245
  }
2015
2246
  }
2016
- }
2017
- }, [
2018
- model,
2019
- modals
2020
- ]);
2021
- const handleFocus = useCallback4((increment, delta) => {
2022
- if (dxGrid) {
2023
- dxGrid.refocus(increment, delta);
2024
- }
2025
- }, [
2026
- dxGrid
2027
- ]);
2028
- const handleEnter = useCallback4((cell) => {
2029
- if (!model?.features.dataEditable) {
2030
- return;
2031
- }
2032
- if (model && cell.row === model.getRowCount() - 1) {
2033
- model.insertRow(cell.row);
2034
- if (dxGrid) {
2035
- requestAnimationFrame(() => {
2036
- dxGrid?.scrollToRow(cell.row + 1);
2037
- dxGrid?.refocus("row", 1);
2038
- });
2247
+ }, [
2248
+ model
2249
+ ]);
2250
+ const handleAxisResize = useCallback5((event) => {
2251
+ if (event.axis === "col") {
2252
+ const columnIndex = parseInt(event.index, 10);
2253
+ model?.setColumnWidth(columnIndex, event.size);
2039
2254
  }
2040
- }
2041
- }, [
2042
- model,
2043
- dxGrid
2044
- ]);
2045
- const handleKeyDown = useCallback4((event) => {
2046
- if (!model?.features.dataEditable) {
2047
- return;
2048
- }
2049
- const cell = closestCell(event.target);
2050
- if (!model || !cell) {
2051
- return;
2052
- }
2053
- switch (event.key) {
2054
- case "Backspace":
2055
- case "Delete": {
2056
- model.setCellData(cell, void 0);
2057
- break;
2255
+ }, [
2256
+ model
2257
+ ]);
2258
+ const handleWheel = useCallback5((event) => {
2259
+ if (!ignoreAttention && !hasAttention) {
2260
+ event.stopPropagation();
2058
2261
  }
2059
- }
2060
- }, [
2061
- model
2062
- ]);
2063
- const handleAxisResize = useCallback4((event) => {
2064
- if (event.axis === "col") {
2065
- const columnIndex = parseInt(event.index, 10);
2066
- model?.setColumnWidth(columnIndex, event.size);
2067
- }
2068
- }, [
2069
- model
2070
- ]);
2071
- const handleWheel = useCallback4((event) => {
2072
- if (!ignoreAttention && !hasAttention) {
2073
- event.stopPropagation();
2074
- }
2075
- }, [
2076
- hasAttention,
2077
- ignoreAttention
2078
- ]);
2079
- const handleNewColumn = useCallback4(() => {
2080
- const columns = model?.getColumnCount();
2081
- if (dxGrid && columns) {
2082
- dxGrid.scrollToColumn(columns - 1);
2083
- }
2084
- }, [
2085
- model,
2086
- dxGrid
2087
- ]);
2088
- const handleQuery = useCallback4(async ({ field, props }, text) => {
2089
- if (model && props.referenceSchema && field.referencePath) {
2090
- const space = model.space;
2091
- invariant3(space, void 0, {
2092
- F: __dxlog_file4,
2093
- L: 312,
2094
- S: void 0,
2095
- A: [
2096
- "space",
2097
- ""
2098
- ]
2099
- });
2100
- const schema = space.db.schemaRegistry.getSchema(props.referenceSchema);
2101
- if (schema) {
2102
- const { objects } = await space.db.query(Filter.schema(schema)).run();
2103
- const options = objects.map((obj) => {
2104
- const value = getValue4(obj, field.referencePath);
2105
- if (!value || typeof value !== "string") {
2106
- return void 0;
2107
- }
2108
- return {
2109
- label: value,
2110
- data: obj
2111
- };
2112
- }).filter(isNotFalsy);
2113
- return [
2114
- ...options,
2115
- {
2116
- label: t("create new object label", {
2117
- text
2118
- }),
2119
- data: createOption(text)
2120
- }
2121
- ];
2262
+ }, [
2263
+ hasAttention,
2264
+ ignoreAttention
2265
+ ]);
2266
+ const handleNewColumn = useCallback5(() => {
2267
+ const columns = model?.getColumnCount();
2268
+ if (dxGrid && columns) {
2269
+ dxGrid.scrollToColumn(columns - 1);
2122
2270
  }
2271
+ }, [
2272
+ model,
2273
+ dxGrid
2274
+ ]);
2275
+ const handleQuery = useCallback5(async ({ field, props }, text) => {
2276
+ if (model && props.referenceSchema && field.referencePath) {
2277
+ const space = model.space;
2278
+ invariant4(space, void 0, {
2279
+ F: __dxlog_file5,
2280
+ L: 309,
2281
+ S: void 0,
2282
+ A: [
2283
+ "space",
2284
+ ""
2285
+ ]
2286
+ });
2287
+ const schema2 = space.db.schemaRegistry.getSchema(props.referenceSchema);
2288
+ if (schema2) {
2289
+ const { objects } = await space.db.query(Filter.type(schema2)).run();
2290
+ const options = objects.map((obj) => {
2291
+ const value = getValue4(obj, field.referencePath);
2292
+ if (!value || typeof value !== "string") {
2293
+ return void 0;
2294
+ }
2295
+ return {
2296
+ label: value,
2297
+ data: obj
2298
+ };
2299
+ }).filter(isNotFalsy);
2300
+ return [
2301
+ ...options,
2302
+ {
2303
+ label: t("create new object label", {
2304
+ text
2305
+ }),
2306
+ data: createOption(text)
2307
+ }
2308
+ ];
2309
+ }
2310
+ }
2311
+ return [];
2312
+ }, [
2313
+ model,
2314
+ t
2315
+ ]);
2316
+ if (!model || !modals) {
2317
+ return /* @__PURE__ */ React7.createElement("span", {
2318
+ role: "none",
2319
+ className: "attention-surface"
2320
+ });
2123
2321
  }
2124
- return [];
2125
- }, [
2126
- model,
2127
- t
2128
- ]);
2129
- if (!model || !modals) {
2130
- return /* @__PURE__ */ React7.createElement("span", {
2131
- role: "none",
2132
- className: "attention-surface"
2133
- });
2322
+ return /* @__PURE__ */ React7.createElement(Grid.Root, {
2323
+ id: model.id ?? "table-grid"
2324
+ }, /* @__PURE__ */ React7.createElement(TableValueEditor, {
2325
+ model,
2326
+ modals,
2327
+ schema,
2328
+ onEnter: handleEnter,
2329
+ onFocus: handleFocus,
2330
+ onQuery: handleQuery
2331
+ }), /* @__PURE__ */ React7.createElement(Grid.Content, {
2332
+ className: mx2("[--dx-grid-base:var(--baseSurface)]", gridSeparatorInlineEnd, gridSeparatorBlockEnd),
2333
+ frozen,
2334
+ // getCells={getCells}
2335
+ columns: model.columnMeta.value,
2336
+ limitRows: model.getRowCount() ?? 0,
2337
+ limitColumns: model.view?.fields?.length ?? 0,
2338
+ overscroll: "trap",
2339
+ onAxisResize: handleAxisResize,
2340
+ onClick: handleGridClick,
2341
+ onKeyDown: handleKeyDown,
2342
+ onWheelCapture: handleWheel,
2343
+ ref: setDxGrid
2344
+ }), /* @__PURE__ */ React7.createElement(RowActionsMenu, {
2345
+ model,
2346
+ modals
2347
+ }), /* @__PURE__ */ React7.createElement(ColumnActionsMenu, {
2348
+ model,
2349
+ modals
2350
+ }), /* @__PURE__ */ React7.createElement(ColumnSettings, {
2351
+ model,
2352
+ modals,
2353
+ onNewColumn: handleNewColumn
2354
+ }), /* @__PURE__ */ React7.createElement(CreateRefPanel, {
2355
+ model,
2356
+ modals
2357
+ }));
2358
+ } finally {
2359
+ _effect.f();
2134
2360
  }
2135
- return /* @__PURE__ */ React7.createElement(Grid.Root, {
2136
- id: model.id ?? "table-grid"
2137
- }, /* @__PURE__ */ React7.createElement(TableCellEditor, {
2138
- model,
2139
- modals,
2140
- onEnter: handleEnter,
2141
- onFocus: handleFocus,
2142
- onQuery: handleQuery
2143
- }), /* @__PURE__ */ React7.createElement(Grid.Content, {
2144
- className: mx2("[--dx-grid-base:var(--surface-bg)]", inlineEndLine, blockEndLine),
2145
- frozen,
2146
- // getCells={getCells}
2147
- columns: model.columnMeta.value,
2148
- limitRows: model.getRowCount() ?? 0,
2149
- limitColumns: model.view?.fields?.length ?? 0,
2150
- overscroll: "trap",
2151
- onAxisResize: handleAxisResize,
2152
- onClick: handleGridClick,
2153
- onKeyDown: handleKeyDown,
2154
- onWheelCapture: handleWheel,
2155
- ref: setDxGrid
2156
- }), /* @__PURE__ */ React7.createElement(RowActionsMenu, {
2157
- model,
2158
- modals
2159
- }), /* @__PURE__ */ React7.createElement(ColumnActionsMenu, {
2160
- model,
2161
- modals
2162
- }), /* @__PURE__ */ React7.createElement(ColumnSettings, {
2163
- model,
2164
- modals,
2165
- onNewColumn: handleNewColumn
2166
- }), /* @__PURE__ */ React7.createElement(CreateRefPanel, {
2167
- model,
2168
- modals
2169
- }), /* @__PURE__ */ React7.createElement(RefPanel, {
2170
- model,
2171
- modals
2172
- }));
2173
2361
  });
2174
2362
  var Table = {
2175
2363
  Root: TableRoot,
@@ -2177,152 +2365,167 @@ var Table = {
2177
2365
  };
2178
2366
 
2179
2367
  // packages/ui/react-ui-table/src/components/Table/DynamicTable.tsx
2180
- import React8, { useRef as useRef2, useMemo as useMemo5, useCallback as useCallback5 } from "react";
2368
+ import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
2369
+ import React8, { useRef as useRef3, useMemo as useMemo6, useCallback as useCallback6 } from "react";
2181
2370
  import { useDefaultValue } from "@dxos/react-ui";
2182
2371
  import { mx as mx3 } from "@dxos/react-ui-theme";
2183
2372
 
2184
2373
  // packages/ui/react-ui-table/src/hooks/useTableModel.ts
2374
+ import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
2185
2375
  import { effect as effect3 } from "@preact/signals-core";
2186
- import { useEffect as useEffect3, useState as useState3 } from "react";
2376
+ import { useEffect as useEffect4, useState as useState3 } from "react";
2187
2377
  import { fullyQualifiedId, getSpace } from "@dxos/react-client/echo";
2188
2378
  import { useSelectionActions } from "@dxos/react-ui-attention";
2189
2379
  import { isNonNullable } from "@dxos/util";
2190
2380
  var useTableModel = ({ table, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
2191
- const [model, setModel] = useState3();
2192
- useEffect3(() => {
2193
- if (!table || !projection) {
2194
- return;
2195
- }
2196
- let model2;
2197
- const t = setTimeout(async () => {
2198
- model2 = new TableModel({
2199
- id: fullyQualifiedId(table),
2200
- space: getSpace(table),
2201
- view: table.view?.target,
2202
- projection,
2203
- features,
2204
- rowActions,
2205
- onRowAction,
2206
- ...props
2381
+ var _effect = _useSignals8();
2382
+ try {
2383
+ const [model, setModel] = useState3();
2384
+ useEffect4(() => {
2385
+ if (!table || !projection) {
2386
+ return;
2387
+ }
2388
+ let model2;
2389
+ const t = setTimeout(async () => {
2390
+ model2 = new TableModel({
2391
+ id: fullyQualifiedId(table),
2392
+ space: getSpace(table),
2393
+ view: table.view?.target,
2394
+ projection,
2395
+ features,
2396
+ rowActions,
2397
+ onRowAction,
2398
+ ...props
2399
+ });
2400
+ await model2.open();
2401
+ setModel(model2);
2207
2402
  });
2208
- await model2.open();
2209
- setModel(model2);
2210
- });
2211
- return () => {
2212
- clearTimeout(t);
2213
- void model2?.close();
2214
- };
2215
- }, [
2216
- table,
2217
- projection,
2218
- table?.view?.target,
2219
- features,
2220
- rowActions
2221
- ]);
2222
- useEffect3(() => {
2223
- if (rows) {
2224
- model?.setRows(rows);
2225
- }
2226
- }, [
2227
- model,
2228
- rows
2229
- ]);
2230
- const { select, clear } = useSelectionActions([
2231
- table?.id,
2232
- table?.view?.target?.query.typename
2233
- ].filter(isNonNullable));
2234
- useEffect3(() => {
2235
- if (!model) {
2236
- return;
2237
- }
2238
- const unsubscribe = effect3(() => {
2239
- const selectedItems = [
2240
- ...model.selection.selection.value
2241
- ];
2242
- select(selectedItems);
2243
- onSelectionChanged?.(selectedItems);
2244
- });
2245
- return () => {
2246
- clear();
2247
- unsubscribe();
2248
- };
2249
- }, [
2250
- model,
2251
- onSelectionChanged
2252
- ]);
2253
- return model;
2403
+ return () => {
2404
+ clearTimeout(t);
2405
+ void model2?.close();
2406
+ };
2407
+ }, [
2408
+ table,
2409
+ projection,
2410
+ table?.view?.target,
2411
+ features,
2412
+ rowActions
2413
+ ]);
2414
+ useEffect4(() => {
2415
+ if (rows) {
2416
+ model?.setRows(rows);
2417
+ }
2418
+ }, [
2419
+ model,
2420
+ rows
2421
+ ]);
2422
+ const { multiSelect, clear } = useSelectionActions([
2423
+ table?.id,
2424
+ table?.view?.target?.query.typename
2425
+ ].filter(isNonNullable));
2426
+ useEffect4(() => {
2427
+ if (!model) {
2428
+ return;
2429
+ }
2430
+ const unsubscribe = effect3(() => {
2431
+ const selectedItems = [
2432
+ ...model.selection.selection.value
2433
+ ];
2434
+ multiSelect(selectedItems);
2435
+ onSelectionChanged?.(selectedItems);
2436
+ });
2437
+ return () => {
2438
+ clear();
2439
+ unsubscribe();
2440
+ };
2441
+ }, [
2442
+ model,
2443
+ onSelectionChanged
2444
+ ]);
2445
+ return model;
2446
+ } finally {
2447
+ _effect.f();
2448
+ }
2254
2449
  };
2255
2450
 
2256
2451
  // packages/ui/react-ui-table/src/components/Table/DynamicTable.tsx
2257
2452
  var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, properties, jsonSchema, schema, rowActions, onRowClick, onRowAction, ...props }) => {
2258
- const { table, projection } = useMemo5(() => {
2259
- const props2 = getBaseSchems({
2260
- typename: name,
2453
+ var _effect = _useSignals9();
2454
+ try {
2455
+ const { table, projection } = useMemo6(() => {
2456
+ const props2 = getBaseSchema({
2457
+ typename: name,
2458
+ properties,
2459
+ jsonSchema,
2460
+ schema
2461
+ });
2462
+ return makeDynamicTable({
2463
+ ...props2,
2464
+ properties
2465
+ });
2466
+ }, [
2467
+ name,
2261
2468
  properties,
2262
- jsonSchema,
2263
- schema
2264
- });
2265
- return makeDynamicTable({
2266
- ...props2,
2267
- properties
2469
+ schema,
2470
+ jsonSchema
2471
+ ]);
2472
+ const tableRef = useRef3(null);
2473
+ const handleCellUpdate = useCallback6((cell) => {
2474
+ tableRef.current?.update?.(cell);
2475
+ }, []);
2476
+ const handleRowOrderChange = useCallback6(() => {
2477
+ tableRef.current?.update?.();
2478
+ }, []);
2479
+ const features = useDefaultValue(props.features, () => ({
2480
+ selection: {
2481
+ enabled: false
2482
+ },
2483
+ dataEditable: false
2484
+ }));
2485
+ const model = useTableModel({
2486
+ table,
2487
+ rows,
2488
+ projection,
2489
+ features,
2490
+ rowActions,
2491
+ onCellUpdate: handleCellUpdate,
2492
+ onRowOrderChange: handleRowOrderChange,
2493
+ onRowAction
2268
2494
  });
2269
- }, [
2270
- name,
2271
- properties,
2272
- schema,
2273
- jsonSchema
2274
- ]);
2275
- const tableRef = useRef2(null);
2276
- const handleCellUpdate = useCallback5((cell) => {
2277
- tableRef.current?.update?.(cell);
2278
- }, []);
2279
- const handleRowOrderChange = useCallback5(() => {
2280
- tableRef.current?.update?.();
2281
- }, []);
2282
- const features = useDefaultValue(props.features, () => ({
2283
- selection: {
2284
- enabled: false
2285
- },
2286
- dataEditable: false
2287
- }));
2288
- const model = useTableModel({
2289
- table,
2290
- rows,
2291
- projection,
2292
- features,
2293
- rowActions,
2294
- onCellUpdate: handleCellUpdate,
2295
- onRowOrderChange: handleRowOrderChange,
2296
- onRowAction
2297
- });
2298
- const presentation = useMemo5(() => {
2299
- if (model) {
2300
- return new TablePresentation(model);
2301
- }
2302
- }, [
2303
- model
2304
- ]);
2305
- return /* @__PURE__ */ React8.createElement("div", {
2306
- role: "none",
2307
- className: mx3("is-full bs-full grow grid", classNames)
2308
- }, /* @__PURE__ */ React8.createElement("div", {
2309
- role: "none",
2310
- className: "grid min-bs-0 overflow-hidden"
2311
- }, /* @__PURE__ */ React8.createElement(Table.Root, null, /* @__PURE__ */ React8.createElement(Table.Main, {
2312
- ref: tableRef,
2313
- model,
2314
- presentation,
2315
- ignoreAttention: true,
2316
- onRowClick
2317
- }))));
2495
+ const presentation = useMemo6(() => {
2496
+ if (model) {
2497
+ return new TablePresentation(model);
2498
+ }
2499
+ }, [
2500
+ model
2501
+ ]);
2502
+ return /* @__PURE__ */ React8.createElement("div", {
2503
+ role: "none",
2504
+ className: mx3("is-full bs-full grow grid", classNames)
2505
+ }, /* @__PURE__ */ React8.createElement("div", {
2506
+ role: "none",
2507
+ className: "grid min-bs-0 overflow-hidden"
2508
+ }, /* @__PURE__ */ React8.createElement(Table.Root, null, /* @__PURE__ */ React8.createElement(Table.Main, {
2509
+ ref: tableRef,
2510
+ model,
2511
+ presentation,
2512
+ ignoreAttention: true,
2513
+ onRowClick
2514
+ }))));
2515
+ } finally {
2516
+ _effect.f();
2517
+ }
2318
2518
  };
2319
2519
 
2320
2520
  // packages/ui/react-ui-table/src/components/TableToolbar/TableToolbar.tsx
2321
- import React9, { useCallback as useCallback6, useMemo as useMemo6 } from "react";
2322
- import { create as create4 } from "@dxos/live-object";
2521
+ import { useSignals as _useSignals10 } from "@preact-signals/safe-react/tracking";
2522
+ import { Rx } from "@effect-rx/rx-react";
2523
+ import React9, { useMemo as useMemo7 } from "react";
2524
+ import { live as live4 } from "@dxos/live-object";
2323
2525
  import { createGapSeparator, createMenuAction, MenuProvider, ToolbarMenu, useMenuActions } from "@dxos/react-ui-menu";
2324
- var createTableToolbarActions = (state) => {
2325
- const add = createMenuAction("add-row", {
2526
+ import { rxFromSignal } from "@dxos/react-ui-menu";
2527
+ var createTableToolbarActions = ({ state, onAdd, onSave, customActions }) => Rx.make((get) => {
2528
+ const add = createMenuAction("add-row", onAdd, {
2326
2529
  type: "add-row",
2327
2530
  icon: "ph--plus--regular",
2328
2531
  label: [
@@ -2333,7 +2536,7 @@ var createTableToolbarActions = (state) => {
2333
2536
  ],
2334
2537
  testId: "table.toolbar.add-row"
2335
2538
  });
2336
- const save = createMenuAction("save-view", {
2539
+ const save = createMenuAction("save-view", onSave, {
2337
2540
  type: "save-view",
2338
2541
  icon: "ph--floppy-disk--regular",
2339
2542
  label: [
@@ -2344,49 +2547,55 @@ var createTableToolbarActions = (state) => {
2344
2547
  ],
2345
2548
  testId: "table.toolbar.save-view",
2346
2549
  iconOnly: false,
2347
- hidden: !state.viewDirty
2550
+ hidden: get(rxFromSignal(() => !state.viewDirty))
2348
2551
  });
2349
2552
  const gap = createGapSeparator();
2350
- const comment = createMenuAction("comment", {
2351
- type: "comment",
2352
- icon: "ph--chat-text--regular",
2353
- label: [
2354
- "create comment",
2355
- {
2356
- ns: translationKey
2357
- }
2358
- ],
2359
- testId: "table.toolbar.comment"
2360
- });
2361
2553
  const nodes = [
2362
2554
  add,
2363
2555
  save,
2364
- ...gap.nodes,
2365
- comment
2556
+ ...gap.nodes
2366
2557
  ];
2558
+ const edges = nodes.map(({ id: target }) => ({
2559
+ source: "root",
2560
+ target
2561
+ }));
2562
+ if (customActions) {
2563
+ const custom = get(customActions);
2564
+ nodes.push(...custom.nodes);
2565
+ edges.push(...custom.edges);
2566
+ }
2367
2567
  return {
2368
2568
  nodes,
2369
- edges: nodes.map(({ id: target }) => ({
2370
- source: "root",
2371
- target
2372
- }))
2569
+ edges
2373
2570
  };
2374
- };
2375
- var TableToolbar = ({ classNames, viewDirty, attendableId, onAction }) => {
2376
- const state = useMemo6(() => create4({
2377
- viewDirty
2378
- }), []);
2379
- const actionsCreator = useCallback6(() => createTableToolbarActions(state), [
2380
- state
2381
- ]);
2382
- const menu = useMenuActions(actionsCreator);
2383
- return /* @__PURE__ */ React9.createElement(MenuProvider, {
2384
- ...menu,
2385
- attendableId,
2386
- onAction
2387
- }, /* @__PURE__ */ React9.createElement(ToolbarMenu, {
2388
- classNames
2389
- }));
2571
+ });
2572
+ var TableToolbar = ({ classNames, viewDirty, attendableId, onAdd, onSave, customActions }) => {
2573
+ var _effect = _useSignals10();
2574
+ try {
2575
+ const state = useMemo7(() => live4({
2576
+ viewDirty
2577
+ }), []);
2578
+ const actionsCreator = useMemo7(() => createTableToolbarActions({
2579
+ state,
2580
+ onAdd,
2581
+ onSave,
2582
+ customActions
2583
+ }), [
2584
+ state,
2585
+ onAdd,
2586
+ onSave,
2587
+ customActions
2588
+ ]);
2589
+ const menu = useMenuActions(actionsCreator);
2590
+ return /* @__PURE__ */ React9.createElement(MenuProvider, {
2591
+ ...menu,
2592
+ attendableId
2593
+ }, /* @__PURE__ */ React9.createElement(ToolbarMenu, {
2594
+ classNames
2595
+ }));
2596
+ } finally {
2597
+ _effect.f();
2598
+ }
2390
2599
  };
2391
2600
  export {
2392
2601
  BUTTON_IDENTIFIERS,
@@ -2402,9 +2611,10 @@ export {
2402
2611
  TableToolbar,
2403
2612
  TableType,
2404
2613
  cellClassesForRowSelection,
2405
- getBaseSchems,
2614
+ getBaseSchema,
2406
2615
  initializeTable,
2407
2616
  makeDynamicTable,
2617
+ narrowSchema,
2408
2618
  tableButtons,
2409
2619
  tableControls,
2410
2620
  touch,