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