@dxos/react-ui-table 0.4.10-main.0302e13 → 0.4.10-main.068c3d8
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/index.mjs +618 -307
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/ColumnMenu/ColumnMenu.d.ts +19 -0
- package/dist/types/src/components/ColumnMenu/ColumnMenu.d.ts.map +1 -0
- package/dist/types/src/components/{ColumnMenu.stories.d.ts → ColumnMenu/ColumnMenu.stories.d.ts} +10 -2
- package/dist/types/src/components/ColumnMenu/ColumnMenu.stories.d.ts.map +1 -0
- package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.d.ts +11 -0
- package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.d.ts.map +1 -0
- package/dist/types/src/components/ColumnMenu/index.d.ts +3 -0
- package/dist/types/src/components/ColumnMenu/index.d.ts.map +1 -0
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +3 -0
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/helpers.d.ts +4 -0
- package/dist/types/src/helpers.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +3 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/useColumnSorting.d.ts +9 -0
- package/dist/types/src/hooks/useColumnSorting.d.ts.map +1 -0
- package/dist/types/src/hooks/usePinLastRow.d.ts +3 -0
- package/dist/types/src/hooks/usePinLastRow.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/schema/SchemaToTable.stories.d.ts +11 -0
- package/dist/types/src/schema/SchemaToTable.stories.d.ts.map +1 -0
- package/dist/types/src/schema/index.d.ts +3 -0
- package/dist/types/src/schema/index.d.ts.map +1 -0
- package/dist/types/src/schema/schema.d.ts +5 -0
- package/dist/types/src/schema/schema.d.ts.map +1 -0
- package/dist/types/src/schema/schema.test.d.ts +2 -0
- package/dist/types/src/schema/schema.test.d.ts.map +1 -0
- package/dist/types/src/schema/schemaToColumns.d.ts +4 -0
- package/dist/types/src/schema/schemaToColumns.d.ts.map +1 -0
- package/dist/types/src/{schema.d.ts → schema/types.d.ts} +1 -1
- package/dist/types/src/schema/types.d.ts.map +1 -0
- package/package.json +19 -16
- package/src/components/ColumnMenu/ColumnMenu.stories.tsx +127 -0
- package/src/components/ColumnMenu/ColumnMenu.tsx +166 -0
- package/src/components/ColumnMenu/ColumnSettingsForm.tsx +214 -0
- package/src/components/ColumnMenu/index.ts +6 -0
- package/src/components/Table/Table.stories.tsx +58 -3
- package/src/components/Table/Table.tsx +24 -9
- package/src/components/index.ts +1 -1
- package/src/helpers.tsx +23 -1
- package/src/hooks/index.ts +6 -0
- package/src/hooks/useColumnSorting.ts +54 -0
- package/src/hooks/usePinLastRow.ts +64 -0
- package/src/index.ts +3 -1
- package/src/schema/SchemaToTable.stories.tsx +72 -0
- package/src/schema/index.ts +6 -0
- package/src/schema/schema.test.ts +148 -0
- package/src/schema/schema.ts +92 -0
- package/src/schema/schemaToColumns.ts +48 -0
- package/src/theme.ts +1 -1
- package/dist/types/src/components/ColumnMenu.d.ts +0 -13
- package/dist/types/src/components/ColumnMenu.d.ts.map +0 -1
- package/dist/types/src/components/ColumnMenu.stories.d.ts.map +0 -1
- package/dist/types/src/components/SortButton.d.ts +0 -8
- package/dist/types/src/components/SortButton.d.ts.map +0 -1
- package/dist/types/src/components/hooks/usePinLastRow.d.ts +0 -3
- package/dist/types/src/components/hooks/usePinLastRow.d.ts.map +0 -1
- package/dist/types/src/schema.d.ts.map +0 -1
- package/src/components/ColumnMenu.stories.tsx +0 -46
- package/src/components/ColumnMenu.tsx +0 -248
- package/src/components/SortButton.tsx +0 -34
- package/src/components/hooks/usePinLastRow.ts +0 -43
- /package/src/{schema.ts → schema/types.ts} +0 -0
|
@@ -1,40 +1,3 @@
|
|
|
1
|
-
// packages/ui/react-ui-table/src/components/ColumnMenu.tsx
|
|
2
|
-
import { Check, Trash, X, GearSix } from "@phosphor-icons/react";
|
|
3
|
-
import React2, { useRef, useState } from "react";
|
|
4
|
-
import { Button as Button2, DensityProvider, Input, Popover, Select, Separator, useTranslation } from "@dxos/react-ui";
|
|
5
|
-
import { getSize as getSize2, mx } from "@dxos/react-ui-theme";
|
|
6
|
-
import { safeParseInt } from "@dxos/util";
|
|
7
|
-
|
|
8
|
-
// packages/ui/react-ui-table/src/components/SortButton.tsx
|
|
9
|
-
import { CaretUpDown, SortAscending, SortDescending } from "@phosphor-icons/react";
|
|
10
|
-
import React from "react";
|
|
11
|
-
import { Button } from "@dxos/react-ui";
|
|
12
|
-
import { getSize } from "@dxos/react-ui-theme";
|
|
13
|
-
var SortButton = ({ sortDirection, onClick }) => {
|
|
14
|
-
let icon;
|
|
15
|
-
const size = getSize(4);
|
|
16
|
-
switch (sortDirection) {
|
|
17
|
-
case "asc":
|
|
18
|
-
icon = /* @__PURE__ */ React.createElement(SortAscending, {
|
|
19
|
-
className: size
|
|
20
|
-
});
|
|
21
|
-
break;
|
|
22
|
-
case "desc":
|
|
23
|
-
icon = /* @__PURE__ */ React.createElement(SortDescending, {
|
|
24
|
-
className: size
|
|
25
|
-
});
|
|
26
|
-
break;
|
|
27
|
-
default:
|
|
28
|
-
icon = /* @__PURE__ */ React.createElement(CaretUpDown, {
|
|
29
|
-
className: size
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
return /* @__PURE__ */ React.createElement(Button, {
|
|
33
|
-
variant: "ghost",
|
|
34
|
-
onClick
|
|
35
|
-
}, icon);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
1
|
// packages/ui/react-ui-table/src/translations.ts
|
|
39
2
|
var translationKey = "table";
|
|
40
3
|
var translations_default = [
|
|
@@ -58,47 +21,107 @@ var translations_default = [
|
|
|
58
21
|
}
|
|
59
22
|
];
|
|
60
23
|
|
|
61
|
-
// packages/ui/react-ui-table/src/components/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
24
|
+
// packages/ui/react-ui-table/src/components/Cell/CellCombobox.tsx
|
|
25
|
+
import { CaretDown } from "@phosphor-icons/react";
|
|
26
|
+
import React, { useCallback, useState } from "react";
|
|
27
|
+
import { Popover, useTranslation } from "@dxos/react-ui";
|
|
28
|
+
import { PopoverCombobox } from "@dxos/react-ui-searchlist";
|
|
29
|
+
import { descriptionText, getSize, mx, staticPlaceholderText } from "@dxos/react-ui-theme";
|
|
30
|
+
var initialItems = (model, value) => value ? {
|
|
31
|
+
[model.getId(value)]: {
|
|
32
|
+
label: model.getText(value),
|
|
33
|
+
data: value
|
|
34
|
+
}
|
|
35
|
+
} : {};
|
|
36
|
+
var CellCombobox = ({ model, value, onValueChange }) => {
|
|
37
|
+
const { t } = useTranslation(translationKey);
|
|
38
|
+
const [items, setItems] = useState(initialItems(model, value));
|
|
39
|
+
const [loading, setLoading] = useState(false);
|
|
40
|
+
const [searchInputValue, setSearchInputValue] = useState("");
|
|
41
|
+
const handleSearchInputValueChange = async (text) => {
|
|
42
|
+
setSearchInputValue(text ?? "");
|
|
43
|
+
setLoading(true);
|
|
44
|
+
const items2 = await model.query(text);
|
|
45
|
+
setItems(items2.reduce((acc, item) => {
|
|
46
|
+
acc[model.getId(item)] = {
|
|
47
|
+
label: model.getText(item),
|
|
48
|
+
data: item
|
|
49
|
+
};
|
|
50
|
+
return acc;
|
|
51
|
+
}, initialItems(model, value)));
|
|
52
|
+
setLoading(false);
|
|
53
|
+
};
|
|
54
|
+
const handleValueChange = useCallback((id) => {
|
|
55
|
+
onValueChange(items[id]?.data);
|
|
56
|
+
}, [
|
|
57
|
+
items,
|
|
58
|
+
onValueChange
|
|
59
|
+
]);
|
|
60
|
+
return /* @__PURE__ */ React.createElement(PopoverCombobox.Root, {
|
|
61
|
+
placeholder: t("no selection label")
|
|
62
|
+
}, /* @__PURE__ */ React.createElement(PopoverCombobox.Trigger, {
|
|
63
|
+
variant: "ghost",
|
|
64
|
+
classNames: "is-full rounded-none ring-inset"
|
|
65
|
+
}, value ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", {
|
|
66
|
+
className: mx("font-normal text-start text-base flex-1 min-is-0 truncate mie-2", !value && staticPlaceholderText)
|
|
67
|
+
}, model.getText(value)), /* @__PURE__ */ React.createElement(CaretDown, {
|
|
68
|
+
weight: "bold",
|
|
69
|
+
className: getSize(3)
|
|
70
|
+
})) : null), /* @__PURE__ */ React.createElement(PopoverCombobox.Content, {
|
|
71
|
+
shouldFilter: false,
|
|
72
|
+
classNames: "is-[--radix-popover-trigger-width]"
|
|
73
|
+
}, /* @__PURE__ */ React.createElement(PopoverCombobox.Input, {
|
|
74
|
+
value: searchInputValue,
|
|
75
|
+
onValueChange: handleSearchInputValueChange
|
|
76
|
+
}), /* @__PURE__ */ React.createElement(PopoverCombobox.List, null, searchInputValue.length < 1 ? /* @__PURE__ */ React.createElement("p", {
|
|
77
|
+
className: mx("text-center", descriptionText)
|
|
78
|
+
}, "Start typing to search") : loading ? /* @__PURE__ */ React.createElement("p", {
|
|
79
|
+
className: mx("text-center", descriptionText)
|
|
80
|
+
}, "Searching\u2026") : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(PopoverCombobox.Empty, {
|
|
81
|
+
classNames: [
|
|
82
|
+
"text-center",
|
|
83
|
+
descriptionText
|
|
84
|
+
]
|
|
85
|
+
}, "No results"), Object.entries(items).map(([id, { label }]) => /* @__PURE__ */ React.createElement(PopoverCombobox.Item, {
|
|
86
|
+
key: id,
|
|
87
|
+
value: id,
|
|
88
|
+
onSelect: handleValueChange,
|
|
89
|
+
classNames: "truncate"
|
|
90
|
+
}, label)))), /* @__PURE__ */ React.createElement(Popover.Arrow, null)));
|
|
82
91
|
};
|
|
92
|
+
|
|
93
|
+
// packages/ui/react-ui-table/src/components/ColumnMenu/ColumnMenu.tsx
|
|
94
|
+
import { X as X2, GearSix, CaretDown as CaretDown2, ArrowDown, ArrowUp } from "@phosphor-icons/react";
|
|
95
|
+
import React3, { useRef as useRef2, useState as useState5, useCallback as useCallback3 } from "react";
|
|
96
|
+
import { Button as Button2, DensityProvider, Popover as Popover2, DropdownMenu } from "@dxos/react-ui";
|
|
97
|
+
import { getSize as getSize3, mx as mx3 } from "@dxos/react-ui-theme";
|
|
98
|
+
|
|
99
|
+
// packages/ui/react-ui-table/src/components/ColumnMenu/ColumnSettingsForm.tsx
|
|
100
|
+
import { Check, Trash, X } from "@phosphor-icons/react";
|
|
101
|
+
import React2, { useRef, useState as useState2 } from "react";
|
|
102
|
+
import { Button, Input, Select, Separator, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
103
|
+
import { getSize as getSize2, mx as mx2 } from "@dxos/react-ui-theme";
|
|
104
|
+
import { safeParseInt } from "@dxos/util";
|
|
83
105
|
var Section = ({ children, className }) => /* @__PURE__ */ React2.createElement("div", {
|
|
84
106
|
role: "none",
|
|
85
|
-
className:
|
|
107
|
+
className: mx2("p-2", className)
|
|
86
108
|
}, children);
|
|
87
|
-
var
|
|
88
|
-
const [
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
109
|
+
var ColumnSettingsForm = ({ column, tableDef, tableDefs, onUpdate, onDelete, onClose }) => {
|
|
110
|
+
const [formState, setFormState] = useState2({
|
|
111
|
+
prop: column.id,
|
|
112
|
+
refTable: column.refTable,
|
|
113
|
+
refProp: column.refProp,
|
|
114
|
+
type: String(column.type),
|
|
115
|
+
label: column.label,
|
|
116
|
+
digits: String(column.digits ?? "0")
|
|
117
|
+
});
|
|
95
118
|
const propRef = useRef(null);
|
|
96
|
-
const { t } =
|
|
119
|
+
const { t } = useTranslation2(translationKey);
|
|
97
120
|
const handleCancel = () => {
|
|
98
|
-
|
|
99
|
-
setOpen(false);
|
|
121
|
+
onClose?.();
|
|
100
122
|
};
|
|
101
123
|
const handleSave = () => {
|
|
124
|
+
const { prop, refTable, refProp, type, label, digits } = formState;
|
|
102
125
|
if (!prop.length || !prop.match(/^[a-zA-Z_].+/i)) {
|
|
103
126
|
propRef.current?.focus();
|
|
104
127
|
return;
|
|
@@ -110,7 +133,7 @@ var ColumnPanel = ({ context, tableDefs, tableDef, column, onUpdate, onDelete })
|
|
|
110
133
|
return;
|
|
111
134
|
}
|
|
112
135
|
}
|
|
113
|
-
onUpdate?.(
|
|
136
|
+
onUpdate?.(column.id, {
|
|
114
137
|
id: prop,
|
|
115
138
|
prop,
|
|
116
139
|
label,
|
|
@@ -119,43 +142,38 @@ var ColumnPanel = ({ context, tableDefs, tableDef, column, onUpdate, onDelete })
|
|
|
119
142
|
refProp,
|
|
120
143
|
digits: safeParseInt(digits)
|
|
121
144
|
});
|
|
122
|
-
|
|
145
|
+
onClose?.();
|
|
123
146
|
};
|
|
124
|
-
return /* @__PURE__ */ React2.createElement(
|
|
125
|
-
open,
|
|
126
|
-
onOpenChange: (nextOpen) => setOpen(nextOpen)
|
|
127
|
-
}, /* @__PURE__ */ React2.createElement(Popover.Trigger, {
|
|
128
|
-
asChild: true
|
|
129
|
-
}, /* @__PURE__ */ React2.createElement(Button2, {
|
|
130
|
-
variant: "ghost"
|
|
131
|
-
}, /* @__PURE__ */ React2.createElement(GearSix, {
|
|
132
|
-
className: mx(getSize2(4), "rotate-90")
|
|
133
|
-
}))), /* @__PURE__ */ React2.createElement(Popover.Portal, null, /* @__PURE__ */ React2.createElement(Popover.Content, null, /* @__PURE__ */ React2.createElement(Popover.Viewport, {
|
|
134
|
-
classNames: "w-60"
|
|
135
|
-
}, /* @__PURE__ */ React2.createElement(DensityProvider, {
|
|
136
|
-
density: "fine"
|
|
137
|
-
}, /* @__PURE__ */ React2.createElement("div", {
|
|
147
|
+
return /* @__PURE__ */ React2.createElement("div", {
|
|
138
148
|
className: "flex flex-col gap-1"
|
|
139
149
|
}, /* @__PURE__ */ React2.createElement(Section, null, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, {
|
|
140
150
|
classNames: "mbe-1"
|
|
141
151
|
}, t("column label label")), /* @__PURE__ */ React2.createElement(Input.TextInput, {
|
|
142
152
|
placeholder: "Column label",
|
|
143
|
-
value: label ?? "",
|
|
144
|
-
onChange: (event) =>
|
|
153
|
+
value: formState.label ?? "",
|
|
154
|
+
onChange: (event) => setFormState((prevState) => ({
|
|
155
|
+
...prevState,
|
|
156
|
+
label: event.target.value
|
|
157
|
+
})),
|
|
145
158
|
autoFocus: true
|
|
146
159
|
})), /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, {
|
|
147
160
|
classNames: "mbe-1 mbs-3"
|
|
148
161
|
}, t("property key label")), /* @__PURE__ */ React2.createElement(Input.TextInput, {
|
|
149
162
|
ref: propRef,
|
|
150
163
|
placeholder: "Property key",
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
164
|
+
value: formState.prop ?? "",
|
|
165
|
+
onChange: (event) => setFormState((prevState) => ({
|
|
166
|
+
...prevState,
|
|
167
|
+
prop: event.target.value.replace(/[^\w_]/g, "")
|
|
168
|
+
}))
|
|
154
169
|
})), /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, {
|
|
155
170
|
classNames: "mbe-1 mbs-3"
|
|
156
171
|
}, t("column type label")), /* @__PURE__ */ React2.createElement(Select.Root, {
|
|
157
|
-
value: type,
|
|
158
|
-
onValueChange:
|
|
172
|
+
value: formState.type,
|
|
173
|
+
onValueChange: (value) => setFormState((prevState) => ({
|
|
174
|
+
...prevState,
|
|
175
|
+
type: value
|
|
176
|
+
}))
|
|
159
177
|
}, /* @__PURE__ */ React2.createElement(Select.TriggerButton, {
|
|
160
178
|
placeholder: "Type",
|
|
161
179
|
classNames: "is-full"
|
|
@@ -164,41 +182,50 @@ var ColumnPanel = ({ context, tableDefs, tableDef, column, onUpdate, onDelete })
|
|
|
164
182
|
"boolean",
|
|
165
183
|
"string",
|
|
166
184
|
"ref"
|
|
167
|
-
].map((
|
|
168
|
-
key:
|
|
169
|
-
value:
|
|
170
|
-
}, t(`${
|
|
185
|
+
].map((type) => /* @__PURE__ */ React2.createElement(Select.Option, {
|
|
186
|
+
key: type,
|
|
187
|
+
value: type
|
|
188
|
+
}, t(`${type} column type label`))))))))), formState.type === "number" && /* @__PURE__ */ React2.createElement(Section, null, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, {
|
|
171
189
|
classNames: "mbe-1 mbs-3"
|
|
172
190
|
}, t("digits label")), /* @__PURE__ */ React2.createElement(Input.TextInput, {
|
|
173
|
-
value: digits ?? "",
|
|
174
|
-
onChange: (event) =>
|
|
175
|
-
|
|
191
|
+
value: formState.digits ?? "",
|
|
192
|
+
onChange: (event) => setFormState((prevState) => ({
|
|
193
|
+
...prevState,
|
|
194
|
+
digits: event.target.value
|
|
195
|
+
}))
|
|
196
|
+
}))), formState.type === "ref" && /* @__PURE__ */ React2.createElement(Section, null, /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, {
|
|
176
197
|
classNames: "mbe-1 mbs-3"
|
|
177
198
|
}, "Table"), /* @__PURE__ */ React2.createElement(Select.Root, {
|
|
178
|
-
value: refTable,
|
|
179
|
-
onValueChange:
|
|
199
|
+
value: formState.refTable,
|
|
200
|
+
onValueChange: (value) => setFormState((prevState) => ({
|
|
201
|
+
...prevState,
|
|
202
|
+
refTable: value
|
|
203
|
+
}))
|
|
180
204
|
}, /* @__PURE__ */ React2.createElement(Select.TriggerButton, {
|
|
181
205
|
placeholder: "Table",
|
|
182
206
|
classNames: "is-full"
|
|
183
207
|
}), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null, tableDefs.filter((t2) => t2.id !== tableDef.id).map(({ id, name }) => /* @__PURE__ */ React2.createElement(Select.Option, {
|
|
184
208
|
key: id,
|
|
185
209
|
value: id
|
|
186
|
-
}, name ?? id))))))), refTable && /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, {
|
|
210
|
+
}, name ?? id))))))), formState.refTable && /* @__PURE__ */ React2.createElement(Input.Root, null, /* @__PURE__ */ React2.createElement(Input.Label, {
|
|
187
211
|
classNames: "mbe-1 mbs-3"
|
|
188
212
|
}, "Table property"), /* @__PURE__ */ React2.createElement(Select.Root, {
|
|
189
|
-
value: refProp,
|
|
190
|
-
onValueChange:
|
|
213
|
+
value: formState.refProp,
|
|
214
|
+
onValueChange: (value) => setFormState((prevState) => ({
|
|
215
|
+
...prevState,
|
|
216
|
+
refProp: value
|
|
217
|
+
}))
|
|
191
218
|
}, /* @__PURE__ */ React2.createElement(Select.TriggerButton, {
|
|
192
219
|
placeholder: "Property",
|
|
193
220
|
classNames: "is-full"
|
|
194
|
-
}), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null, tableDefs.find((tableDef2) => tableDef2.id === refTable)?.columns.map(({ id, label
|
|
221
|
+
}), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null, tableDefs.find((tableDef2) => tableDef2.id === formState.refTable)?.columns.map(({ id, label }) => /* @__PURE__ */ React2.createElement(Select.Option, {
|
|
195
222
|
key: id,
|
|
196
223
|
value: id
|
|
197
|
-
},
|
|
224
|
+
}, label ?? id)))))))), /* @__PURE__ */ React2.createElement(Separator, {
|
|
198
225
|
classNames: "mli-2"
|
|
199
226
|
}), /* @__PURE__ */ React2.createElement(Section, {
|
|
200
227
|
className: "space-b-1.5"
|
|
201
|
-
}, /* @__PURE__ */ React2.createElement(
|
|
228
|
+
}, /* @__PURE__ */ React2.createElement(Button, {
|
|
202
229
|
variant: "primary",
|
|
203
230
|
classNames: "is-full flex gap-2",
|
|
204
231
|
onClick: handleSave
|
|
@@ -206,7 +233,7 @@ var ColumnPanel = ({ context, tableDefs, tableDef, column, onUpdate, onDelete })
|
|
|
206
233
|
className: "grow"
|
|
207
234
|
}), /* @__PURE__ */ React2.createElement(Check, {
|
|
208
235
|
className: getSize2(5)
|
|
209
|
-
})), /* @__PURE__ */ React2.createElement(
|
|
236
|
+
})), /* @__PURE__ */ React2.createElement(Button, {
|
|
210
237
|
classNames: "is-full flex gap-2",
|
|
211
238
|
onClick: handleCancel
|
|
212
239
|
}, /* @__PURE__ */ React2.createElement("span", null, t("cancel label", {
|
|
@@ -215,34 +242,261 @@ var ColumnPanel = ({ context, tableDefs, tableDef, column, onUpdate, onDelete })
|
|
|
215
242
|
className: "grow"
|
|
216
243
|
}), /* @__PURE__ */ React2.createElement(X, {
|
|
217
244
|
className: getSize2(5)
|
|
218
|
-
})), /* @__PURE__ */ React2.createElement(
|
|
245
|
+
})), /* @__PURE__ */ React2.createElement(Button, {
|
|
219
246
|
classNames: "is-full flex gap-2",
|
|
220
247
|
onClick: () => onDelete?.(column.id)
|
|
221
248
|
}, /* @__PURE__ */ React2.createElement("span", null, t("delete label")), /* @__PURE__ */ React2.createElement("div", {
|
|
222
249
|
className: "grow"
|
|
223
250
|
}), /* @__PURE__ */ React2.createElement(Trash, {
|
|
224
251
|
className: getSize2(5)
|
|
225
|
-
}))))
|
|
252
|
+
}))));
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
// packages/ui/react-ui-table/src/hooks/useColumnSorting.ts
|
|
256
|
+
import { useState as useState3 } from "react";
|
|
257
|
+
var useColumnSorting = (column) => {
|
|
258
|
+
const [sortDirection, setSortDirection] = useState3(column.getIsSorted());
|
|
259
|
+
const [firstSort, setFirstSort] = useState3();
|
|
260
|
+
const canSort = column.getCanSort();
|
|
261
|
+
const updateColumnSort = (direction) => {
|
|
262
|
+
setSortDirection(direction);
|
|
263
|
+
switch (direction) {
|
|
264
|
+
case false:
|
|
265
|
+
column.clearSorting();
|
|
266
|
+
break;
|
|
267
|
+
case "asc":
|
|
268
|
+
column.toggleSorting(false);
|
|
269
|
+
break;
|
|
270
|
+
case "desc":
|
|
271
|
+
column.toggleSorting(true);
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
const onToggleSort = () => {
|
|
276
|
+
if (sortDirection === false) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (sortDirection === firstSort) {
|
|
280
|
+
updateColumnSort(firstSort === "asc" ? "desc" : "asc");
|
|
281
|
+
} else {
|
|
282
|
+
updateColumnSort(false);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
const onSelectSort = (direction) => {
|
|
286
|
+
setFirstSort(direction);
|
|
287
|
+
updateColumnSort(direction);
|
|
288
|
+
};
|
|
289
|
+
const onClearSort = () => {
|
|
290
|
+
updateColumnSort(false);
|
|
291
|
+
};
|
|
292
|
+
return {
|
|
293
|
+
canSort,
|
|
294
|
+
sortDirection,
|
|
295
|
+
onSelectSort,
|
|
296
|
+
onToggleSort,
|
|
297
|
+
onClearSort
|
|
298
|
+
};
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
// packages/ui/react-ui-table/src/hooks/usePinLastRow.ts
|
|
302
|
+
import { useCallback as useCallback2, useEffect, useState as useState4 } from "react";
|
|
303
|
+
var usePinLastRow = (pinLastRow, table, data, getScrollElement) => {
|
|
304
|
+
const [pinnedRowKey, setPinnedRowKey] = useState4();
|
|
305
|
+
const scrollToBottom = useCallback2(() => {
|
|
306
|
+
const scrollElement = getScrollElement?.();
|
|
307
|
+
if (scrollElement) {
|
|
308
|
+
requestAnimationFrame(() => scrollElement.scrollTo({
|
|
309
|
+
top: scrollElement.scrollHeight
|
|
310
|
+
}));
|
|
311
|
+
}
|
|
312
|
+
}, [
|
|
313
|
+
getScrollElement
|
|
314
|
+
]);
|
|
315
|
+
const pinRow = useCallback2((rowToPin) => {
|
|
316
|
+
table.resetRowPinning();
|
|
317
|
+
rowToPin.pin("bottom");
|
|
318
|
+
setPinnedRowKey(rowToPin.id);
|
|
319
|
+
}, [
|
|
320
|
+
table
|
|
321
|
+
]);
|
|
322
|
+
const clearRowPinning = useCallback2(() => {
|
|
323
|
+
table.resetRowPinning();
|
|
324
|
+
setPinnedRowKey(void 0);
|
|
325
|
+
}, [
|
|
326
|
+
table
|
|
327
|
+
]);
|
|
328
|
+
const pinLastRowCallback = useCallback2(() => {
|
|
329
|
+
const rows = table.getRowModel().rows;
|
|
330
|
+
if (rows.length === 0) {
|
|
331
|
+
return clearRowPinning();
|
|
332
|
+
}
|
|
333
|
+
const lastRow = rows[rows.length - 1];
|
|
334
|
+
if (lastRow.id === pinnedRowKey) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
pinRow(lastRow);
|
|
338
|
+
if (pinnedRowKey !== void 0) {
|
|
339
|
+
scrollToBottom();
|
|
340
|
+
}
|
|
341
|
+
}, [
|
|
342
|
+
table,
|
|
343
|
+
scrollToBottom,
|
|
344
|
+
pinnedRowKey
|
|
345
|
+
]);
|
|
346
|
+
useEffect(() => {
|
|
347
|
+
if (pinLastRow) {
|
|
348
|
+
pinLastRowCallback();
|
|
349
|
+
}
|
|
350
|
+
}, [
|
|
351
|
+
data,
|
|
352
|
+
pinLastRow,
|
|
353
|
+
pinLastRowCallback
|
|
354
|
+
]);
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
// packages/ui/react-ui-table/src/components/ColumnMenu/ColumnMenu.tsx
|
|
358
|
+
var ColumnMenu = ({ column, ...props }) => {
|
|
359
|
+
const title = column.label?.length ? column.label : column.id;
|
|
360
|
+
const header = props.context.header;
|
|
361
|
+
const { canSort, sortDirection, onSelectSort, onToggleSort, onClearSort } = useColumnSorting(header.column);
|
|
362
|
+
const columnSettingsAnchorRef = useRef2(null);
|
|
363
|
+
const [isColumnSettingsOpen, setIsColumnSettingsOpen] = useState5(false);
|
|
364
|
+
const shouldPreventFocusOnClose = useRef2(false);
|
|
365
|
+
const onOpenColumnSettings = useCallback3(() => {
|
|
366
|
+
shouldPreventFocusOnClose.current = true;
|
|
367
|
+
setIsColumnSettingsOpen(true);
|
|
368
|
+
}, [
|
|
369
|
+
shouldPreventFocusOnClose,
|
|
370
|
+
setIsColumnSettingsOpen
|
|
371
|
+
]);
|
|
372
|
+
const onDropdownCloseAutoFocus = useCallback3((event) => {
|
|
373
|
+
if (shouldPreventFocusOnClose.current) {
|
|
374
|
+
event.preventDefault();
|
|
375
|
+
shouldPreventFocusOnClose.current = false;
|
|
376
|
+
}
|
|
377
|
+
}, [
|
|
378
|
+
shouldPreventFocusOnClose
|
|
379
|
+
]);
|
|
380
|
+
return /* @__PURE__ */ React3.createElement("div", {
|
|
381
|
+
className: "flex items-center justify-center justify-between"
|
|
382
|
+
}, /* @__PURE__ */ React3.createElement("div", {
|
|
383
|
+
className: "flex items-center gap-1 truncate",
|
|
384
|
+
title
|
|
385
|
+
}, /* @__PURE__ */ React3.createElement(SortIndicator, {
|
|
386
|
+
direction: sortDirection,
|
|
387
|
+
onClick: onToggleSort
|
|
388
|
+
}), /* @__PURE__ */ React3.createElement("div", {
|
|
389
|
+
className: "truncate"
|
|
390
|
+
}, title)), /* @__PURE__ */ React3.createElement(DropdownMenu.Root, {
|
|
391
|
+
modal: false
|
|
392
|
+
}, /* @__PURE__ */ React3.createElement(Popover2.Root, {
|
|
393
|
+
open: isColumnSettingsOpen,
|
|
394
|
+
onOpenChange: setIsColumnSettingsOpen,
|
|
395
|
+
modal: false
|
|
396
|
+
}, /* @__PURE__ */ React3.createElement(DropdownMenu.Trigger, {
|
|
397
|
+
ref: columnSettingsAnchorRef,
|
|
398
|
+
asChild: true
|
|
399
|
+
}, /* @__PURE__ */ React3.createElement(Popover2.Anchor, {
|
|
400
|
+
asChild: true
|
|
401
|
+
}, /* @__PURE__ */ React3.createElement(Button2, {
|
|
402
|
+
variant: "ghost"
|
|
403
|
+
}, /* @__PURE__ */ React3.createElement(CaretDown2, {
|
|
404
|
+
className: getSize3(4)
|
|
405
|
+
})))), /* @__PURE__ */ React3.createElement(DropdownMenu.Content, {
|
|
406
|
+
onCloseAutoFocus: onDropdownCloseAutoFocus,
|
|
407
|
+
sideOffset: 4,
|
|
408
|
+
collisionPadding: 8
|
|
409
|
+
}, /* @__PURE__ */ React3.createElement(DropdownMenu.Viewport, null, canSort && /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(DropdownMenu.Item, {
|
|
410
|
+
onClick: () => onSelectSort("asc")
|
|
411
|
+
}, /* @__PURE__ */ React3.createElement("span", {
|
|
412
|
+
className: "grow"
|
|
413
|
+
}, "Sort ascending"), /* @__PURE__ */ React3.createElement("span", {
|
|
414
|
+
className: "opacity-50"
|
|
415
|
+
}, /* @__PURE__ */ React3.createElement(ArrowUp, {
|
|
416
|
+
className: getSize3(4)
|
|
417
|
+
}))), /* @__PURE__ */ React3.createElement(DropdownMenu.Item, {
|
|
418
|
+
onClick: () => onSelectSort("desc")
|
|
419
|
+
}, /* @__PURE__ */ React3.createElement("span", {
|
|
420
|
+
className: "grow"
|
|
421
|
+
}, "Sort descending"), /* @__PURE__ */ React3.createElement("span", {
|
|
422
|
+
className: "opacity-50"
|
|
423
|
+
}, /* @__PURE__ */ React3.createElement(ArrowDown, {
|
|
424
|
+
className: getSize3(4)
|
|
425
|
+
}))), sortDirection !== false && /* @__PURE__ */ React3.createElement(DropdownMenu.Item, {
|
|
426
|
+
onClick: onClearSort
|
|
427
|
+
}, /* @__PURE__ */ React3.createElement("span", {
|
|
428
|
+
className: "grow"
|
|
429
|
+
}, "Clear sort"), /* @__PURE__ */ React3.createElement("span", {
|
|
430
|
+
className: "opacity-50"
|
|
431
|
+
}, /* @__PURE__ */ React3.createElement(X2, {
|
|
432
|
+
className: getSize3(4)
|
|
433
|
+
})))), /* @__PURE__ */ React3.createElement(DropdownMenu.Item, {
|
|
434
|
+
onClick: onOpenColumnSettings
|
|
435
|
+
}, /* @__PURE__ */ React3.createElement("span", {
|
|
436
|
+
className: "grow"
|
|
437
|
+
}, "Column settings"), /* @__PURE__ */ React3.createElement("span", {
|
|
438
|
+
className: "opacity-50"
|
|
439
|
+
}, /* @__PURE__ */ React3.createElement(GearSix, {
|
|
440
|
+
className: mx3(getSize3(4), "rotate-90")
|
|
441
|
+
})))), /* @__PURE__ */ React3.createElement(DropdownMenu.Arrow, null)), /* @__PURE__ */ React3.createElement(ColumnSettingsPanel, {
|
|
442
|
+
...props,
|
|
443
|
+
column,
|
|
444
|
+
onClose: () => setIsColumnSettingsOpen(false)
|
|
445
|
+
}))));
|
|
446
|
+
};
|
|
447
|
+
var ColumnSettingsPanel = ({ tableDefs, tableDef, column, onUpdate, onDelete, onClose }) => /* @__PURE__ */ React3.createElement(Popover2.Portal, null, /* @__PURE__ */ React3.createElement(Popover2.Content, null, /* @__PURE__ */ React3.createElement(Popover2.Viewport, {
|
|
448
|
+
classNames: "w-60"
|
|
449
|
+
}, /* @__PURE__ */ React3.createElement(DensityProvider, {
|
|
450
|
+
density: "fine"
|
|
451
|
+
}, /* @__PURE__ */ React3.createElement(ColumnSettingsForm, {
|
|
452
|
+
column,
|
|
453
|
+
tableDefs,
|
|
454
|
+
tableDef,
|
|
455
|
+
onUpdate,
|
|
456
|
+
onDelete,
|
|
457
|
+
onClose
|
|
458
|
+
}))), /* @__PURE__ */ React3.createElement(Popover2.Arrow, null)));
|
|
459
|
+
var SortIndicator = ({ direction, onClick }) => {
|
|
460
|
+
if (direction === false) {
|
|
461
|
+
return null;
|
|
462
|
+
}
|
|
463
|
+
let icon;
|
|
464
|
+
switch (direction) {
|
|
465
|
+
case "asc":
|
|
466
|
+
icon = /* @__PURE__ */ React3.createElement(ArrowUp, {
|
|
467
|
+
className: getSize3(3)
|
|
468
|
+
});
|
|
469
|
+
break;
|
|
470
|
+
case "desc":
|
|
471
|
+
icon = /* @__PURE__ */ React3.createElement(ArrowDown, {
|
|
472
|
+
className: getSize3(3)
|
|
473
|
+
});
|
|
474
|
+
break;
|
|
475
|
+
}
|
|
476
|
+
return /* @__PURE__ */ React3.createElement("div", {
|
|
477
|
+
onClick,
|
|
478
|
+
className: "flex items-center cursor-pointer"
|
|
479
|
+
}, icon);
|
|
226
480
|
};
|
|
227
481
|
|
|
228
482
|
// packages/ui/react-ui-table/src/components/Table/Table.tsx
|
|
229
483
|
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
230
484
|
import { getCoreRowModel, getSortedRowModel, useReactTable, getGroupedRowModel, getExpandedRowModel } from "@tanstack/react-table";
|
|
231
485
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
232
|
-
import
|
|
486
|
+
import React9, { Fragment, useCallback as useCallback4, useEffect as useEffect2, useState as useState6 } from "react";
|
|
233
487
|
import { log } from "@dxos/log";
|
|
234
488
|
import { useDefaultValue, useOnTransition } from "@dxos/react-ui";
|
|
235
489
|
|
|
236
490
|
// packages/ui/react-ui-table/src/components/Table/TableBody.tsx
|
|
237
491
|
import { useArrowNavigationGroup } from "@fluentui/react-tabster";
|
|
238
492
|
import { flexRender } from "@tanstack/react-table";
|
|
239
|
-
import
|
|
493
|
+
import React6 from "react";
|
|
240
494
|
|
|
241
495
|
// packages/ui/react-ui-table/src/components/Table/TableContext.tsx
|
|
242
|
-
import
|
|
496
|
+
import React4, { useContext, createContext } from "react";
|
|
243
497
|
var TableContext = /* @__PURE__ */ createContext({});
|
|
244
498
|
var TableProvider = ({ children, ...value }) => {
|
|
245
|
-
return /* @__PURE__ */
|
|
499
|
+
return /* @__PURE__ */ React4.createElement(TableContext.Provider, {
|
|
246
500
|
value
|
|
247
501
|
}, children);
|
|
248
502
|
};
|
|
@@ -252,32 +506,32 @@ var useTableContext = () => {
|
|
|
252
506
|
};
|
|
253
507
|
|
|
254
508
|
// packages/ui/react-ui-table/src/theme.ts
|
|
255
|
-
import { modalSurface, focusRing, ghostSelected, ghostSelectedCurrent, groupBorder, mx as
|
|
509
|
+
import { modalSurface, focusRing, ghostSelected, ghostSelectedCurrent, groupBorder, mx as mx4 } from "@dxos/react-ui-theme";
|
|
256
510
|
var currentRow = "!bg-neutral-75 !dark:bg-neutral-850";
|
|
257
511
|
var selectedRow = "!bg-primary-100 dark:!bg-primary-700";
|
|
258
512
|
var flushPadding = "pli-0 plb-0";
|
|
259
513
|
var textPadding = "pli-2 plb-0.5";
|
|
260
514
|
var headPadding = "pli-2 plb-1";
|
|
261
515
|
var gridCellFocusRing = "focus-within:z-[11] focus-within:outline outline-2 outline-primary-500 dark:outline-primary-400";
|
|
262
|
-
var tableRoot = ({ fullWidth }, ...etc) =>
|
|
263
|
-
var groupTh = (_props, ...etc) =>
|
|
264
|
-
var theadRoot = ({ header, stickyHeader }, ...etc) =>
|
|
265
|
-
var theadTr = (_props, ...etc) =>
|
|
266
|
-
var theadTh = ({ border }, ...etc) =>
|
|
516
|
+
var tableRoot = ({ fullWidth }, ...etc) => mx4("table-fixed", fullWidth && "is-full", ...etc);
|
|
517
|
+
var groupTh = (_props, ...etc) => mx4("text-start font-medium", flushPadding, ...etc);
|
|
518
|
+
var theadRoot = ({ header, stickyHeader }, ...etc) => mx4(header ? stickyHeader && "sticky block-start-[--sticky-top] z-[1]" : "collapse", header && "base-surface", "drop-shadow-sm", ...etc);
|
|
519
|
+
var theadTr = (_props, ...etc) => mx4("group", ...etc);
|
|
520
|
+
var theadTh = ({ border }, ...etc) => mx4("relative", "text-start font-medium select-none truncate", headPadding, border && groupBorder, border && "border border-t-0 border-b-0 border-neutral-200", ...etc);
|
|
267
521
|
var theadResizeRoot = ({ isResizing }) => {
|
|
268
|
-
return
|
|
522
|
+
return mx4("absolute h-full w-[4px] top-0 right-0", "cursor-col-resize", "user-select-none", "touch-action-none", !isResizing && "group-hover:bg-neutral-100 dark:group-hover:bg-neutral-800", "pointer-coarse:bg-neutral-100 dark:pointer-coarse:bg-neutral-800", isResizing && "bg-primary-500 dark:bg-primary-400");
|
|
269
523
|
};
|
|
270
|
-
var tbodyRoot = (_props, ...etc) =>
|
|
271
|
-
var tbodyTr = ({ canBeCurrent, isPinned }, ...etc) =>
|
|
272
|
-
var tdRoot = ({ border, isGrid }, ...etc) =>
|
|
273
|
-
var tdContent = (_props, ...etc) =>
|
|
274
|
-
var tfootRoot = (_props, ...etc) =>
|
|
275
|
-
var tfootTr = (_props, ...etc) =>
|
|
276
|
-
var tfootTh = ({ border }, ...etc) =>
|
|
524
|
+
var tbodyRoot = (_props, ...etc) => mx4(...etc);
|
|
525
|
+
var tbodyTr = ({ canBeCurrent, isPinned }, ...etc) => mx4("group", canBeCurrent ? ghostSelectedCurrent : ghostSelected, canBeCurrent && focusRing, canBeCurrent && "cursor-pointer rounded", isPinned && "sticky z-1 bottom-[-1px] base-surface", ...etc);
|
|
526
|
+
var tdRoot = ({ border, isGrid }, ...etc) => mx4("relative", flushPadding, border && "border", border && groupBorder, isGrid && gridCellFocusRing, ...etc);
|
|
527
|
+
var tdContent = (_props, ...etc) => mx4(...etc);
|
|
528
|
+
var tfootRoot = (_props, ...etc) => mx4("sticky block-end-0 z-10", modalSurface, ...etc);
|
|
529
|
+
var tfootTr = (_props, ...etc) => mx4(...etc);
|
|
530
|
+
var tfootTh = ({ border }, ...etc) => mx4(textPadding, modalSurface, border && groupBorder, ...etc);
|
|
277
531
|
|
|
278
532
|
// packages/ui/react-ui-table/src/components/Cell/Cell.tsx
|
|
279
533
|
import { useFocusableGroup } from "@fluentui/react-tabster";
|
|
280
|
-
import
|
|
534
|
+
import React5 from "react";
|
|
281
535
|
var CELL_NAME = "Cell";
|
|
282
536
|
var FocusableCell = ({ cell, children }) => {
|
|
283
537
|
const tableContext = useTableContext();
|
|
@@ -285,7 +539,7 @@ var FocusableCell = ({ cell, children }) => {
|
|
|
285
539
|
tabBehavior: "limited"
|
|
286
540
|
});
|
|
287
541
|
const className = tdRoot(tableContext, cell.column.columnDef.meta?.cell?.classNames);
|
|
288
|
-
return /* @__PURE__ */
|
|
542
|
+
return /* @__PURE__ */ React5.createElement("td", {
|
|
289
543
|
tabIndex: 0,
|
|
290
544
|
...domAttributes,
|
|
291
545
|
className
|
|
@@ -293,14 +547,14 @@ var FocusableCell = ({ cell, children }) => {
|
|
|
293
547
|
};
|
|
294
548
|
var StaticCell = ({ cell, children }) => {
|
|
295
549
|
const tableContext = useTableContext();
|
|
296
|
-
return /* @__PURE__ */
|
|
550
|
+
return /* @__PURE__ */ React5.createElement("td", {
|
|
297
551
|
className: tdRoot(tableContext, cell.column.columnDef.meta?.cell?.classNames)
|
|
298
552
|
}, children);
|
|
299
553
|
};
|
|
300
554
|
var Cell = ({ cell, children }) => {
|
|
301
555
|
const { isGrid } = useTableContext();
|
|
302
556
|
const Root = isGrid ? FocusableCell : StaticCell;
|
|
303
|
-
return /* @__PURE__ */
|
|
557
|
+
return /* @__PURE__ */ React5.createElement(Root, {
|
|
304
558
|
cell
|
|
305
559
|
}, children);
|
|
306
560
|
};
|
|
@@ -315,7 +569,7 @@ var TableBody = ({ rows }) => {
|
|
|
315
569
|
axis: "grid"
|
|
316
570
|
});
|
|
317
571
|
const canBeCurrent = !isGrid && !!onDatumClick;
|
|
318
|
-
return /* @__PURE__ */
|
|
572
|
+
return /* @__PURE__ */ React6.createElement("tbody", isGrid && domAttributes, rows.map((row) => {
|
|
319
573
|
const isCurrent = currentDatum === row.original;
|
|
320
574
|
const isSelected = rowSelection?.[row.id];
|
|
321
575
|
const isPinned = row.getIsPinned();
|
|
@@ -323,7 +577,7 @@ var TableBody = ({ rows }) => {
|
|
|
323
577
|
canBeCurrent,
|
|
324
578
|
isPinned: isPinned !== false
|
|
325
579
|
});
|
|
326
|
-
return /* @__PURE__ */
|
|
580
|
+
return /* @__PURE__ */ React6.createElement("tr", {
|
|
327
581
|
key: keyAccessor ? keyAccessor(row.original) : row.id,
|
|
328
582
|
className: classNames,
|
|
329
583
|
...isCurrent && {
|
|
@@ -343,57 +597,57 @@ var TableBody = ({ rows }) => {
|
|
|
343
597
|
}
|
|
344
598
|
}
|
|
345
599
|
}
|
|
346
|
-
}, debug && /* @__PURE__ */
|
|
347
|
-
return /* @__PURE__ */
|
|
600
|
+
}, debug && /* @__PURE__ */ React6.createElement("td", null, row.id), row.getVisibleCells().map((cell) => {
|
|
601
|
+
return /* @__PURE__ */ React6.createElement(Cell, {
|
|
348
602
|
key: cell.id,
|
|
349
603
|
cell
|
|
350
604
|
}, flexRender(cell.column.columnDef.cell, {
|
|
351
605
|
className: "pli-2",
|
|
352
606
|
...cell.getContext()
|
|
353
607
|
}));
|
|
354
|
-
}), expand && /* @__PURE__ */
|
|
608
|
+
}), expand && /* @__PURE__ */ React6.createElement("td", null));
|
|
355
609
|
}));
|
|
356
610
|
};
|
|
357
611
|
TableBody.displayName = TABLE_BODY_NAME;
|
|
358
612
|
|
|
359
613
|
// packages/ui/react-ui-table/src/components/Table/TableFooter.tsx
|
|
360
614
|
import { flexRender as flexRender2 } from "@tanstack/react-table";
|
|
361
|
-
import
|
|
615
|
+
import React7 from "react";
|
|
362
616
|
var TABLE_FOOT_NAME = "TableFooter";
|
|
363
617
|
var TableFooter = (props) => {
|
|
364
618
|
const tableContext = useTableContext();
|
|
365
619
|
const { table, expand, debug } = tableContext;
|
|
366
620
|
const footers = table.getFooterGroups();
|
|
367
|
-
return /* @__PURE__ */
|
|
621
|
+
return /* @__PURE__ */ React7.createElement("tfoot", {
|
|
368
622
|
className: tfootRoot(props)
|
|
369
|
-
}, footers.map((footerGroup) => /* @__PURE__ */
|
|
623
|
+
}, footers.map((footerGroup) => /* @__PURE__ */ React7.createElement("tr", {
|
|
370
624
|
key: footerGroup.id,
|
|
371
625
|
className: tfootTr(tableContext)
|
|
372
|
-
}, debug && /* @__PURE__ */
|
|
373
|
-
return /* @__PURE__ */
|
|
626
|
+
}, debug && /* @__PURE__ */ React7.createElement("th", null), footerGroup.headers.map((footer) => {
|
|
627
|
+
return /* @__PURE__ */ React7.createElement("th", {
|
|
374
628
|
key: footer.id,
|
|
375
629
|
className: tfootTh(tableContext, footer.column.columnDef.meta?.footer?.classNames)
|
|
376
630
|
}, footer.isPlaceholder ? null : flexRender2(footer.column.columnDef.footer, footer.getContext()));
|
|
377
|
-
}), expand && /* @__PURE__ */
|
|
631
|
+
}), expand && /* @__PURE__ */ React7.createElement("th", null))));
|
|
378
632
|
};
|
|
379
633
|
TableFooter.displayName = TABLE_FOOT_NAME;
|
|
380
634
|
|
|
381
635
|
// packages/ui/react-ui-table/src/components/Table/TableHead.tsx
|
|
382
636
|
import { flexRender as flexRender3 } from "@tanstack/react-table";
|
|
383
|
-
import
|
|
637
|
+
import React8 from "react";
|
|
384
638
|
var TABLE_HEAD_NAME = "TableHeader";
|
|
385
639
|
var TableHead = (_props) => {
|
|
386
640
|
const tableContext = useTableContext();
|
|
387
641
|
const headerGroups = tableContext.table.getHeaderGroups();
|
|
388
|
-
return /* @__PURE__ */
|
|
642
|
+
return /* @__PURE__ */ React8.createElement("thead", {
|
|
389
643
|
className: theadRoot(tableContext)
|
|
390
644
|
}, headerGroups.map((headerGroup) => {
|
|
391
645
|
return (
|
|
392
646
|
// Group element to hover resize handles.
|
|
393
|
-
/* @__PURE__ */
|
|
647
|
+
/* @__PURE__ */ React8.createElement("tr", {
|
|
394
648
|
key: headerGroup.id,
|
|
395
649
|
className: theadTr(tableContext)
|
|
396
|
-
}, tableContext.debug && /* @__PURE__ */
|
|
650
|
+
}, tableContext.debug && /* @__PURE__ */ React8.createElement("th", {
|
|
397
651
|
className: "font-mono",
|
|
398
652
|
style: {
|
|
399
653
|
width: 32
|
|
@@ -402,13 +656,13 @@ var TableHead = (_props) => {
|
|
|
402
656
|
const isResizing = header.column.getIsResizing();
|
|
403
657
|
const onResize = header.getResizeHandler();
|
|
404
658
|
const resizable = header.column.columnDef.meta?.resizable;
|
|
405
|
-
return /* @__PURE__ */
|
|
659
|
+
return /* @__PURE__ */ React8.createElement("th", {
|
|
406
660
|
key: header.id,
|
|
407
661
|
style: {
|
|
408
662
|
width: header.getSize()
|
|
409
663
|
},
|
|
410
664
|
className: theadTh(tableContext, header.column.columnDef.meta?.header?.classNames)
|
|
411
|
-
}, !header || header.isPlaceholder ? null : flexRender3(header.column.columnDef.header, header.getContext()), resizable && /* @__PURE__ */
|
|
665
|
+
}, !header || header.isPlaceholder ? null : flexRender3(header.column.columnDef.header, header.getContext()), resizable && /* @__PURE__ */ React8.createElement("div", {
|
|
412
666
|
className: theadResizeRoot({
|
|
413
667
|
isResizing
|
|
414
668
|
}),
|
|
@@ -416,48 +670,12 @@ var TableHead = (_props) => {
|
|
|
416
670
|
onMouseDown: onResize,
|
|
417
671
|
onTouchStart: onResize
|
|
418
672
|
}));
|
|
419
|
-
}), tableContext.expand && /* @__PURE__ */
|
|
673
|
+
}), tableContext.expand && /* @__PURE__ */ React8.createElement("th", null))
|
|
420
674
|
);
|
|
421
675
|
}));
|
|
422
676
|
};
|
|
423
677
|
TableHead.displayName = TABLE_HEAD_NAME;
|
|
424
678
|
|
|
425
|
-
// packages/ui/react-ui-table/src/components/hooks/usePinLastRow.ts
|
|
426
|
-
import { useEffect, useState as useState2 } from "react";
|
|
427
|
-
var usePinLastRow = (pinLastRow, table, data, getScrollElement) => {
|
|
428
|
-
const [pinnedRowKey, setPinnedRowKey] = useState2();
|
|
429
|
-
useEffect(() => {
|
|
430
|
-
if (!pinLastRow) {
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
const rows = table.getRowModel().rows;
|
|
434
|
-
const rowToPin = rows[rows.length - 1];
|
|
435
|
-
const rowId = rowToPin.id;
|
|
436
|
-
if (rowId === pinnedRowKey) {
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
table.resetRowPinning();
|
|
440
|
-
rowToPin.pin("bottom");
|
|
441
|
-
const scrollElement = getScrollElement?.();
|
|
442
|
-
const isFirstRender = pinnedRowKey === void 0;
|
|
443
|
-
if (scrollElement && !isFirstRender) {
|
|
444
|
-
requestAnimationFrame(() => {
|
|
445
|
-
scrollElement.scrollTo({
|
|
446
|
-
top: scrollElement.scrollHeight
|
|
447
|
-
});
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
setPinnedRowKey(rowId);
|
|
451
|
-
}, [
|
|
452
|
-
pinLastRow,
|
|
453
|
-
table,
|
|
454
|
-
getScrollElement,
|
|
455
|
-
pinnedRowKey,
|
|
456
|
-
setPinnedRowKey,
|
|
457
|
-
data
|
|
458
|
-
]);
|
|
459
|
-
};
|
|
460
|
-
|
|
461
679
|
// packages/ui/react-ui-table/src/components/Table/Table.tsx
|
|
462
680
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/Table/Table.tsx";
|
|
463
681
|
var Table = (props) => {
|
|
@@ -465,8 +683,8 @@ var Table = (props) => {
|
|
|
465
683
|
const columns = useDefaultValue(props.columns, []);
|
|
466
684
|
const data = useDefaultValue(props.data, []);
|
|
467
685
|
const TableProvider2 = TableProvider;
|
|
468
|
-
const [columnsInitialised, setColumnsInitialised] =
|
|
469
|
-
const [columnSizing, setColumnSizing] =
|
|
686
|
+
const [columnsInitialised, setColumnsInitialised] = useState6(false);
|
|
687
|
+
const [columnSizing, setColumnSizing] = useState6({});
|
|
470
688
|
useEffect2(() => {
|
|
471
689
|
if (columnsInitialised) {
|
|
472
690
|
return;
|
|
@@ -480,8 +698,8 @@ var Table = (props) => {
|
|
|
480
698
|
columns,
|
|
481
699
|
setColumnSizing
|
|
482
700
|
]);
|
|
483
|
-
const [columnSizingInfo, setColumnSizingInfo] =
|
|
484
|
-
const notifyColumnResize =
|
|
701
|
+
const [columnSizingInfo, setColumnSizingInfo] = useState6({});
|
|
702
|
+
const notifyColumnResize = useCallback4(() => onColumnResize?.(columnSizing), [
|
|
485
703
|
onColumnResize,
|
|
486
704
|
columnSizing
|
|
487
705
|
]);
|
|
@@ -491,7 +709,7 @@ var Table = (props) => {
|
|
|
491
709
|
onChange: props.onRowSelectionChange,
|
|
492
710
|
defaultProp: props.defaultRowSelection
|
|
493
711
|
});
|
|
494
|
-
const handleRowSelectionChange =
|
|
712
|
+
const handleRowSelectionChange = useCallback4((updaterOrValue) => {
|
|
495
713
|
const nextRowSelection = typeof updaterOrValue === "function" ? updaterOrValue(rowSelection) : updaterOrValue;
|
|
496
714
|
if (rowsSelectable === "multi") {
|
|
497
715
|
setRowSelection(nextRowSelection);
|
|
@@ -508,7 +726,7 @@ var Table = (props) => {
|
|
|
508
726
|
setRowSelection,
|
|
509
727
|
rowSelection
|
|
510
728
|
]);
|
|
511
|
-
const [grouping, handleGroupingChange] =
|
|
729
|
+
const [grouping, handleGroupingChange] = useState6(props.grouping ?? []);
|
|
512
730
|
useEffect2(() => handleGroupingChange(props.grouping ?? []), [
|
|
513
731
|
handleGroupingChange,
|
|
514
732
|
props.grouping
|
|
@@ -563,18 +781,18 @@ var Table = (props) => {
|
|
|
563
781
|
if (!getScrollElement) {
|
|
564
782
|
log.warn("Table: getScrollElement is not set. This is required for virtualized tables.", void 0, {
|
|
565
783
|
F: __dxlog_file,
|
|
566
|
-
L:
|
|
784
|
+
L: 160,
|
|
567
785
|
S: void 0,
|
|
568
786
|
C: (f, a) => f(...a)
|
|
569
787
|
});
|
|
570
788
|
}
|
|
571
|
-
return /* @__PURE__ */
|
|
789
|
+
return /* @__PURE__ */ React9.createElement(TableProvider2, {
|
|
572
790
|
...props,
|
|
573
791
|
table,
|
|
574
792
|
header,
|
|
575
793
|
expand,
|
|
576
794
|
isGrid: role === "grid" || role === "treegrid"
|
|
577
|
-
}, /* @__PURE__ */
|
|
795
|
+
}, /* @__PURE__ */ React9.createElement(TableImpl, {
|
|
578
796
|
debug: false,
|
|
579
797
|
getScrollElement,
|
|
580
798
|
...props
|
|
@@ -583,20 +801,14 @@ var Table = (props) => {
|
|
|
583
801
|
var TableImpl = (props) => {
|
|
584
802
|
const { debug, classNames, getScrollElement, role, footer, grouping, fullWidth } = props;
|
|
585
803
|
const { table } = useTableContext();
|
|
586
|
-
const centerRows = table.getCenterRows();
|
|
587
|
-
const bottomRows = table.getBottomRows();
|
|
588
|
-
const rows = [
|
|
589
|
-
...centerRows,
|
|
590
|
-
...bottomRows
|
|
591
|
-
];
|
|
592
804
|
if (debug) {
|
|
593
|
-
return /* @__PURE__ */
|
|
805
|
+
return /* @__PURE__ */ React9.createElement("pre", {
|
|
594
806
|
className: "font-mono text-xs text-neutral-500 m-1 p-2 ring"
|
|
595
|
-
}, /* @__PURE__ */
|
|
807
|
+
}, /* @__PURE__ */ React9.createElement("code", null, JSON.stringify(table.getState(), void 0, 2)));
|
|
596
808
|
}
|
|
597
809
|
const virtualisable = getScrollElement !== void 0;
|
|
598
810
|
const isResizingColumn = table.getState().columnSizingInfo.isResizingColumn;
|
|
599
|
-
return /* @__PURE__ */
|
|
811
|
+
return /* @__PURE__ */ React9.createElement("table", {
|
|
600
812
|
role,
|
|
601
813
|
className: tableRoot(props, classNames),
|
|
602
814
|
...!fullWidth && {
|
|
@@ -604,18 +816,32 @@ var TableImpl = (props) => {
|
|
|
604
816
|
width: table.getTotalSize()
|
|
605
817
|
}
|
|
606
818
|
}
|
|
607
|
-
}, /* @__PURE__ */
|
|
819
|
+
}, /* @__PURE__ */ React9.createElement(TableHead, null), grouping?.length !== 0 ? virtualisable ? isResizingColumn ? /* @__PURE__ */ React9.createElement(MemoizedVirtualisedTableContent, {
|
|
608
820
|
getScrollElement
|
|
609
|
-
}) : /* @__PURE__ */
|
|
821
|
+
}) : /* @__PURE__ */ React9.createElement(VirtualizedTableContent, {
|
|
610
822
|
getScrollElement
|
|
611
|
-
}) : /* @__PURE__ */
|
|
823
|
+
}) : /* @__PURE__ */ React9.createElement(UnvirtualizedTableContent, null) : /* @__PURE__ */ React9.createElement(GroupedTableContent, null), footer && /* @__PURE__ */ React9.createElement(TableFooter, null));
|
|
824
|
+
};
|
|
825
|
+
var UnvirtualizedTableContent = () => {
|
|
826
|
+
const { table } = useTableContext();
|
|
827
|
+
const centerRows = table.getCenterRows();
|
|
828
|
+
const pinnedRows = table.getBottomRows();
|
|
829
|
+
const rows = [
|
|
830
|
+
...centerRows,
|
|
831
|
+
...pinnedRows
|
|
832
|
+
];
|
|
833
|
+
return /* @__PURE__ */ React9.createElement(TableBody, {
|
|
612
834
|
rows
|
|
613
|
-
})
|
|
835
|
+
});
|
|
614
836
|
};
|
|
615
837
|
var VirtualizedTableContent = ({ getScrollElement }) => {
|
|
616
838
|
const { table } = useTableContext();
|
|
617
839
|
const centerRows = table.getCenterRows();
|
|
618
|
-
|
|
840
|
+
let pinnedRows = [];
|
|
841
|
+
try {
|
|
842
|
+
pinnedRows = table.getBottomRows();
|
|
843
|
+
} catch (_) {
|
|
844
|
+
}
|
|
619
845
|
const { getTotalSize, getVirtualItems } = useVirtualizer({
|
|
620
846
|
getScrollElement,
|
|
621
847
|
count: centerRows.length,
|
|
@@ -630,123 +856,54 @@ var VirtualizedTableContent = ({ getScrollElement }) => {
|
|
|
630
856
|
...virtualRows.map((virtualRow) => centerRows[virtualRow.index]),
|
|
631
857
|
...pinnedRows
|
|
632
858
|
];
|
|
633
|
-
return /* @__PURE__ */
|
|
859
|
+
return /* @__PURE__ */ React9.createElement(React9.Fragment, null, paddingTop > 0 && /* @__PURE__ */ React9.createElement("tbody", {
|
|
634
860
|
role: "none"
|
|
635
|
-
}, /* @__PURE__ */
|
|
861
|
+
}, /* @__PURE__ */ React9.createElement("tr", {
|
|
636
862
|
role: "none"
|
|
637
|
-
}, /* @__PURE__ */
|
|
863
|
+
}, /* @__PURE__ */ React9.createElement("td", {
|
|
638
864
|
style: {
|
|
639
865
|
height: `${paddingTop}px`
|
|
640
866
|
},
|
|
641
867
|
role: "none"
|
|
642
|
-
}))), /* @__PURE__ */
|
|
868
|
+
}))), /* @__PURE__ */ React9.createElement(TableBody, {
|
|
643
869
|
rows: rowsToRender
|
|
644
|
-
}), paddingBottom > 0 && /* @__PURE__ */
|
|
870
|
+
}), paddingBottom > 0 && /* @__PURE__ */ React9.createElement("tbody", {
|
|
645
871
|
role: "none"
|
|
646
|
-
}, /* @__PURE__ */
|
|
872
|
+
}, /* @__PURE__ */ React9.createElement("tr", {
|
|
647
873
|
role: "none"
|
|
648
|
-
}, /* @__PURE__ */
|
|
874
|
+
}, /* @__PURE__ */ React9.createElement("td", {
|
|
649
875
|
style: {
|
|
650
876
|
height: `${paddingBottom}px`
|
|
651
877
|
},
|
|
652
878
|
role: "none"
|
|
653
879
|
}))));
|
|
654
880
|
};
|
|
655
|
-
var MemoizedVirtualisedTableContent = /* @__PURE__ */
|
|
881
|
+
var MemoizedVirtualisedTableContent = /* @__PURE__ */ React9.memo(VirtualizedTableContent);
|
|
656
882
|
var GroupedTableContent = () => {
|
|
657
883
|
const { table: { getGroupedRowModel: getGroupedRowModel2, getHeaderGroups, getState }, debug } = useTableContext();
|
|
658
|
-
return /* @__PURE__ */
|
|
659
|
-
return /* @__PURE__ */
|
|
884
|
+
return /* @__PURE__ */ React9.createElement(React9.Fragment, null, getGroupedRowModel2().rows.map((row, i) => {
|
|
885
|
+
return /* @__PURE__ */ React9.createElement(Fragment, {
|
|
660
886
|
key: i
|
|
661
|
-
}, /* @__PURE__ */
|
|
887
|
+
}, /* @__PURE__ */ React9.createElement("thead", null, /* @__PURE__ */ React9.createElement("tr", null, debug && /* @__PURE__ */ React9.createElement("th", null), /* @__PURE__ */ React9.createElement("th", {
|
|
662
888
|
// TODO(burdon): Calculate row span.
|
|
663
889
|
colSpan: getHeaderGroups()[0].headers.length,
|
|
664
890
|
className: groupTh({})
|
|
665
|
-
}, getState().grouping[0], "[", String(row.getGroupingValue(getState().grouping[0])), "]"))), /* @__PURE__ */
|
|
891
|
+
}, getState().grouping[0], "[", String(row.getGroupingValue(getState().grouping[0])), "]"))), /* @__PURE__ */ React9.createElement(TableBody, {
|
|
666
892
|
rows: row.subRows
|
|
667
893
|
}));
|
|
668
894
|
}));
|
|
669
895
|
};
|
|
670
896
|
|
|
671
|
-
// packages/ui/react-ui-table/src/components/Cell/CellCombobox.tsx
|
|
672
|
-
import { CaretDown } from "@phosphor-icons/react";
|
|
673
|
-
import React9, { useCallback as useCallback2, useState as useState4 } from "react";
|
|
674
|
-
import { Popover as Popover2, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
675
|
-
import { PopoverCombobox } from "@dxos/react-ui-searchlist";
|
|
676
|
-
import { descriptionText, getSize as getSize3, mx as mx3, staticPlaceholderText } from "@dxos/react-ui-theme";
|
|
677
|
-
var initialItems = (model, value) => value ? {
|
|
678
|
-
[model.getId(value)]: {
|
|
679
|
-
label: model.getText(value),
|
|
680
|
-
data: value
|
|
681
|
-
}
|
|
682
|
-
} : {};
|
|
683
|
-
var CellCombobox = ({ model, value, onValueChange }) => {
|
|
684
|
-
const { t } = useTranslation2(translationKey);
|
|
685
|
-
const [items, setItems] = useState4(initialItems(model, value));
|
|
686
|
-
const [loading, setLoading] = useState4(false);
|
|
687
|
-
const [searchInputValue, setSearchInputValue] = useState4("");
|
|
688
|
-
const handleSearchInputValueChange = async (text) => {
|
|
689
|
-
setSearchInputValue(text ?? "");
|
|
690
|
-
setLoading(true);
|
|
691
|
-
const items2 = await model.query(text);
|
|
692
|
-
setItems(items2.reduce((acc, item) => {
|
|
693
|
-
acc[model.getId(item)] = {
|
|
694
|
-
label: model.getText(item),
|
|
695
|
-
data: item
|
|
696
|
-
};
|
|
697
|
-
return acc;
|
|
698
|
-
}, initialItems(model, value)));
|
|
699
|
-
setLoading(false);
|
|
700
|
-
};
|
|
701
|
-
const handleValueChange = useCallback2((id) => {
|
|
702
|
-
onValueChange(items[id]?.data);
|
|
703
|
-
}, [
|
|
704
|
-
items,
|
|
705
|
-
onValueChange
|
|
706
|
-
]);
|
|
707
|
-
return /* @__PURE__ */ React9.createElement(PopoverCombobox.Root, {
|
|
708
|
-
placeholder: t("no selection label")
|
|
709
|
-
}, /* @__PURE__ */ React9.createElement(PopoverCombobox.Trigger, {
|
|
710
|
-
variant: "ghost",
|
|
711
|
-
classNames: "is-full rounded-none ring-inset"
|
|
712
|
-
}, value ? /* @__PURE__ */ React9.createElement(React9.Fragment, null, /* @__PURE__ */ React9.createElement("span", {
|
|
713
|
-
className: mx3("font-normal text-start text-base flex-1 min-is-0 truncate mie-2", !value && staticPlaceholderText)
|
|
714
|
-
}, model.getText(value)), /* @__PURE__ */ React9.createElement(CaretDown, {
|
|
715
|
-
weight: "bold",
|
|
716
|
-
className: getSize3(3)
|
|
717
|
-
})) : null), /* @__PURE__ */ React9.createElement(PopoverCombobox.Content, {
|
|
718
|
-
shouldFilter: false,
|
|
719
|
-
classNames: "is-[--radix-popover-trigger-width]"
|
|
720
|
-
}, /* @__PURE__ */ React9.createElement(PopoverCombobox.Input, {
|
|
721
|
-
value: searchInputValue,
|
|
722
|
-
onValueChange: handleSearchInputValueChange
|
|
723
|
-
}), /* @__PURE__ */ React9.createElement(PopoverCombobox.List, null, searchInputValue.length < 1 ? /* @__PURE__ */ React9.createElement("p", {
|
|
724
|
-
className: mx3("text-center", descriptionText)
|
|
725
|
-
}, "Start typing to search") : loading ? /* @__PURE__ */ React9.createElement("p", {
|
|
726
|
-
className: mx3("text-center", descriptionText)
|
|
727
|
-
}, "Searching\u2026") : /* @__PURE__ */ React9.createElement(React9.Fragment, null, /* @__PURE__ */ React9.createElement(PopoverCombobox.Empty, {
|
|
728
|
-
classNames: [
|
|
729
|
-
"text-center",
|
|
730
|
-
descriptionText
|
|
731
|
-
]
|
|
732
|
-
}, "No results"), Object.entries(items).map(([id, { label }]) => /* @__PURE__ */ React9.createElement(PopoverCombobox.Item, {
|
|
733
|
-
key: id,
|
|
734
|
-
value: id,
|
|
735
|
-
onSelect: handleValueChange,
|
|
736
|
-
classNames: "truncate"
|
|
737
|
-
}, label)))), /* @__PURE__ */ React9.createElement(Popover2.Arrow, null)));
|
|
738
|
-
};
|
|
739
|
-
|
|
740
897
|
// packages/ui/react-ui-table/src/helpers.tsx
|
|
741
898
|
import { useFocusFinders } from "@fluentui/react-tabster";
|
|
742
|
-
import { Check as Check2, ClipboardText, X as
|
|
899
|
+
import { Check as Check2, ClipboardText, X as X3 } from "@phosphor-icons/react";
|
|
743
900
|
import { createColumnHelper } from "@tanstack/react-table";
|
|
744
901
|
import { format } from "date-fns/format";
|
|
745
902
|
import { formatDistanceToNow } from "date-fns/formatDistanceToNow";
|
|
746
|
-
import React10, { useEffect as useEffect3, useRef as
|
|
903
|
+
import React10, { useEffect as useEffect3, useRef as useRef3, useState as useState7 } from "react";
|
|
747
904
|
import { log as log2 } from "@dxos/log";
|
|
748
905
|
import { Input as Input2, Tooltip } from "@dxos/react-ui";
|
|
749
|
-
import { getSize as getSize4, mx as
|
|
906
|
+
import { getSize as getSize4, mx as mx5 } from "@dxos/react-ui-theme";
|
|
750
907
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/helpers.tsx";
|
|
751
908
|
var createColumnBuilder = () => ({
|
|
752
909
|
helper: createColumnHelper(),
|
|
@@ -761,11 +918,11 @@ var ComboboxBuilderCell = (cellContext) => {
|
|
|
761
918
|
}) : null;
|
|
762
919
|
};
|
|
763
920
|
var StringBuilderCell = (cellContext) => {
|
|
764
|
-
const ref =
|
|
921
|
+
const ref = useRef3(null);
|
|
765
922
|
const { findPrevFocusable } = useFocusFinders();
|
|
766
923
|
const { onUpdate, cell } = cellContext.column.columnDef.meta;
|
|
767
924
|
const initialValue = cellContext.getValue();
|
|
768
|
-
const [value, setValue] =
|
|
925
|
+
const [value, setValue] = useState7(() => {
|
|
769
926
|
if (initialValue?.content) {
|
|
770
927
|
return initialValue?.content;
|
|
771
928
|
}
|
|
@@ -807,9 +964,9 @@ var displayNumber = (value, digits) => value || value === 0 ? value.toLocaleStri
|
|
|
807
964
|
var NumberBuilderCell = (cellContext) => {
|
|
808
965
|
const { onUpdate, digits } = cellContext.column.columnDef.meta;
|
|
809
966
|
const value = cellContext.getValue();
|
|
810
|
-
const [text, setText] =
|
|
967
|
+
const [text, setText] = useState7(displayNumber(value, digits));
|
|
811
968
|
const { findPrevFocusable } = useFocusFinders();
|
|
812
|
-
const ref =
|
|
969
|
+
const ref = useRef3(null);
|
|
813
970
|
useEffect3(() => {
|
|
814
971
|
(!document.activeElement || document.activeElement !== ref.current) && setText(displayNumber(value, digits));
|
|
815
972
|
}, [
|
|
@@ -897,7 +1054,7 @@ var ColumnBuilder = class {
|
|
|
897
1054
|
cell: model && onUpdate ? ComboboxBuilderCell : (cellContext) => {
|
|
898
1055
|
const cellValue = cellContext.getValue();
|
|
899
1056
|
return /* @__PURE__ */ React10.createElement("div", {
|
|
900
|
-
className:
|
|
1057
|
+
className: mx5("truncate", classNames)
|
|
901
1058
|
}, cellValue ? model?.getText(cellValue) : "");
|
|
902
1059
|
},
|
|
903
1060
|
...props,
|
|
@@ -928,7 +1085,7 @@ var ColumnBuilder = class {
|
|
|
928
1085
|
value = value.content;
|
|
929
1086
|
}
|
|
930
1087
|
return /* @__PURE__ */ React10.createElement("div", {
|
|
931
|
-
className:
|
|
1088
|
+
className: mx5("truncate", textPadding, classNames)
|
|
932
1089
|
}, value);
|
|
933
1090
|
},
|
|
934
1091
|
...props,
|
|
@@ -957,7 +1114,6 @@ var ColumnBuilder = class {
|
|
|
957
1114
|
onUpdate,
|
|
958
1115
|
digits,
|
|
959
1116
|
header: {
|
|
960
|
-
classNames: "text-end",
|
|
961
1117
|
...props.meta?.header
|
|
962
1118
|
},
|
|
963
1119
|
cell: {
|
|
@@ -983,7 +1139,7 @@ var ColumnBuilder = class {
|
|
|
983
1139
|
addSuffix: true
|
|
984
1140
|
}) : value.toISOString() : void 0;
|
|
985
1141
|
return /* @__PURE__ */ React10.createElement("div", {
|
|
986
|
-
className:
|
|
1142
|
+
className: mx5(textPadding, classNames)
|
|
987
1143
|
}, str);
|
|
988
1144
|
} catch (err) {
|
|
989
1145
|
log2.info("formatError", {
|
|
@@ -1110,7 +1266,7 @@ var ColumnBuilder = class {
|
|
|
1110
1266
|
*/
|
|
1111
1267
|
icon({ label, size, on, off, ...props } = {}) {
|
|
1112
1268
|
const IconOn = on?.Icon ?? Check2;
|
|
1113
|
-
const IconOff = off?.Icon ??
|
|
1269
|
+
const IconOff = off?.Icon ?? X3;
|
|
1114
1270
|
return {
|
|
1115
1271
|
size: size ?? 32,
|
|
1116
1272
|
// TODO(Zan): Implement sort algorithm
|
|
@@ -1122,11 +1278,11 @@ var ColumnBuilder = class {
|
|
|
1122
1278
|
const value = cell.getValue();
|
|
1123
1279
|
if (value) {
|
|
1124
1280
|
return /* @__PURE__ */ React10.createElement(IconOn, {
|
|
1125
|
-
className:
|
|
1281
|
+
className: mx5("block mli-auto", getSize4(6), on?.className ?? "text-green-700")
|
|
1126
1282
|
});
|
|
1127
1283
|
} else if (value === false) {
|
|
1128
1284
|
return /* @__PURE__ */ React10.createElement(IconOff, {
|
|
1129
|
-
className:
|
|
1285
|
+
className: mx5("block mli-auto", getSize4(6), off?.className ?? "text-red-700")
|
|
1130
1286
|
});
|
|
1131
1287
|
} else {
|
|
1132
1288
|
return null;
|
|
@@ -1135,13 +1291,165 @@ var ColumnBuilder = class {
|
|
|
1135
1291
|
...props
|
|
1136
1292
|
};
|
|
1137
1293
|
}
|
|
1294
|
+
/**
|
|
1295
|
+
* This display column type is for nested/unhandled data to appear as JSON.
|
|
1296
|
+
*/
|
|
1297
|
+
display({ label, classNames, ...props } = {}) {
|
|
1298
|
+
return {
|
|
1299
|
+
size: 120,
|
|
1300
|
+
minSize: 120,
|
|
1301
|
+
header: (cell) => label ?? cell.header.id,
|
|
1302
|
+
cell: (cell) => {
|
|
1303
|
+
const value = cell.getValue();
|
|
1304
|
+
return /* @__PURE__ */ React10.createElement("div", {
|
|
1305
|
+
className: "overflow-scroll"
|
|
1306
|
+
}, /* @__PURE__ */ React10.createElement("code", {
|
|
1307
|
+
className: "text-xs"
|
|
1308
|
+
}, JSON.stringify(value)));
|
|
1309
|
+
},
|
|
1310
|
+
...props,
|
|
1311
|
+
meta: {
|
|
1312
|
+
...props.meta,
|
|
1313
|
+
cell: {
|
|
1314
|
+
...props.meta?.cell,
|
|
1315
|
+
classNames: [
|
|
1316
|
+
"font-mono",
|
|
1317
|
+
textPadding,
|
|
1318
|
+
classNames
|
|
1319
|
+
]
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
};
|
|
1325
|
+
|
|
1326
|
+
// packages/ui/react-ui-table/src/schema/schema.ts
|
|
1327
|
+
import * as AST from "@effect/schema/AST";
|
|
1328
|
+
var classifySchemaProperties = (schema) => {
|
|
1329
|
+
const recurse = (node, path, acc) => {
|
|
1330
|
+
const properties = AST.getPropertySignatures(node);
|
|
1331
|
+
properties.forEach((prop) => {
|
|
1332
|
+
const propName = prop.name.toString();
|
|
1333
|
+
if (prop.isOptional) {
|
|
1334
|
+
const unwrappedAst = unwrapOptionProperty(prop);
|
|
1335
|
+
if (isStruct(unwrappedAst)) {
|
|
1336
|
+
return recurse(unwrappedAst, [
|
|
1337
|
+
...path,
|
|
1338
|
+
propName
|
|
1339
|
+
], acc);
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
if (isStruct(prop.type)) {
|
|
1343
|
+
recurse(prop.type, [
|
|
1344
|
+
...path,
|
|
1345
|
+
propName
|
|
1346
|
+
], acc);
|
|
1347
|
+
} else {
|
|
1348
|
+
acc.push([
|
|
1349
|
+
path.concat(propName).join("."),
|
|
1350
|
+
propertyToColumn(prop)
|
|
1351
|
+
]);
|
|
1352
|
+
}
|
|
1353
|
+
});
|
|
1354
|
+
return acc;
|
|
1355
|
+
};
|
|
1356
|
+
return recurse(schema.ast, [], []);
|
|
1357
|
+
};
|
|
1358
|
+
var isStruct = (node) => AST.isTypeLiteral(node);
|
|
1359
|
+
var isOptionalUnion = (prop) => AST.isUnion(prop.type) && prop.isOptional;
|
|
1360
|
+
var unwrapOptionProperty = (prop) => {
|
|
1361
|
+
if (!isOptionalUnion(prop)) {
|
|
1362
|
+
throw new Error(`Not an optional property: ${String(prop.name)}`);
|
|
1363
|
+
}
|
|
1364
|
+
if (!AST.isUnion(prop.type)) {
|
|
1365
|
+
throw new Error(`Not a union type: ${String(prop.name)}`);
|
|
1366
|
+
}
|
|
1367
|
+
const [type, _undefinedCase] = prop.type.types;
|
|
1368
|
+
return type;
|
|
1369
|
+
};
|
|
1370
|
+
var typeToColumn = (type) => {
|
|
1371
|
+
if (AST.isStringKeyword(type)) {
|
|
1372
|
+
return "string";
|
|
1373
|
+
} else if (AST.isNumberKeyword(type)) {
|
|
1374
|
+
return "number";
|
|
1375
|
+
} else if (AST.isBooleanKeyword(type)) {
|
|
1376
|
+
return "boolean";
|
|
1377
|
+
}
|
|
1378
|
+
if (AST.isRefinement(type)) {
|
|
1379
|
+
return typeToColumn(type.from);
|
|
1380
|
+
}
|
|
1381
|
+
if (AST.isTransform(type)) {
|
|
1382
|
+
const identifier = AST.getIdentifierAnnotation(type);
|
|
1383
|
+
if (identifier._tag === "Some") {
|
|
1384
|
+
if (identifier.value === "DateFromString") {
|
|
1385
|
+
return "date";
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
return "display";
|
|
1390
|
+
};
|
|
1391
|
+
var propertyToColumn = (prop) => {
|
|
1392
|
+
let type = prop.type;
|
|
1393
|
+
if (prop.isOptional) {
|
|
1394
|
+
type = unwrapOptionProperty(prop);
|
|
1395
|
+
}
|
|
1396
|
+
return typeToColumn(type);
|
|
1397
|
+
};
|
|
1398
|
+
|
|
1399
|
+
// packages/ui/react-ui-table/src/schema/schemaToColumns.ts
|
|
1400
|
+
var schemaToColumnDefs = (schema) => {
|
|
1401
|
+
const { helper, builder } = createColumnBuilder();
|
|
1402
|
+
const classified = classifySchemaProperties(schema);
|
|
1403
|
+
return classified.map(([name, type]) => {
|
|
1404
|
+
const propertyKey = name.toString();
|
|
1405
|
+
let column;
|
|
1406
|
+
switch (type) {
|
|
1407
|
+
case "string": {
|
|
1408
|
+
column = builder.string({
|
|
1409
|
+
label: propertyKey
|
|
1410
|
+
});
|
|
1411
|
+
break;
|
|
1412
|
+
}
|
|
1413
|
+
case "number": {
|
|
1414
|
+
column = builder.number({
|
|
1415
|
+
label: propertyKey
|
|
1416
|
+
});
|
|
1417
|
+
break;
|
|
1418
|
+
}
|
|
1419
|
+
case "boolean": {
|
|
1420
|
+
column = builder.switch({
|
|
1421
|
+
label: propertyKey
|
|
1422
|
+
});
|
|
1423
|
+
break;
|
|
1424
|
+
}
|
|
1425
|
+
case "date": {
|
|
1426
|
+
column = builder.date({
|
|
1427
|
+
label: propertyKey
|
|
1428
|
+
});
|
|
1429
|
+
break;
|
|
1430
|
+
}
|
|
1431
|
+
case "display": {
|
|
1432
|
+
column = builder.display({
|
|
1433
|
+
label: propertyKey,
|
|
1434
|
+
id: propertyKey
|
|
1435
|
+
});
|
|
1436
|
+
break;
|
|
1437
|
+
}
|
|
1438
|
+
default: {
|
|
1439
|
+
throw new Error(`Unhandled column type: ${type}`);
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
return helper.accessor(propertyKey, column);
|
|
1443
|
+
});
|
|
1138
1444
|
};
|
|
1139
1445
|
export {
|
|
1140
1446
|
CellCombobox,
|
|
1141
1447
|
ColumnBuilder,
|
|
1142
1448
|
ColumnMenu,
|
|
1143
|
-
|
|
1449
|
+
ColumnSettingsForm,
|
|
1450
|
+
ColumnSettingsPanel,
|
|
1144
1451
|
MemoizedVirtualisedTableContent,
|
|
1452
|
+
SortIndicator,
|
|
1145
1453
|
Table,
|
|
1146
1454
|
createColumnBuilder,
|
|
1147
1455
|
currentRow,
|
|
@@ -1149,6 +1457,7 @@ export {
|
|
|
1149
1457
|
gridCellFocusRing,
|
|
1150
1458
|
groupTh,
|
|
1151
1459
|
headPadding,
|
|
1460
|
+
schemaToColumnDefs,
|
|
1152
1461
|
selectedRow,
|
|
1153
1462
|
tableRoot,
|
|
1154
1463
|
tbodyRoot,
|
|
@@ -1163,6 +1472,8 @@ export {
|
|
|
1163
1472
|
theadRoot,
|
|
1164
1473
|
theadTh,
|
|
1165
1474
|
theadTr,
|
|
1166
|
-
translations_default as translations
|
|
1475
|
+
translations_default as translations,
|
|
1476
|
+
useColumnSorting,
|
|
1477
|
+
usePinLastRow
|
|
1167
1478
|
};
|
|
1168
1479
|
//# sourceMappingURL=index.mjs.map
|