@dxos/react-ui-table 0.8.2-main.fbd8ed0 → 0.8.2-staging.42af850

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 (47) hide show
  1. package/dist/lib/browser/{chunk-PFFO5LYM.mjs → chunk-U6LL2AVU.mjs} +5 -6
  2. package/dist/lib/browser/chunk-U6LL2AVU.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +972 -911
  4. package/dist/lib/browser/index.mjs.map +3 -3
  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-VREQOYRW.cjs → chunk-CXDGXPM6.cjs} +7 -8
  8. package/dist/lib/node/chunk-CXDGXPM6.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +973 -912
  10. package/dist/lib/node/index.cjs.map +3 -3
  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-34JG3SDI.mjs → chunk-EFSM52KQ.mjs} +5 -6
  15. package/dist/lib/node-esm/chunk-EFSM52KQ.mjs.map +7 -0
  16. package/dist/lib/node-esm/index.mjs +972 -911
  17. package/dist/lib/node-esm/index.mjs.map +3 -3
  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/Table.stories.d.ts.map +1 -1
  21. package/dist/types/src/components/Table/relations.stories.d.ts.map +1 -1
  22. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  23. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +6 -3
  24. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
  25. package/dist/types/src/components/testing.d.ts +4 -4
  26. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  27. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  28. package/dist/types/src/model/table-model.d.ts.map +1 -1
  29. package/dist/types/src/types/table.d.ts +2 -2
  30. package/dist/types/src/types/table.d.ts.map +1 -1
  31. package/dist/types/src/util/table.d.ts.map +1 -1
  32. package/package.json +41 -35
  33. package/src/components/Table/Table.stories.tsx +16 -28
  34. package/src/components/Table/relations.stories.tsx +1 -2
  35. package/src/components/TableCellEditor/FormCellEditor.tsx +2 -2
  36. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +2 -1
  37. package/src/components/TableToolbar/TableToolbar.tsx +62 -31
  38. package/src/hooks/useTableModel.ts +4 -2
  39. package/src/model/selection-model.ts +1 -1
  40. package/src/model/table-model.ts +1 -1
  41. package/src/model/table-presentation.ts +1 -1
  42. package/src/types/table.ts +2 -5
  43. package/src/util/table-buttons.ts +1 -1
  44. package/src/util/table.ts +3 -3
  45. package/dist/lib/browser/chunk-PFFO5LYM.mjs.map +0 -7
  46. package/dist/lib/node/chunk-VREQOYRW.cjs.map +0 -7
  47. package/dist/lib/node-esm/chunk-34JG3SDI.mjs.map +0 -7
@@ -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-34JG3SDI.mjs";
5
+ } from "./chunk-EFSM52KQ.mjs";
6
6
 
7
7
  // packages/ui/react-ui-table/src/translations.ts
8
8
  var translationKey = "table";
@@ -37,6 +37,7 @@ var translations_default = [
37
37
  ];
38
38
 
39
39
  // packages/ui/react-ui-table/src/components/Table/Table.tsx
40
+ import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
40
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
43
  import { invariant as invariant4 } from "@dxos/invariant";
@@ -48,109 +49,122 @@ 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";
154
168
  import { Schema } from "effect";
155
169
  import React3, { useCallback as useCallback2, useMemo as useMemo2 } from "react";
156
170
  import { live } from "@dxos/react-client/echo";
@@ -158,99 +172,110 @@ 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 = Schema.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(live(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))));
184
+ const [schema2] = space.db.schemaRegistry.query({
185
+ typename: state.typename
186
+ }).runSync();
187
+ if (schema2) {
188
+ const omit = Schema.omit("id");
189
+ return omit(schema2);
190
+ }
191
+ }, [
192
+ space,
193
+ state
194
+ ]);
195
+ const handleSave = useCallback2((values) => {
196
+ if (!model || !space || state?.type !== "createRefPanel") {
197
+ return;
198
+ }
199
+ const [schema2] = space.db.schemaRegistry.query({
200
+ typename: state.typename
201
+ }).runSync();
202
+ if (schema2) {
203
+ const obj = space.db.add(live(schema2, values));
204
+ state.onCreate?.(obj);
205
+ }
206
+ void modals.close();
207
+ }, [
208
+ modals,
209
+ space,
210
+ state
211
+ ]);
212
+ const handleCancel = useCallback2(() => {
213
+ if (model) {
214
+ modals.close();
215
+ }
216
+ }, [
217
+ modals
218
+ ]);
219
+ if (!model?.view || !model.projection) {
220
+ return null;
221
+ }
222
+ return /* @__PURE__ */ React3.createElement(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
+ }
225
244
  };
226
245
 
227
246
  // packages/ui/react-ui-table/src/components/Table/RowActionsMenu.tsx
247
+ import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
228
248
  import React4 from "react";
229
249
  import { DropdownMenu as DropdownMenu3, useTranslation as useTranslation2 } from "@dxos/react-ui";
230
250
  var RowActionsMenu = ({ model, modals }) => {
231
- const { t } = useTranslation2(translationKey);
232
- const hasSelection = model.selection.hasSelection.value;
233
- const state = modals.state.value;
234
- if (state?.type !== "row") {
235
- return null;
236
- }
237
- return /* @__PURE__ */ React4.createElement(DropdownMenu3.Root, {
238
- modal: false,
239
- open: true,
240
- onOpenChange: modals.close
241
- }, /* @__PURE__ */ React4.createElement(DropdownMenu3.VirtualTrigger, {
242
- virtualRef: modals.trigger
243
- }), /* @__PURE__ */ React4.createElement(DropdownMenu3.Content, null, /* @__PURE__ */ React4.createElement(DropdownMenu3.Viewport, null, model.features.dataEditable !== false && /* @__PURE__ */ React4.createElement(DropdownMenu3.Item, {
244
- "data-testid": "row-menu-delete",
245
- onClick: () => model.deleteRow(state.rowIndex)
246
- }, t(hasSelection ? "bulk delete row label" : "delete row label")), model.rowActions?.map((action) => /* @__PURE__ */ React4.createElement(DropdownMenu3.Item, {
247
- key: action.id,
248
- "data-testid": `row-action-${action.id}`,
249
- onClick: () => {
250
- modals.close();
251
- model.handleRowAction(action.id, state.rowIndex);
252
- }
253
- }, t(action.translationKey)))), /* @__PURE__ */ React4.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
+ }
254
279
  };
255
280
 
256
281
  // packages/ui/react-ui-table/src/model/table-model.ts
@@ -346,7 +371,7 @@ var setProperties = (view, projection, properties) => {
346
371
  var touch = (value) => value;
347
372
 
348
373
  // packages/ui/react-ui-table/src/util/table.ts
349
- import { Schema as Schema2, SchemaAST } from "effect";
374
+ import { Schema as Schema2 } from "effect";
350
375
  import { Format, FormatEnum, Ref, TypedObject, TypeEnum } from "@dxos/echo-schema";
351
376
  import { PublicKey } from "@dxos/react-client";
352
377
  import { live as live3 } from "@dxos/react-client/echo";
@@ -389,12 +414,12 @@ var ContactSchema = TypedObject({
389
414
  version: "0.1.0"
390
415
  })({
391
416
  name: Schema2.optional(Schema2.String).annotations({
392
- [SchemaAST.TitleAnnotationId]: "Name"
417
+ title: "Name"
393
418
  }),
394
419
  active: Schema2.optional(Schema2.Boolean),
395
420
  email: Schema2.optional(Format.Email),
396
421
  salary: Schema2.optional(Format.Currency()).annotations({
397
- [SchemaAST.TitleAnnotationId]: "Salary"
422
+ title: "Salary"
398
423
  })
399
424
  });
400
425
  var ContactFields = [
@@ -447,7 +472,7 @@ var BUTTON_IDENTIFIERS = {
447
472
  var createButton = ({ attr, data, disabled = false, icon, testId, type = "primary" }) => {
448
473
  const dataAttrs = Object.entries(data).map(([k, v]) => `${k}="${v}"`).join(" ");
449
474
  const positionClass = type === "primary" ? "inline-end-2" : "inline-end-9";
450
- 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>`;
451
476
  };
452
477
  var addColumnButton = {
453
478
  attr: BUTTON_IDENTIFIERS.newColumn,
@@ -603,12 +628,7 @@ var narrowSchema = (schema, paths) => {
603
628
  // packages/ui/react-ui-table/src/model/selection-model.ts
604
629
  var SelectionModel = class extends Resource {
605
630
  constructor(_rows, _selectionMode, _onSelectionChanged) {
606
- super();
607
- this._rows = _rows;
608
- this._selectionMode = _selectionMode;
609
- this._onSelectionChanged = _onSelectionChanged;
610
- this._selection = signal(/* @__PURE__ */ new Set());
611
- this._validSelectedIds = computed(() => {
631
+ super(), this._rows = _rows, this._selectionMode = _selectionMode, this._onSelectionChanged = _onSelectionChanged, this._selection = signal(/* @__PURE__ */ new Set()), this._validSelectedIds = computed(() => {
612
632
  const rows = this._rows.value;
613
633
  if (!rows) {
614
634
  return /* @__PURE__ */ new Set();
@@ -617,27 +637,21 @@ var SelectionModel = class extends Resource {
617
637
  return new Set([
618
638
  ...this._selection.value
619
639
  ].filter((id) => validIds.has(id)));
620
- });
621
- this._hasSelection = computed(() => this._validSelectedIds.value.size > 0);
622
- this._allSelected = computed(() => {
640
+ }), this._hasSelection = computed(() => this._validSelectedIds.value.size > 0), this._allSelected = computed(() => {
623
641
  const rows = this._rows.value;
624
642
  if (rows.length === 0) {
625
643
  return false;
626
644
  }
627
645
  return rows.every((row) => this._selection.value.has(row.id));
628
- });
629
- this.getSelectedRows = () => {
646
+ }), this.getSelectedRows = () => {
630
647
  const selectedIds = this._validSelectedIds.value;
631
648
  return this._rows.value.filter((row) => selectedIds.has(row.id));
632
- };
633
- this.isRowIndexSelected = (rowIndex) => {
649
+ }, this.isRowIndexSelected = (rowIndex) => {
634
650
  const row = this._rows.value[rowIndex];
635
651
  return this._selection.value.has(row.id);
636
- };
637
- this.isObjectSelected = (object) => {
652
+ }, this.isObjectSelected = (object) => {
638
653
  return this._selection.value.has(object.id);
639
- };
640
- this.toggleSelectionForRowIndex = (rowIndex) => {
654
+ }, this.toggleSelectionForRowIndex = (rowIndex) => {
641
655
  const row = this._rows.value[rowIndex];
642
656
  const newSelection = new Set(this._selection.value);
643
657
  if (newSelection.has(row.id)) {
@@ -649,8 +663,7 @@ var SelectionModel = class extends Resource {
649
663
  newSelection.add(row.id);
650
664
  }
651
665
  this._selection.value = newSelection;
652
- };
653
- this.setSelection = (mode) => {
666
+ }, this.setSelection = (mode) => {
654
667
  switch (mode) {
655
668
  case "all": {
656
669
  this._selection.value = new Set(this._rows.value.map((row) => row.id));
@@ -1426,7 +1439,7 @@ var TablePresentation = class {
1426
1439
  const targetObj = getValue3(obj, field.path)?.target;
1427
1440
  if (targetObj) {
1428
1441
  const dxn = getDXN(targetObj)?.toString();
1429
- cell.accessoryHtml = `<dx-ref-tag ref=${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>`;
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>`;
1430
1443
  }
1431
1444
  }
1432
1445
  if (props.format === FormatEnum4.Boolean) {
@@ -1618,6 +1631,7 @@ var cellClassesForRowSelection = (selected, selectionMode) => {
1618
1631
  };
1619
1632
 
1620
1633
  // packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx
1634
+ import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
1621
1635
  import React6, { useCallback as useCallback4, useMemo as useMemo4, useRef as useRef2 } from "react";
1622
1636
  import { FormatEnum as FormatEnum5, TypeEnum as TypeEnum4 } from "@dxos/echo-schema";
1623
1637
  import { invariant as invariant3 } from "@dxos/invariant";
@@ -1627,6 +1641,7 @@ import { cellQuery, editorKeys, parseCellIndex as parseCellIndex2, useGridContex
1627
1641
  import { tagPickerExtension, createLinks } from "@dxos/react-ui-tag-picker";
1628
1642
 
1629
1643
  // packages/ui/react-ui-table/src/components/TableCellEditor/FormCellEditor.tsx
1644
+ import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
1630
1645
  import React5, { useCallback as useCallback3, useEffect as useEffect2, useMemo as useMemo3, useRef } from "react";
1631
1646
  import { getSnapshot } from "@dxos/echo-schema";
1632
1647
  import { invariant as invariant2 } from "@dxos/invariant";
@@ -1636,89 +1651,94 @@ import { parseCellIndex, useGridContext as useGridContext2 } from "@dxos/react-u
1636
1651
  import { getDeep, setDeep } from "@dxos/util";
1637
1652
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/FormCellEditor.tsx";
1638
1653
  var FormCellEditor = ({ fieldProjection, model, schema, __gridScope }) => {
1639
- const { editing, setEditing } = useGridContext2("ArrayEditor", __gridScope);
1640
- const cellRef = useRef(null);
1641
- useEffect2(() => {
1642
- if (editing && editing.cellElement) {
1643
- cellRef.current = editing.cellElement;
1644
- }
1645
- }, [
1646
- editing?.cellElement
1647
- ]);
1648
- const narrowedSchema = useMemo3(() => {
1649
- if (!schema) {
1650
- return void 0;
1651
- }
1652
- return narrowSchema(schema, [
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),
1653
1674
  fieldProjection.field.path
1654
1675
  ]);
1655
- }, [
1656
- JSON.stringify(schema),
1657
- fieldProjection.field.path
1658
- ]);
1659
- const originalRow = useMemo3(() => {
1660
- if (model && editing) {
1661
- const cell = parseCellIndex(editing.index);
1662
- const row = model.getRowAt(cell.row);
1663
- invariant2(row, void 0, {
1664
- F: __dxlog_file3,
1665
- L: 47,
1666
- S: void 0,
1667
- A: [
1668
- "row",
1669
- ""
1670
- ]
1671
- });
1672
- return row;
1673
- }
1674
- return void 0;
1675
- }, [
1676
- model,
1677
- editing
1678
- ]);
1679
- const formValues = useMemo3(() => {
1680
- if (originalRow) {
1681
- return getSnapshot(originalRow);
1682
- }
1683
- }, [
1684
- originalRow
1685
- ]);
1686
- const handleSave = useCallback3((values) => {
1687
- const path = fieldProjection.field.path;
1688
- const value = getDeep(values, [
1689
- path
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
1690
1702
  ]);
1691
- setDeep(originalRow, [
1692
- path
1693
- ], value);
1694
- setEditing(null);
1695
- }, [
1696
- fieldProjection.field.path,
1697
- originalRow
1698
- ]);
1699
- const handleOpenChange = useCallback3((nextOpen) => {
1700
- if (nextOpen === false) {
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);
1701
1711
  setEditing(null);
1702
- }
1703
- }, [
1704
- setEditing
1705
- ]);
1706
- if (!editing) {
1707
- return null;
1708
- }
1709
- return /* @__PURE__ */ React5.createElement(Popover2.Root, {
1710
- open: editing !== null,
1711
- onOpenChange: handleOpenChange
1712
- }, /* @__PURE__ */ React5.createElement(Popover2.VirtualTrigger, {
1713
- virtualRef: cellRef
1714
- }), /* @__PURE__ */ React5.createElement(Popover2.Content, {
1715
- tabIndex: -1,
1716
- classNames: "popover-consistent-width"
1717
- }, /* @__PURE__ */ React5.createElement(Popover2.Arrow, null), /* @__PURE__ */ React5.createElement(Form2, {
1718
- values: formValues,
1719
- schema: narrowedSchema,
1720
- onSave: handleSave
1721
- })));
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
+ }
1722
1742
  };
1723
1743
 
1724
1744
  // packages/ui/react-ui-table/src/components/TableCellEditor/extension.ts
@@ -1769,250 +1789,260 @@ var createOption = (text) => ({
1769
1789
  });
1770
1790
  var isCreateOption = (data) => typeof data === "object" && data[newValue];
1771
1791
  var TableValueEditor = ({ model, modals, schema, onEnter, onFocus, onQuery, __gridScope }) => {
1772
- const { editing } = useGridContext3("TableValueEditor", __gridScope);
1773
- const fieldProjection = useMemo4(() => {
1774
- if (!model || !editing) {
1775
- return;
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
+ });
1776
1823
  }
1777
- const { col } = parseCellIndex2(editing.index);
1778
- const field = model.projection.view.fields[col];
1779
- const fieldProjection2 = model.projection.getFieldProjection(field.id);
1780
- invariant3(fieldProjection2, void 0, {
1781
- F: __dxlog_file4,
1782
- L: 73,
1783
- S: void 0,
1784
- A: [
1785
- "fieldProjection",
1786
- ""
1787
- ]
1788
- });
1789
- return fieldProjection2;
1790
- }, [
1791
- model,
1792
- editing
1793
- ]);
1794
- if (fieldProjection?.props.type === TypeEnum4.Array) {
1795
- return /* @__PURE__ */ React6.createElement(FormCellEditor, {
1796
- fieldProjection,
1824
+ return /* @__PURE__ */ React6.createElement(TableCellEditor, {
1797
1825
  model,
1798
- schema,
1826
+ modals,
1827
+ onEnter,
1828
+ onFocus,
1829
+ onQuery,
1799
1830
  __gridScope
1800
1831
  });
1832
+ } finally {
1833
+ _effect.f();
1801
1834
  }
1802
- return /* @__PURE__ */ React6.createElement(TableCellEditor, {
1803
- model,
1804
- modals,
1805
- onEnter,
1806
- onFocus,
1807
- onQuery,
1808
- __gridScope
1809
- });
1810
1835
  };
1811
1836
  var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }) => {
1812
- const { id: gridId, editing, setEditing } = useGridContext3("TableCellEditor", __gridScope);
1813
- const suppressNextBlur = useRef2(false);
1814
- const { themeMode } = useThemeContext();
1815
- const fieldProjection = useMemo4(() => {
1816
- if (!model || !editing) {
1817
- return;
1818
- }
1819
- const { col } = parseCellIndex2(editing.index);
1820
- const field = model.projection.view.fields[col];
1821
- const fieldProjection2 = model.projection.getFieldProjection(field.id);
1822
- invariant3(fieldProjection2, void 0, {
1823
- F: __dxlog_file4,
1824
- L: 114,
1825
- S: void 0,
1826
- A: [
1827
- "fieldProjection",
1828
- ""
1829
- ]
1830
- });
1831
- return fieldProjection2;
1832
- }, [
1833
- model,
1834
- editing
1835
- ]);
1836
- const handleEnter = useCallback4((value) => {
1837
- if (!model || !editing) {
1838
- return;
1839
- }
1840
- const cell = parseCellIndex2(editing.index);
1841
- model.setCellData(cell, value);
1842
- onEnter?.(cell);
1843
- onFocus?.();
1844
- setEditing(null);
1845
- }, [
1846
- model,
1847
- editing,
1848
- onEnter,
1849
- onFocus,
1850
- setEditing
1851
- ]);
1852
- const handleBlur = useCallback4((value) => {
1853
- if (!model || !editing) {
1854
- return;
1855
- }
1856
- if (suppressNextBlur.current) {
1857
- suppressNextBlur.current = false;
1858
- return;
1859
- }
1860
- const cell = parseCellIndex2(editing.index);
1861
- if (value !== void 0) {
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);
1862
1868
  model.setCellData(cell, value);
1863
- }
1864
- }, [
1865
- model,
1866
- editing
1867
- ]);
1868
- const handleClose = useCallback4((value, event) => {
1869
- if (!model || !editing || !fieldProjection) {
1870
- return;
1871
- }
1872
- const cell = parseCellIndex2(editing.index);
1873
- onEnter?.(cell);
1874
- if (event && onFocus) {
1875
- onFocus(determineNavigationAxis(event), determineNavigationDelta(event));
1876
- }
1877
- }, [
1878
- model,
1879
- editing,
1880
- onFocus,
1881
- onEnter,
1882
- fieldProjection
1883
- ]);
1884
- const extension = useMemo4(() => {
1885
- if (!fieldProjection) {
1886
- return [];
1887
- }
1888
- const extension2 = [
1889
- editorKeys({
1890
- onClose: handleClose,
1891
- ...editing?.initialContent && {
1892
- onNav: handleClose
1893
- }
1894
- })
1895
- ];
1896
- const format = fieldProjection.props.format;
1897
- if (format === FormatEnum5.SingleSelect || format === FormatEnum5.MultiSelect) {
1898
- extension2.push(createMarkdownExtensions({
1899
- themeMode
1900
- }));
1901
- const options = fieldProjection.props.options || [];
1902
- const mode = format === FormatEnum5.SingleSelect ? "single-select" : "multi-select";
1903
- extension2.push(tagPickerExtension({
1904
- mode,
1905
- inGrid: true,
1906
- onSearch: (text, selectedIds) => {
1907
- return options.filter((option) => selectedIds.indexOf(option.id) === -1 && (text.length === 0 || option.title.toLowerCase().includes(text.toLowerCase()))).map((option) => ({
1908
- id: option.id,
1909
- label: option.title,
1910
- hue: option.color
1911
- }));
1912
- },
1913
- onUpdate: (ids) => {
1914
- if (model && editing) {
1915
- if (ids.length === 0) {
1916
- return;
1917
- }
1918
- if (mode === "single-select") {
1919
- handleEnter(ids[0]);
1920
- } else {
1921
- 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
+ }
1922
1950
  }
1923
1951
  }
1924
- }
1925
- }));
1926
- }
1927
- if (onQuery) {
1928
- switch (fieldProjection.props.format) {
1929
- case FormatEnum5.Ref: {
1930
- extension2.push([
1931
- completion({
1932
- onQuery: (text) => onQuery(fieldProjection, text),
1933
- onMatch: (data) => {
1934
- if (model && editing && modals) {
1935
- if (isCreateOption(data)) {
1936
- const { field, props } = fieldProjection;
1937
- if (props.referenceSchema) {
1938
- suppressNextBlur.current = true;
1939
- modals.openCreateRef(props.referenceSchema, document.querySelector(cellQuery(editing.index, gridId)), {
1940
- [field.referencePath]: data.text
1941
- }, (data2) => {
1942
- handleEnter(data2);
1943
- });
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);
1944
1974
  }
1945
- } else {
1946
- handleEnter(data);
1947
1975
  }
1948
1976
  }
1949
- }
1950
- })
1951
- ]);
1952
- break;
1977
+ })
1978
+ ]);
1979
+ break;
1980
+ }
1953
1981
  }
1954
1982
  }
1955
- }
1956
- return extension2;
1957
- }, [
1958
- model,
1959
- modals,
1960
- editing,
1961
- fieldProjection,
1962
- handleClose,
1963
- themeMode
1964
- ]);
1965
- const getCellContent = useCallback4(() => {
1966
- if (model && editing) {
1967
- const cell = parseCellIndex2(editing.index);
1968
- const { col } = cell;
1969
- const field = model.projection.view.fields[col];
1970
- const fieldProjection2 = model.projection.getFieldProjection(field.id);
1971
- if (fieldProjection2?.props.format === FormatEnum5.SingleSelect || fieldProjection2?.props.format === FormatEnum5.MultiSelect) {
1972
- const value2 = model.getCellData(cell);
1973
- if (value2 !== void 0) {
1974
- const options = fieldProjection2.props.options || [];
1975
- if (fieldProjection2.props.format === FormatEnum5.MultiSelect && Array.isArray(value2)) {
1976
- const tagItems = value2.map((id) => {
1977
- 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);
1978
2017
  if (option) {
1979
- return {
1980
- id,
2018
+ const tagItem = {
2019
+ id: value2,
1981
2020
  label: option.title,
1982
2021
  hue: option.color
1983
2022
  };
2023
+ return createLinks([
2024
+ tagItem
2025
+ ]);
1984
2026
  }
1985
- return void 0;
1986
- }).filter((item) => item !== void 0);
1987
- return createLinks(tagItems);
1988
- } else {
1989
- const option = options.find((o) => o.id === value2);
1990
- if (option) {
1991
- const tagItem = {
1992
- id: value2,
1993
- label: option.title,
1994
- hue: option.color
1995
- };
1996
- return createLinks([
1997
- tagItem
1998
- ]);
1999
2027
  }
2000
2028
  }
2029
+ return "";
2001
2030
  }
2002
- return "";
2031
+ const value = model.getCellData(cell);
2032
+ return value !== void 0 ? String(value) : "";
2003
2033
  }
2004
- const value = model.getCellData(cell);
2005
- return value !== void 0 ? String(value) : "";
2006
- }
2007
- }, [
2008
- model,
2009
- editing
2010
- ]);
2011
- return /* @__PURE__ */ React6.createElement(GridCellEditor, {
2012
- extension,
2013
- getCellContent,
2014
- onBlur: handleBlur
2015
- });
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
+ }
2016
2046
  };
2017
2047
  var determineNavigationAxis = ({ key }) => {
2018
2048
  switch (key) {
@@ -2042,282 +2072,292 @@ var determineNavigationDelta = ({ key, shift }) => {
2042
2072
  // packages/ui/react-ui-table/src/components/Table/Table.tsx
2043
2073
  var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/Table/Table.tsx";
2044
2074
  var TableRoot = ({ children, role }) => {
2045
- return /* @__PURE__ */ React7.createElement("div", {
2046
- role: "none",
2047
- 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]")
2048
- }, 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
+ }
2049
2084
  };
2050
2085
  var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention, schema, onRowClick }, forwardedRef) => {
2051
- const [dxGrid, setDxGrid] = useState2(null);
2052
- const { hasAttention } = useAttention(model?.id ?? "table");
2053
- const { t } = useTranslation3(translationKey);
2054
- const modals = useMemo5(() => new ModalController(), []);
2055
- const frozen = useMemo5(() => {
2056
- const noActionColumn = model?.features.dataEditable === false && model?.features.schemaEditable === false && model.rowActions.length === 0;
2057
- return {
2058
- frozenRowsStart: 1,
2059
- frozenColsStart: model?.features.selection.enabled ? 1 : 0,
2060
- frozenColsEnd: noActionColumn ? 0 : 1
2061
- };
2062
- }, [
2063
- model
2064
- ]);
2065
- const getCells = useCallback5((range, plane) => presentation?.getCells(range, plane) ?? {}, [
2066
- presentation
2067
- ]);
2068
- useEffect3(() => {
2069
- if (!presentation || !dxGrid) {
2070
- return;
2071
- }
2072
- dxGrid.getCells = getCells;
2073
- }, [
2074
- presentation,
2075
- dxGrid,
2076
- getCells
2077
- ]);
2078
- useImperativeHandle(forwardedRef, () => {
2079
- if (!presentation || !dxGrid) {
2080
- return {};
2081
- }
2082
- return {
2083
- update: (cell) => {
2084
- if (cell) {
2085
- dxGrid.updateIfWithinBounds(cell);
2086
- } else {
2087
- dxGrid.updateCells(true);
2088
- dxGrid.requestUpdate();
2089
- }
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;
2090
2108
  }
2091
- };
2092
- }, [
2093
- presentation,
2094
- dxGrid
2095
- ]);
2096
- const handleGridClick = useCallback5((event) => {
2097
- const rowIndex = safeParseInt(event.target.ariaRowIndex ?? "");
2098
- if (rowIndex != null) {
2099
- if (onRowClick) {
2100
- const row = model?.getRowAt(rowIndex);
2101
- row && onRowClick(row);
2102
- }
2103
- if (model?.features.selection.enabled && model?.selection.selectionMode === "single") {
2104
- 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 {};
2105
2118
  }
2106
- }
2107
- if (!modals) {
2108
- return;
2109
- }
2110
- const buttonSelector = Object.values(tableButtons).map((button) => `button[${button.attr}]`).join(",");
2111
- const tableButtonElement = event.target.closest(buttonSelector);
2112
- if (tableButtonElement) {
2113
- const button = Object.values(tableButtons).find((btn) => tableButtonElement.hasAttribute(btn.attr));
2114
- 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) {
2115
2145
  return;
2116
2146
  }
2117
- modals.setTrigger(tableButtonElement);
2118
- const data = button.getData(tableButtonElement);
2119
- switch (data.type) {
2120
- case "rowMenu": {
2121
- modals.showRowMenu(data.rowIndex);
2122
- 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;
2123
2153
  }
2124
- case "columnSettings": {
2125
- modals.showColumnMenu(data.fieldId);
2126
- 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
+ }
2127
2173
  }
2128
- case "newColumn": {
2129
- modals.showColumnCreator();
2130
- 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;
2131
2182
  }
2132
- case "sort": {
2133
- model?.sorting?.toggleSort(data.fieldId);
2134
- 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
+ }
2135
2202
  }
2136
2203
  }
2137
- return;
2138
- }
2139
- const controlSelector = Object.values(tableControls).map((control) => `input[${control.attr}]`).join(",");
2140
- const controlElement = event.target.closest(controlSelector);
2141
- if (controlElement) {
2142
- const control = Object.values(tableControls).find((ctrl) => controlElement.hasAttribute(ctrl.attr));
2143
- 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) {
2144
2217
  return;
2145
2218
  }
2146
- const data = control.getData(controlElement);
2147
- switch (data.type) {
2148
- case "checkbox": {
2149
- if (data.header) {
2150
- model?.selection.setSelection(model.selection.allRowsSeleted.value ? "none" : "all");
2151
- } else {
2152
- model?.selection.toggleSelectionForRowIndex(data.rowIndex);
2153
- }
2154
- 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
+ });
2155
2226
  }
2156
- case "switch": {
2157
- if (model) {
2158
- model.updateCellData({
2159
- row: data.rowIndex,
2160
- col: data.colIndex
2161
- }, (value) => !value);
2162
- }
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);
2163
2244
  break;
2164
2245
  }
2165
2246
  }
2166
- }
2167
- }, [
2168
- model,
2169
- modals
2170
- ]);
2171
- const handleFocus = useCallback5((increment, delta) => {
2172
- if (dxGrid) {
2173
- dxGrid.refocus(increment, delta);
2174
- }
2175
- }, [
2176
- dxGrid
2177
- ]);
2178
- const handleEnter = useCallback5((cell) => {
2179
- if (!model?.features.dataEditable) {
2180
- return;
2181
- }
2182
- if (model && cell.row === model.getRowCount() - 1) {
2183
- model.insertRow(cell.row);
2184
- if (dxGrid) {
2185
- requestAnimationFrame(() => {
2186
- dxGrid?.scrollToRow(cell.row + 1);
2187
- dxGrid?.refocus("row", 1);
2188
- });
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);
2189
2254
  }
2190
- }
2191
- }, [
2192
- model,
2193
- dxGrid
2194
- ]);
2195
- const handleKeyDown = useCallback5((event) => {
2196
- if (!model?.features.dataEditable) {
2197
- return;
2198
- }
2199
- const cell = closestCell(event.target);
2200
- if (!model || !cell) {
2201
- return;
2202
- }
2203
- switch (event.key) {
2204
- case "Backspace":
2205
- case "Delete": {
2206
- model.setCellData(cell, void 0);
2207
- break;
2255
+ }, [
2256
+ model
2257
+ ]);
2258
+ const handleWheel = useCallback5((event) => {
2259
+ if (!ignoreAttention && !hasAttention) {
2260
+ event.stopPropagation();
2208
2261
  }
2209
- }
2210
- }, [
2211
- model
2212
- ]);
2213
- const handleAxisResize = useCallback5((event) => {
2214
- if (event.axis === "col") {
2215
- const columnIndex = parseInt(event.index, 10);
2216
- model?.setColumnWidth(columnIndex, event.size);
2217
- }
2218
- }, [
2219
- model
2220
- ]);
2221
- const handleWheel = useCallback5((event) => {
2222
- if (!ignoreAttention && !hasAttention) {
2223
- event.stopPropagation();
2224
- }
2225
- }, [
2226
- hasAttention,
2227
- ignoreAttention
2228
- ]);
2229
- const handleNewColumn = useCallback5(() => {
2230
- const columns = model?.getColumnCount();
2231
- if (dxGrid && columns) {
2232
- dxGrid.scrollToColumn(columns - 1);
2233
- }
2234
- }, [
2235
- model,
2236
- dxGrid
2237
- ]);
2238
- const handleQuery = useCallback5(async ({ field, props }, text) => {
2239
- if (model && props.referenceSchema && field.referencePath) {
2240
- const space = model.space;
2241
- invariant4(space, void 0, {
2242
- F: __dxlog_file5,
2243
- L: 309,
2244
- S: void 0,
2245
- A: [
2246
- "space",
2247
- ""
2248
- ]
2249
- });
2250
- const schema2 = space.db.schemaRegistry.getSchema(props.referenceSchema);
2251
- if (schema2) {
2252
- const { objects } = await space.db.query(Filter.type(schema2)).run();
2253
- const options = objects.map((obj) => {
2254
- const value = getValue4(obj, field.referencePath);
2255
- if (!value || typeof value !== "string") {
2256
- return void 0;
2257
- }
2258
- return {
2259
- label: value,
2260
- data: obj
2261
- };
2262
- }).filter(isNotFalsy);
2263
- return [
2264
- ...options,
2265
- {
2266
- label: t("create new object label", {
2267
- text
2268
- }),
2269
- data: createOption(text)
2270
- }
2271
- ];
2262
+ }, [
2263
+ hasAttention,
2264
+ ignoreAttention
2265
+ ]);
2266
+ const handleNewColumn = useCallback5(() => {
2267
+ const columns = model?.getColumnCount();
2268
+ if (dxGrid && columns) {
2269
+ dxGrid.scrollToColumn(columns - 1);
2272
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
+ });
2273
2321
  }
2274
- return [];
2275
- }, [
2276
- model,
2277
- t
2278
- ]);
2279
- if (!model || !modals) {
2280
- return /* @__PURE__ */ React7.createElement("span", {
2281
- role: "none",
2282
- className: "attention-surface"
2283
- });
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();
2284
2360
  }
2285
- return /* @__PURE__ */ React7.createElement(Grid.Root, {
2286
- id: model.id ?? "table-grid"
2287
- }, /* @__PURE__ */ React7.createElement(TableValueEditor, {
2288
- model,
2289
- modals,
2290
- schema,
2291
- onEnter: handleEnter,
2292
- onFocus: handleFocus,
2293
- onQuery: handleQuery
2294
- }), /* @__PURE__ */ React7.createElement(Grid.Content, {
2295
- className: mx2("[--dx-grid-base:var(--baseSurface)]", gridSeparatorInlineEnd, gridSeparatorBlockEnd),
2296
- frozen,
2297
- // getCells={getCells}
2298
- columns: model.columnMeta.value,
2299
- limitRows: model.getRowCount() ?? 0,
2300
- limitColumns: model.view?.fields?.length ?? 0,
2301
- overscroll: "trap",
2302
- onAxisResize: handleAxisResize,
2303
- onClick: handleGridClick,
2304
- onKeyDown: handleKeyDown,
2305
- onWheelCapture: handleWheel,
2306
- ref: setDxGrid
2307
- }), /* @__PURE__ */ React7.createElement(RowActionsMenu, {
2308
- model,
2309
- modals
2310
- }), /* @__PURE__ */ React7.createElement(ColumnActionsMenu, {
2311
- model,
2312
- modals
2313
- }), /* @__PURE__ */ React7.createElement(ColumnSettings, {
2314
- model,
2315
- modals,
2316
- onNewColumn: handleNewColumn
2317
- }), /* @__PURE__ */ React7.createElement(CreateRefPanel, {
2318
- model,
2319
- modals
2320
- }));
2321
2361
  });
2322
2362
  var Table = {
2323
2363
  Root: TableRoot,
@@ -2325,152 +2365,167 @@ var Table = {
2325
2365
  };
2326
2366
 
2327
2367
  // packages/ui/react-ui-table/src/components/Table/DynamicTable.tsx
2368
+ import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
2328
2369
  import React8, { useRef as useRef3, useMemo as useMemo6, useCallback as useCallback6 } from "react";
2329
2370
  import { useDefaultValue } from "@dxos/react-ui";
2330
2371
  import { mx as mx3 } from "@dxos/react-ui-theme";
2331
2372
 
2332
2373
  // packages/ui/react-ui-table/src/hooks/useTableModel.ts
2374
+ import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
2333
2375
  import { effect as effect3 } from "@preact/signals-core";
2334
2376
  import { useEffect as useEffect4, useState as useState3 } from "react";
2335
2377
  import { fullyQualifiedId, getSpace } from "@dxos/react-client/echo";
2336
2378
  import { useSelectionActions } from "@dxos/react-ui-attention";
2337
2379
  import { isNonNullable } from "@dxos/util";
2338
2380
  var useTableModel = ({ table, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
2339
- const [model, setModel] = useState3();
2340
- useEffect4(() => {
2341
- if (!table || !projection) {
2342
- return;
2343
- }
2344
- let model2;
2345
- const t = setTimeout(async () => {
2346
- model2 = new TableModel({
2347
- id: fullyQualifiedId(table),
2348
- space: getSpace(table),
2349
- view: table.view?.target,
2350
- projection,
2351
- features,
2352
- rowActions,
2353
- onRowAction,
2354
- ...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);
2355
2402
  });
2356
- await model2.open();
2357
- setModel(model2);
2358
- });
2359
- return () => {
2360
- clearTimeout(t);
2361
- void model2?.close();
2362
- };
2363
- }, [
2364
- table,
2365
- projection,
2366
- table?.view?.target,
2367
- features,
2368
- rowActions
2369
- ]);
2370
- useEffect4(() => {
2371
- if (rows) {
2372
- model?.setRows(rows);
2373
- }
2374
- }, [
2375
- model,
2376
- rows
2377
- ]);
2378
- const { select, clear } = useSelectionActions([
2379
- table?.id,
2380
- table?.view?.target?.query.typename
2381
- ].filter(isNonNullable));
2382
- useEffect4(() => {
2383
- if (!model) {
2384
- return;
2385
- }
2386
- const unsubscribe = effect3(() => {
2387
- const selectedItems = [
2388
- ...model.selection.selection.value
2389
- ];
2390
- select(selectedItems);
2391
- onSelectionChanged?.(selectedItems);
2392
- });
2393
- return () => {
2394
- clear();
2395
- unsubscribe();
2396
- };
2397
- }, [
2398
- model,
2399
- onSelectionChanged
2400
- ]);
2401
- 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
+ }
2402
2449
  };
2403
2450
 
2404
2451
  // packages/ui/react-ui-table/src/components/Table/DynamicTable.tsx
2405
2452
  var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, properties, jsonSchema, schema, rowActions, onRowClick, onRowAction, ...props }) => {
2406
- const { table, projection } = useMemo6(() => {
2407
- const props2 = getBaseSchema({
2408
- 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,
2409
2468
  properties,
2410
- jsonSchema,
2411
- schema
2412
- });
2413
- return makeDynamicTable({
2414
- ...props2,
2415
- 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
2416
2494
  });
2417
- }, [
2418
- name,
2419
- properties,
2420
- schema,
2421
- jsonSchema
2422
- ]);
2423
- const tableRef = useRef3(null);
2424
- const handleCellUpdate = useCallback6((cell) => {
2425
- tableRef.current?.update?.(cell);
2426
- }, []);
2427
- const handleRowOrderChange = useCallback6(() => {
2428
- tableRef.current?.update?.();
2429
- }, []);
2430
- const features = useDefaultValue(props.features, () => ({
2431
- selection: {
2432
- enabled: false
2433
- },
2434
- dataEditable: false
2435
- }));
2436
- const model = useTableModel({
2437
- table,
2438
- rows,
2439
- projection,
2440
- features,
2441
- rowActions,
2442
- onCellUpdate: handleCellUpdate,
2443
- onRowOrderChange: handleRowOrderChange,
2444
- onRowAction
2445
- });
2446
- const presentation = useMemo6(() => {
2447
- if (model) {
2448
- return new TablePresentation(model);
2449
- }
2450
- }, [
2451
- model
2452
- ]);
2453
- return /* @__PURE__ */ React8.createElement("div", {
2454
- role: "none",
2455
- className: mx3("is-full bs-full grow grid", classNames)
2456
- }, /* @__PURE__ */ React8.createElement("div", {
2457
- role: "none",
2458
- className: "grid min-bs-0 overflow-hidden"
2459
- }, /* @__PURE__ */ React8.createElement(Table.Root, null, /* @__PURE__ */ React8.createElement(Table.Main, {
2460
- ref: tableRef,
2461
- model,
2462
- presentation,
2463
- ignoreAttention: true,
2464
- onRowClick
2465
- }))));
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
+ }
2466
2518
  };
2467
2519
 
2468
2520
  // packages/ui/react-ui-table/src/components/TableToolbar/TableToolbar.tsx
2469
- import React9, { useCallback as useCallback7, useMemo as useMemo7 } from "react";
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";
2470
2524
  import { live as live4 } from "@dxos/live-object";
2471
2525
  import { createGapSeparator, createMenuAction, MenuProvider, ToolbarMenu, useMenuActions } from "@dxos/react-ui-menu";
2472
- var createTableToolbarActions = (state, onAction) => {
2473
- const add = createMenuAction("add-row", () => onAction(add), {
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, {
2474
2529
  type: "add-row",
2475
2530
  icon: "ph--plus--regular",
2476
2531
  label: [
@@ -2481,7 +2536,7 @@ var createTableToolbarActions = (state, onAction) => {
2481
2536
  ],
2482
2537
  testId: "table.toolbar.add-row"
2483
2538
  });
2484
- const save = createMenuAction("save-view", () => onAction(save), {
2539
+ const save = createMenuAction("save-view", onSave, {
2485
2540
  type: "save-view",
2486
2541
  icon: "ph--floppy-disk--regular",
2487
2542
  label: [
@@ -2492,49 +2547,55 @@ var createTableToolbarActions = (state, onAction) => {
2492
2547
  ],
2493
2548
  testId: "table.toolbar.save-view",
2494
2549
  iconOnly: false,
2495
- hidden: !state.viewDirty
2550
+ hidden: get(rxFromSignal(() => !state.viewDirty))
2496
2551
  });
2497
2552
  const gap = createGapSeparator();
2498
- const comment = createMenuAction("comment", () => onAction(comment), {
2499
- type: "comment",
2500
- icon: "ph--chat-text--regular",
2501
- label: [
2502
- "create comment",
2503
- {
2504
- ns: translationKey
2505
- }
2506
- ],
2507
- testId: "table.toolbar.comment"
2508
- });
2509
2553
  const nodes = [
2510
2554
  add,
2511
2555
  save,
2512
- ...gap.nodes,
2513
- comment
2556
+ ...gap.nodes
2514
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
+ }
2515
2567
  return {
2516
2568
  nodes,
2517
- edges: nodes.map(({ id: target }) => ({
2518
- source: "root",
2519
- target
2520
- }))
2569
+ edges
2521
2570
  };
2522
- };
2523
- var TableToolbar = ({ classNames, viewDirty, attendableId, onAction }) => {
2524
- const state = useMemo7(() => live4({
2525
- viewDirty
2526
- }), []);
2527
- const actionsCreator = useCallback7(() => createTableToolbarActions(state, onAction), [
2528
- state,
2529
- onAction
2530
- ]);
2531
- const menu = useMenuActions(actionsCreator);
2532
- return /* @__PURE__ */ React9.createElement(MenuProvider, {
2533
- ...menu,
2534
- attendableId
2535
- }, /* @__PURE__ */ React9.createElement(ToolbarMenu, {
2536
- classNames
2537
- }));
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
+ }
2538
2599
  };
2539
2600
  export {
2540
2601
  BUTTON_IDENTIFIERS,