@x-tech-laboratories/x-libs 0.4.0 → 0.7.0
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/README.md +89 -13
- package/dist/backups.d.ts +31 -0
- package/dist/backups.js +43 -0
- package/dist/dates.d.ts +9 -0
- package/dist/dates.js +60 -0
- package/dist/durations.d.ts +9 -1
- package/dist/durations.js +19 -5
- package/dist/electron/app.d.ts +13 -0
- package/dist/electron/app.js +27 -0
- package/dist/electron/bridge.d.ts +32 -0
- package/dist/electron/bridge.js +53 -0
- package/dist/electron/events.d.ts +21 -0
- package/dist/electron/events.js +25 -0
- package/dist/electron/fetch.d.ts +25 -0
- package/dist/electron/fetch.js +67 -0
- package/dist/electron/window.d.ts +96 -0
- package/dist/electron/window.js +128 -0
- package/dist/log.d.ts +30 -0
- package/dist/log.js +79 -0
- package/dist/server/backup_files.d.ts +3 -0
- package/dist/server/backup_files.js +25 -0
- package/dist/web/drag.d.ts +3 -0
- package/dist/web/drag.js +13 -0
- package/dist/web/format.d.ts +1 -0
- package/dist/web/format.js +5 -0
- package/dist/web/menus.d.ts +4 -0
- package/dist/web/menus.js +28 -1
- package/dist/web/prefs.d.ts +12 -0
- package/dist/web/prefs.js +62 -0
- package/dist/web/{preact → react}/badges.d.ts +9 -9
- package/dist/web/{preact → react}/badges.js +6 -6
- package/dist/web/react/controls.d.ts +72 -0
- package/dist/web/react/controls.js +88 -0
- package/dist/web/{preact → react}/dialog.d.ts +10 -10
- package/dist/web/{preact → react}/dialog.js +14 -9
- package/dist/web/react/layout.d.ts +100 -0
- package/dist/web/react/layout.js +80 -0
- package/dist/web/react/menus.d.ts +31 -0
- package/dist/web/react/menus.js +159 -0
- package/dist/web/react/prefs.d.ts +2 -0
- package/dist/web/react/prefs.js +11 -0
- package/dist/web/react/reveal.d.ts +9 -0
- package/dist/web/react/reveal.js +30 -0
- package/dist/web/react/shell.d.ts +41 -0
- package/dist/web/react/shell.js +90 -0
- package/dist/web/react/shortcuts.d.ts +23 -0
- package/dist/web/react/shortcuts.js +95 -0
- package/dist/web/{preact → react}/split.d.ts +4 -4
- package/dist/web/{preact → react}/split.js +9 -10
- package/dist/web/{preact → react}/states.d.ts +7 -7
- package/dist/web/{preact → react}/states.js +6 -5
- package/dist/web/react/table.d.ts +69 -0
- package/dist/web/react/table.js +278 -0
- package/dist/web/{preact → react}/time.d.ts +2 -1
- package/dist/web/react/time.js +19 -0
- package/dist/web/react/toasts.d.ts +29 -0
- package/dist/web/react/toasts.js +72 -0
- package/dist/web/react/tree.d.ts +28 -0
- package/dist/web/react/tree.js +183 -0
- package/dist/web/react/watch.d.ts +3 -0
- package/dist/web/react/watch.js +5 -0
- package/dist/web/selection.d.ts +25 -0
- package/dist/web/selection.js +106 -0
- package/dist/web/tables.d.ts +19 -1
- package/dist/web/tables.js +78 -8
- package/dist/web/theme.d.ts +6 -1
- package/dist/web/theme.js +31 -21
- package/dist/web/tree.d.ts +37 -0
- package/dist/web/tree.js +128 -0
- package/dist/web/virtual.d.ts +7 -0
- package/dist/web/virtual.js +10 -0
- package/dist/web/watch.d.ts +6 -0
- package/dist/web/watch.js +17 -0
- package/package.json +15 -4
- package/dist/web/preact/controls.d.ts +0 -37
- package/dist/web/preact/controls.js +0 -43
- package/dist/web/preact/layout.d.ts +0 -80
- package/dist/web/preact/layout.js +0 -71
- package/dist/web/preact/menus.d.ts +0 -19
- package/dist/web/preact/menus.js +0 -70
- package/dist/web/preact/shell.d.ts +0 -27
- package/dist/web/preact/shell.js +0 -63
- package/dist/web/preact/table.d.ts +0 -23
- package/dist/web/preact/table.js +0 -20
- package/dist/web/preact/time.js +0 -9
- package/dist/web/preact/toasts.d.ts +0 -15
- package/dist/web/preact/toasts.js +0 -34
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// A React table drawn like the page's own on TanStack Table: sorting by one column or several, columns the user moves, resizes,
|
|
3
|
+
// hides and filters, rows nested under rows, rows in groups under headings, rows dragged by the app's rules, and cards on phones.
|
|
4
|
+
import { Fragment, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { getCoreRowModel, getExpandedRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
|
|
6
|
+
import { clamp_width, column_id, compare_values, move_column, ordered_columns, sort_after_click, sorting_list } from "../tables.js";
|
|
7
|
+
import { placement_at } from "../tree.js";
|
|
8
|
+
import { ContextMenu, Popover } from "./menus.js";
|
|
9
|
+
import { ResizeHandle } from "./split.js";
|
|
10
|
+
const is_empty = (value) => value === null || value === undefined || value === "";
|
|
11
|
+
// The rows that pass and, in a tree, those above a row that passes, with each row's passing children.
|
|
12
|
+
function filtered_tree(rows, passes, get_children, kept_children) {
|
|
13
|
+
return rows.filter((row) => {
|
|
14
|
+
const children = get_children ? filtered_tree(get_children(row) ?? [], passes, get_children, kept_children) : [];
|
|
15
|
+
kept_children.set(row, children);
|
|
16
|
+
return passes(row) || children.length > 0;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
// ── Table ────────────────────────────────────────────────────────────────────
|
|
20
|
+
export function DataTable(props) {
|
|
21
|
+
const { columns, row_key, caption, get_children, row_passes, groups, allow_inside_drop = true } = props;
|
|
22
|
+
const rows = useMemo(() => groups ? groups.flatMap((group) => group.rows) : props.rows, [groups, props.rows]);
|
|
23
|
+
const [own_expanded, set_own_expanded] = useState(true);
|
|
24
|
+
const [open_filter, set_open_filter] = useState(null);
|
|
25
|
+
const filter_closed = useRef({ id: "", at: 0 });
|
|
26
|
+
const [columns_menu, set_columns_menu] = useState(null);
|
|
27
|
+
const [dragged, set_dragged] = useState(null);
|
|
28
|
+
const [drop_target, set_drop_target] = useState(null);
|
|
29
|
+
const resizing = useRef(false);
|
|
30
|
+
const header_cells = useRef(new Map());
|
|
31
|
+
const [measured, set_measured] = useState({});
|
|
32
|
+
const [row_dragging, set_row_dragging] = useState(false);
|
|
33
|
+
const [row_drop, set_row_drop] = useState(null);
|
|
34
|
+
const by_id = useMemo(() => new Map(columns.map((column) => [column_id(column), column])), [columns]);
|
|
35
|
+
const all_ids = columns.map(column_id);
|
|
36
|
+
const manual = props.manual_sorting === true;
|
|
37
|
+
const is_sortable = (column) => Boolean(column) && (manual ? column.sortable !== false : Boolean(column.sort));
|
|
38
|
+
// Rows that come sorted keep every key, even one naming no column, so a click never drops it.
|
|
39
|
+
const sorting = manual ? sorting_list(props.sorting) : sorting_list(props.sorting).filter((key) => is_sortable(by_id.get(key.key)));
|
|
40
|
+
const hidden = props.hidden_columns ?? [];
|
|
41
|
+
const widths = props.column_widths ?? {};
|
|
42
|
+
const expanded = props.expanded ?? own_expanded;
|
|
43
|
+
const tree = get_children !== undefined;
|
|
44
|
+
// ── Rows ──
|
|
45
|
+
const { data, children_of } = useMemo(() => {
|
|
46
|
+
if (!row_passes)
|
|
47
|
+
return { data: rows, children_of: get_children };
|
|
48
|
+
const kept_children = new Map();
|
|
49
|
+
const kept = filtered_tree(rows, row_passes, get_children, kept_children);
|
|
50
|
+
return { data: kept, children_of: get_children && ((row) => kept_children.get(row) ?? []) };
|
|
51
|
+
}, [rows, row_passes, get_children]);
|
|
52
|
+
// TanStack flips a descending column's order, so an empty value is flipped first to stay last.
|
|
53
|
+
const descending = useRef(new Set());
|
|
54
|
+
descending.current = new Set(sorting.filter((key) => key.descending).map((key) => key.key));
|
|
55
|
+
const definitions = useMemo(() => columns.map((column) => ({
|
|
56
|
+
id: column_id(column),
|
|
57
|
+
accessorFn: column.sort,
|
|
58
|
+
enableSorting: Boolean(column.sort),
|
|
59
|
+
sortingFn: (left, right, id) => {
|
|
60
|
+
const [first, second] = [left.getValue(id), right.getValue(id)];
|
|
61
|
+
const order = compare_values(first, second);
|
|
62
|
+
return (is_empty(first) || is_empty(second)) && descending.current.has(id) ? -order : order;
|
|
63
|
+
},
|
|
64
|
+
})), [columns]);
|
|
65
|
+
const table = useReactTable({
|
|
66
|
+
data,
|
|
67
|
+
columns: definitions,
|
|
68
|
+
getRowId: row_key ? (row) => String(row_key(row)) : undefined,
|
|
69
|
+
getSubRows: children_of ? (row) => children_of(row) ?? [] : undefined,
|
|
70
|
+
state: {
|
|
71
|
+
sorting: sorting.filter((key) => by_id.has(key.key)).map((key) => ({ id: key.key, desc: key.descending })),
|
|
72
|
+
columnOrder: ordered_columns(props.column_order ?? all_ids, all_ids),
|
|
73
|
+
columnVisibility: Object.fromEntries(hidden.map((id) => [id, false])),
|
|
74
|
+
expanded: expanded === true ? true : Object.fromEntries(expanded.map((id) => [id, true])),
|
|
75
|
+
},
|
|
76
|
+
getCoreRowModel: getCoreRowModel(),
|
|
77
|
+
getSortedRowModel: getSortedRowModel(),
|
|
78
|
+
getExpandedRowModel: getExpandedRowModel(),
|
|
79
|
+
getRowCanExpand: (row) => row.subRows.length > 0,
|
|
80
|
+
manualSorting: manual,
|
|
81
|
+
});
|
|
82
|
+
const shown = table.getVisibleLeafColumns().map((column) => by_id.get(column.id));
|
|
83
|
+
function toggle_row(row) {
|
|
84
|
+
const open = expanded === true
|
|
85
|
+
? table.getCoreRowModel().flatRows.filter((each) => each.subRows.length > 0).map((each) => each.id)
|
|
86
|
+
: expanded;
|
|
87
|
+
const next = row.getIsExpanded() ? open.filter((id) => id !== row.id) : [...open, row.id];
|
|
88
|
+
if (props.expanded === undefined)
|
|
89
|
+
set_own_expanded(next);
|
|
90
|
+
props.on_expanded_change?.(next);
|
|
91
|
+
}
|
|
92
|
+
// ── Sorting ──
|
|
93
|
+
function sort_by(id, adding) {
|
|
94
|
+
if (props.on_sorting_change)
|
|
95
|
+
return props.on_sorting_change(sort_after_click(sorting, id, adding));
|
|
96
|
+
const current = sorting.find((key) => key.key === id);
|
|
97
|
+
props.on_sort?.({ key: id, descending: current ? !current.descending : false });
|
|
98
|
+
}
|
|
99
|
+
// ── Widths ──
|
|
100
|
+
const width_of = (column) => widths[column_id(column)] ?? column.width;
|
|
101
|
+
// A column never sized is measured, so the first drag of its edge starts from where it is.
|
|
102
|
+
useLayoutEffect(() => {
|
|
103
|
+
if (!props.on_column_widths_change)
|
|
104
|
+
return;
|
|
105
|
+
const sizes = Object.fromEntries([...header_cells.current].map(([id, cell]) => [id, cell.offsetWidth]));
|
|
106
|
+
set_measured((before) => JSON.stringify(before) === JSON.stringify(sizes) ? before : sizes);
|
|
107
|
+
}, [shown.map(column_id).join("\n"), props.on_column_widths_change]);
|
|
108
|
+
function resize(column, width, done) {
|
|
109
|
+
props.on_column_widths_change?.({ ...widths, [column_id(column)]: width }, done);
|
|
110
|
+
}
|
|
111
|
+
// ── Moving ──
|
|
112
|
+
const can_move = (column) => Boolean(props.on_column_order_change) && column.movable !== false;
|
|
113
|
+
const order = () => table.getState().columnOrder;
|
|
114
|
+
function move(id, target, after) {
|
|
115
|
+
if (id !== target)
|
|
116
|
+
props.on_column_order_change?.(move_column(order(), id, target, after));
|
|
117
|
+
}
|
|
118
|
+
// A column dropped on the left half of another goes before it, and on the right half after it.
|
|
119
|
+
function drag_over(column, event) {
|
|
120
|
+
if (!dragged || !can_move(column))
|
|
121
|
+
return;
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
const cell = event.currentTarget.getBoundingClientRect();
|
|
124
|
+
set_drop_target({ id: column_id(column), after: event.clientX > cell.left + cell.width / 2 });
|
|
125
|
+
}
|
|
126
|
+
function drop(event) {
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
if (dragged && drop_target)
|
|
129
|
+
move(dragged, drop_target.id, drop_target.after);
|
|
130
|
+
set_dragged(null);
|
|
131
|
+
set_drop_target(null);
|
|
132
|
+
}
|
|
133
|
+
// Alt with an arrow moves the column one place along, past any hidden ones.
|
|
134
|
+
function move_by_key(column, event) {
|
|
135
|
+
if (!event.altKey || !can_move(column) || (event.key !== "ArrowLeft" && event.key !== "ArrowRight"))
|
|
136
|
+
return;
|
|
137
|
+
event.preventDefault();
|
|
138
|
+
const ids = shown.map(column_id);
|
|
139
|
+
const index = ids.indexOf(column_id(column));
|
|
140
|
+
const target = ids[index + (event.key === "ArrowLeft" ? -1 : 1)];
|
|
141
|
+
if (target && by_id.get(target)?.movable !== false)
|
|
142
|
+
move(column_id(column), target, event.key === "ArrowRight");
|
|
143
|
+
}
|
|
144
|
+
// ── Filters ──
|
|
145
|
+
function toggle_filter(id, anchor) {
|
|
146
|
+
// The click that closed the popover by landing outside it is the same one that reaches its button.
|
|
147
|
+
const just_closed = filter_closed.current.id === id && Date.now() - filter_closed.current.at < 300;
|
|
148
|
+
set_open_filter(open_filter?.id === id || just_closed ? null : { id, anchor });
|
|
149
|
+
}
|
|
150
|
+
function close_filter() {
|
|
151
|
+
if (open_filter)
|
|
152
|
+
filter_closed.current = { id: open_filter.id, at: Date.now() };
|
|
153
|
+
set_open_filter(null);
|
|
154
|
+
}
|
|
155
|
+
const any_filter = columns.some((column) => column.filter_active);
|
|
156
|
+
// ── Hiding ──
|
|
157
|
+
function open_columns_menu(event) {
|
|
158
|
+
if (!props.on_hidden_columns_change)
|
|
159
|
+
return;
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
if (event.type === "contextmenu")
|
|
162
|
+
return set_columns_menu({ x: event.clientX, y: event.clientY });
|
|
163
|
+
const button = event.currentTarget.getBoundingClientRect();
|
|
164
|
+
set_columns_menu({ x: button.left, y: button.bottom + 4 });
|
|
165
|
+
}
|
|
166
|
+
const column_choices = columns.map((column) => {
|
|
167
|
+
const id = column_id(column);
|
|
168
|
+
const visible = !hidden.includes(id);
|
|
169
|
+
// The last column on show stays, so the table never empties.
|
|
170
|
+
const fixed = column.hideable === false || (visible && shown.length === 1);
|
|
171
|
+
return { label: column.label, checked: visible, disabled: fixed, keep_open: true, run: () => props.on_hidden_columns_change(visible ? [...hidden, id] : hidden.filter((each) => each !== id)) };
|
|
172
|
+
});
|
|
173
|
+
// ── Dragging rows ──
|
|
174
|
+
// A drag started in this table lands anywhere, and any drag lands where the app's rule allows it.
|
|
175
|
+
function row_placement(row, event) {
|
|
176
|
+
if (!props.on_row_drop)
|
|
177
|
+
return null;
|
|
178
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
179
|
+
const placement = placement_at(box.height > 0 ? (event.clientY - box.top) / box.height : 0.5, allow_inside_drop);
|
|
180
|
+
const allowed = props.can_drop_on_row ? props.can_drop_on_row(row.original, placement) : row_dragging;
|
|
181
|
+
return allowed ? placement : null;
|
|
182
|
+
}
|
|
183
|
+
function row_drag_start(row, event) {
|
|
184
|
+
set_row_dragging(true);
|
|
185
|
+
props.on_row_drag_start(row.original, event);
|
|
186
|
+
// Some browsers start a drag only once it carries data.
|
|
187
|
+
if (event.dataTransfer && event.dataTransfer.types.length === 0)
|
|
188
|
+
event.dataTransfer.setData("text/plain", row.id);
|
|
189
|
+
}
|
|
190
|
+
function row_drag_over(row, event) {
|
|
191
|
+
const placement = row_placement(row, event);
|
|
192
|
+
if (!placement) {
|
|
193
|
+
if (row_drop?.id === row.id)
|
|
194
|
+
set_row_drop(null);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
event.preventDefault();
|
|
198
|
+
if (row_drop?.id !== row.id || row_drop.placement !== placement)
|
|
199
|
+
set_row_drop({ id: row.id, placement });
|
|
200
|
+
}
|
|
201
|
+
function row_drag_drop(row, event) {
|
|
202
|
+
const placement = row_placement(row, event);
|
|
203
|
+
set_row_drop(null);
|
|
204
|
+
if (!placement)
|
|
205
|
+
return;
|
|
206
|
+
event.preventDefault();
|
|
207
|
+
props.on_row_drop(row.original, placement, event);
|
|
208
|
+
}
|
|
209
|
+
function row_drag_end() {
|
|
210
|
+
set_row_dragging(false);
|
|
211
|
+
set_row_drop(null);
|
|
212
|
+
props.on_row_drag_end?.();
|
|
213
|
+
}
|
|
214
|
+
// ── Drawing ──
|
|
215
|
+
function header(column) {
|
|
216
|
+
const id = column_id(column);
|
|
217
|
+
const index = sorting.findIndex((key) => key.key === id);
|
|
218
|
+
const key = sorting[index];
|
|
219
|
+
const sortable = is_sortable(column) && Boolean(props.on_sort || props.on_sorting_change);
|
|
220
|
+
const width = width_of(column);
|
|
221
|
+
const movable = can_move(column);
|
|
222
|
+
const class_name = [
|
|
223
|
+
column.class, column.filter_active && "filtered", dragged === id && "dragged", drop_target?.id === id && (drop_target.after ? "drop-after" : "drop-before"),
|
|
224
|
+
].filter(Boolean).join(" ") || undefined;
|
|
225
|
+
const marker = key && (_jsxs("span", { className: "sort-marker", "aria-hidden": "true", children: [key.descending ? " ↓" : " ↑", sorting.length > 1 && _jsx("sup", { className: "sort-rank", children: index + 1 })] }));
|
|
226
|
+
return (_jsxs("th", { ref: (cell) => { if (cell)
|
|
227
|
+
header_cells.current.set(id, cell);
|
|
228
|
+
else
|
|
229
|
+
header_cells.current.delete(id); }, className: class_name, scope: "col", style: width === undefined ? undefined : { width, minWidth: width, maxWidth: width }, "aria-sort": sortable ? (key ? (key.descending ? "descending" : "ascending") : "none") : undefined, draggable: movable || undefined, title: movable ? "Drag to move this column" : undefined, onPointerDownCapture: (event) => { resizing.current = event.target.classList.contains("resize-handle"); }, onDragStart: (event) => {
|
|
230
|
+
if (resizing.current)
|
|
231
|
+
return event.preventDefault();
|
|
232
|
+
event.dataTransfer.setData("text/plain", id);
|
|
233
|
+
set_dragged(id);
|
|
234
|
+
}, onDragEnd: () => { set_dragged(null); set_drop_target(null); }, onDragOver: (event) => drag_over(column, event), onDragLeave: () => set_drop_target(null), onDrop: drop, children: [sortable ? (_jsxs("button", { type: "button", className: "sort", title: props.on_sorting_change ? "Click to sort by this column, Shift+click to add it to the sort" : undefined, onClick: (event) => sort_by(id, event.shiftKey), onKeyDown: (event) => move_by_key(column, event), children: [column.label, marker] })) : movable ? (_jsx("span", { tabIndex: 0, onKeyDown: (event) => move_by_key(column, event), children: column.label })) : column.label, column.filter !== undefined && (_jsx("button", { type: "button", className: column.filter_active ? "icon filter-button active" : "icon filter-button", "aria-label": `Filter by ${column.label}`, "aria-expanded": open_filter?.id === id, title: column.filter_active ? `Filtered by ${column.label}` : `Filter by ${column.label}`, onClick: (event) => toggle_filter(id, event.currentTarget), children: _jsx("svg", { viewBox: "0 0 16 16", width: "12", height: "12", "aria-hidden": "true", children: _jsx("path", { d: "M2 3h12l-4.5 5.5V13l-3 1.5v-6z", fill: "currentColor" }) }) })), props.on_column_widths_change && (_jsx(ResizeHandle, { side: "left", size: width ?? measured[id] ?? column.min_width ?? 48, min: column.min_width ?? 48, max: column.max_width ?? 960, default_size: clamp_width(column.width ?? measured[id] ?? 120, column.min_width, column.max_width), on_resize: (size) => resize(column, size, false), on_resize_end: (size) => resize(column, size, true), label: `Resize the ${column.label} column`, class_name: "column-resize" }))] }, id));
|
|
235
|
+
}
|
|
236
|
+
function body_row(row) {
|
|
237
|
+
const original = row.original;
|
|
238
|
+
const row_class = [props.row_class?.(original), row_drop?.id === row.id && `drop-${row_drop.placement}`].filter(Boolean).join(" ") || undefined;
|
|
239
|
+
const after = props.render_after_row?.(original);
|
|
240
|
+
const draggable = Boolean(props.on_row_drag_start);
|
|
241
|
+
const keyed = props.on_row_key_down !== undefined;
|
|
242
|
+
const key = row_key ? String(row_key(original)) : row.id;
|
|
243
|
+
return (_jsxs(Fragment, { children: [_jsx("tr", { className: row_class, title: props.row_title?.(original), style: props.row_style?.(original), "data-row-key": keyed ? key : undefined, tabIndex: keyed ? (props.active_row !== undefined && String(props.active_row) === key ? 0 : -1) : undefined, "aria-selected": props.row_selected ? props.row_selected(original) : undefined, draggable: draggable || undefined, onDragStart: draggable ? (event) => row_drag_start(row, event) : undefined, onDragEnd: draggable ? row_drag_end : undefined, onDragOver: props.on_row_drop && ((event) => row_drag_over(row, event)), onDragLeave: props.on_row_drop && (() => { if (row_drop?.id === row.id)
|
|
244
|
+
set_row_drop(null); }), onDrop: props.on_row_drop && ((event) => row_drag_drop(row, event)), onClick: props.on_row_click && ((event) => props.on_row_click(original, event)), onDoubleClick: props.on_row_double_click && ((event) => props.on_row_double_click(original, event)), onKeyDown: props.on_row_key_down && ((event) => props.on_row_key_down(original, event)), onContextMenu: props.on_row_context_menu && ((event) => props.on_row_context_menu(original, event)), children: shown.map((column, index) => {
|
|
245
|
+
const label = column.label;
|
|
246
|
+
if (!tree || index > 0)
|
|
247
|
+
return _jsx("td", { className: column.class, "data-label": label, children: column.cell(original) }, column_id(column));
|
|
248
|
+
const open = row.getIsExpanded();
|
|
249
|
+
const count = row.subRows.length;
|
|
250
|
+
return (_jsxs("td", { className: [column.class, "tree-cell"].filter(Boolean).join(" "), "data-label": label, style: { "--tree-depth": row.depth }, children: [count > 0 ? (_jsx("button", { type: "button", className: "icon tree-toggle", "aria-expanded": open, "aria-label": open ? "Collapse" : "Expand", onClick: (event) => { event.stopPropagation(); toggle_row(row); }, children: open ? "▾" : "▸" })) : _jsx("span", { className: "tree-spacer" }), column.cell(original), count > 0 && !open && _jsx("span", { className: "tree-count", title: `${count} inside`, children: count })] }, column_id(column)));
|
|
251
|
+
}) }), after !== undefined && after !== null && typeof after !== "boolean" && _jsx("tr", { className: "row-extra", children: _jsx("td", { colSpan: shown.length, children: after }) })] }, row.id));
|
|
252
|
+
}
|
|
253
|
+
// Each group's heading and then its rows, which keep the order of the sorted whole, so each group is sorted on its own.
|
|
254
|
+
function grouped_body(groups) {
|
|
255
|
+
const group_of = new Map();
|
|
256
|
+
groups.forEach((group, index) => group.rows.forEach((row) => { if (!group_of.has(row))
|
|
257
|
+
group_of.set(row, index); }));
|
|
258
|
+
const rows_by_group = groups.map(() => []);
|
|
259
|
+
let current = 0;
|
|
260
|
+
for (const row of table.getRowModel().rows) {
|
|
261
|
+
if (row.depth === 0)
|
|
262
|
+
current = group_of.get(row.original) ?? current;
|
|
263
|
+
rows_by_group[current].push(row);
|
|
264
|
+
}
|
|
265
|
+
return groups.map((group, index) => (_jsxs(Fragment, { children: [_jsx("tr", { className: group.class_name ? `group-row ${group.class_name}` : "group-row", children: _jsx("th", { scope: "colgroup", colSpan: shown.length, children: group.label }) }), rows_by_group[index].map(body_row)] }, group.key)));
|
|
266
|
+
}
|
|
267
|
+
const filtered_column = open_filter ? by_id.get(open_filter.id) : undefined;
|
|
268
|
+
const filter_body = filtered_column?.filter;
|
|
269
|
+
const tools = (props.on_clear_filters && any_filter) || props.on_hidden_columns_change;
|
|
270
|
+
return (_jsxs(_Fragment, { children: [tools && (_jsxs("div", { className: "table-tools", children: [props.on_clear_filters && any_filter && _jsx("button", { type: "button", onClick: props.on_clear_filters, children: "Clear filters" }), props.on_hidden_columns_change && _jsx("button", { type: "button", "aria-haspopup": "menu", onClick: open_columns_menu, children: "Columns" })] })), _jsx("div", { className: "table-wrap", children: _jsxs("table", { className: "responsive", children: [caption && _jsx("caption", { className: "visually-hidden", children: caption }), _jsx("thead", { onContextMenu: props.on_hidden_columns_change && open_columns_menu, children: _jsx("tr", { children: shown.map(header) }) }), _jsx("tbody", { children: groups ? grouped_body(groups) : table.getRowModel().rows.map(body_row) })] }) }), open_filter && filtered_column && filter_body !== undefined && (_jsx(Popover, { anchor: open_filter.anchor, label: `Filter by ${filtered_column.label}`, on_close: close_filter, children: typeof filter_body === "function" ? filter_body(close_filter) : filter_body })), columns_menu && _jsx(ContextMenu, { x: columns_menu.x, y: columns_menu.y, label: "Columns", items: column_choices, on_close: () => set_columns_menu(null) })] }));
|
|
271
|
+
}
|
|
272
|
+
// ── Pages ────────────────────────────────────────────────────────────────────
|
|
273
|
+
// Newer and older buttons around the page number, or nothing when everything fits on one page.
|
|
274
|
+
export function Pager({ page, has_more, go }) {
|
|
275
|
+
if (page === 1 && !has_more)
|
|
276
|
+
return null;
|
|
277
|
+
return (_jsxs("nav", { className: "pager", "aria-label": "Pages", children: [_jsx("button", { disabled: page <= 1, onClick: () => go(page - 1), children: "\u2190 Newer" }), _jsxs("span", { className: "muted", children: ["Page ", page] }), _jsx("button", { disabled: !has_more, onClick: () => go(page + 1), children: "Older \u2192" })] }));
|
|
278
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// Times as the page shows them: how long ago, with the full date and time on hover, and the current time kept fresh.
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { age, stamp } from "../format.js";
|
|
5
|
+
// A time as its age, such as "3h ago", or the missing text, a dash unless told otherwise, when there is none.
|
|
6
|
+
export function Age({ epoch, missing = "—" }) {
|
|
7
|
+
if (!epoch)
|
|
8
|
+
return _jsx(_Fragment, { children: missing });
|
|
9
|
+
return _jsx("span", { title: stamp(epoch), children: age(epoch) });
|
|
10
|
+
}
|
|
11
|
+
// The current time, read again every interval, a minute unless told otherwise, so a page notices the day turning.
|
|
12
|
+
export function use_now(interval_in_milliseconds = 60_000) {
|
|
13
|
+
const [now, set_now] = useState(() => new Date());
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const timer = setInterval(() => set_now(new Date()), interval_in_milliseconds);
|
|
16
|
+
return () => clearInterval(timer);
|
|
17
|
+
}, [interval_in_milliseconds]);
|
|
18
|
+
return now;
|
|
19
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface ToastOptions {
|
|
2
|
+
tone?: "good" | "bad" | "warn" | "info";
|
|
3
|
+
link?: {
|
|
4
|
+
href: string;
|
|
5
|
+
text: string;
|
|
6
|
+
} | null;
|
|
7
|
+
action?: {
|
|
8
|
+
text: string;
|
|
9
|
+
run: () => void;
|
|
10
|
+
};
|
|
11
|
+
sticky?: boolean;
|
|
12
|
+
duration_in_milliseconds?: number;
|
|
13
|
+
on_close?: (reason: ToastCloseReason) => void;
|
|
14
|
+
}
|
|
15
|
+
export type ToastCloseReason = "timeout" | "dismissed" | "action" | "closed";
|
|
16
|
+
export declare function toast(message: string, options?: ToastOptions): () => void;
|
|
17
|
+
export interface UndoableOptions {
|
|
18
|
+
commit: () => void;
|
|
19
|
+
undo: () => void;
|
|
20
|
+
duration_in_milliseconds?: number;
|
|
21
|
+
undo_label?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface Undoable {
|
|
24
|
+
finish: () => void;
|
|
25
|
+
undo: () => void;
|
|
26
|
+
readonly settled: boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare function undoable(message: string, { commit, undo, duration_in_milliseconds, undo_label }: UndoableOptions): Undoable;
|
|
29
|
+
export declare function Toasts(): import("react").JSX.Element;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Short notes in the page's corner after something happened, with an optional link or action such as Undo.
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
let shown = [];
|
|
5
|
+
let next_id = 1;
|
|
6
|
+
const listeners = new Set();
|
|
7
|
+
function publish(toasts) {
|
|
8
|
+
shown = toasts;
|
|
9
|
+
for (const listener of listeners)
|
|
10
|
+
listener(shown);
|
|
11
|
+
}
|
|
12
|
+
// Takes the toast away and tells its owner why, once only.
|
|
13
|
+
function close_toast(id, reason) {
|
|
14
|
+
const item = shown.find((each) => each.id === id);
|
|
15
|
+
if (!item)
|
|
16
|
+
return;
|
|
17
|
+
publish(shown.filter((each) => each.id !== id));
|
|
18
|
+
item.on_close?.(reason);
|
|
19
|
+
}
|
|
20
|
+
// Shows the message and returns a function that closes it early.
|
|
21
|
+
export function toast(message, options = {}) {
|
|
22
|
+
const id = next_id++;
|
|
23
|
+
publish([...shown, { ...options, id, message }]);
|
|
24
|
+
if (!(options.sticky ?? options.tone === "bad"))
|
|
25
|
+
setTimeout(() => close_toast(id, "timeout"), options.duration_in_milliseconds ?? 6000);
|
|
26
|
+
return () => close_toast(id, "closed");
|
|
27
|
+
}
|
|
28
|
+
// Shows the message with an Undo button, then either undoes or commits the action, exactly once.
|
|
29
|
+
export function undoable(message, { commit, undo, duration_in_milliseconds = 8000, undo_label = "Undo" }) {
|
|
30
|
+
let settled = false;
|
|
31
|
+
let undo_wanted = false;
|
|
32
|
+
const settle = (reason) => {
|
|
33
|
+
if (settled)
|
|
34
|
+
return;
|
|
35
|
+
settled = true;
|
|
36
|
+
if (reason === "action" || undo_wanted)
|
|
37
|
+
undo();
|
|
38
|
+
else
|
|
39
|
+
commit();
|
|
40
|
+
};
|
|
41
|
+
const close = toast(message, {
|
|
42
|
+
action: { text: undo_label, run: () => { } },
|
|
43
|
+
duration_in_milliseconds,
|
|
44
|
+
on_close: settle,
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
finish: () => close(),
|
|
48
|
+
undo: () => {
|
|
49
|
+
if (settled)
|
|
50
|
+
return;
|
|
51
|
+
undo_wanted = true;
|
|
52
|
+
close();
|
|
53
|
+
},
|
|
54
|
+
get settled() {
|
|
55
|
+
return settled;
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// ── Host ─────────────────────────────────────────────────────────────────────
|
|
60
|
+
// Where toasts stack; the Shell holds one, and a page without the Shell renders its own.
|
|
61
|
+
export function Toasts() {
|
|
62
|
+
const [toasts, set_toasts] = useState(shown);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
listeners.add(set_toasts);
|
|
65
|
+
return () => void listeners.delete(set_toasts);
|
|
66
|
+
}, []);
|
|
67
|
+
return (_jsx("div", { id: "toasts", className: "toasts", children: toasts.map((item) => {
|
|
68
|
+
const tone = item.tone ?? "info";
|
|
69
|
+
const close = () => close_toast(item.id, "dismissed");
|
|
70
|
+
return (_jsxs("div", { className: `toast tone-${tone}`, role: tone === "bad" ? "alert" : "status", children: [_jsx("span", { children: item.message }), item.link && _jsx("a", { href: item.link.href, onClick: close, children: item.link.text }), item.action && _jsx("button", { className: "toast-action", onClick: () => { close_toast(item.id, "action"); item.action.run(); }, children: item.action.text }), _jsx("button", { className: "icon", "aria-label": "Dismiss", onClick: close, children: "\u00D7" })] }, item.id));
|
|
71
|
+
}) }));
|
|
72
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type DragEvent, type MouseEvent, type ReactNode } from "react";
|
|
2
|
+
import { type DropPlacement, type TreeItem, type TreeMove } from "../tree.ts";
|
|
3
|
+
export type { DropPlacement, TreeItem, TreeMove } from "../tree.ts";
|
|
4
|
+
interface TreeProps<Item extends TreeItem> {
|
|
5
|
+
items: Item[];
|
|
6
|
+
label: string;
|
|
7
|
+
render_item: (item: Item) => ReactNode;
|
|
8
|
+
render_extra?: (item: Item) => ReactNode;
|
|
9
|
+
name_of?: (item: Item) => string;
|
|
10
|
+
collapsed: ReadonlySet<string>;
|
|
11
|
+
on_collapsed_change: (collapsed: Set<string>) => void;
|
|
12
|
+
selected_id?: string | null;
|
|
13
|
+
selected_ids?: ReadonlySet<string>;
|
|
14
|
+
on_select?: (item: Item) => void;
|
|
15
|
+
on_activate?: (item: Item) => void;
|
|
16
|
+
row_class?: (item: Item) => string | undefined;
|
|
17
|
+
on_move?: (item: Item, move: TreeMove) => void;
|
|
18
|
+
can_drop?: (dragged: Item, target: Item, placement: DropPlacement) => boolean;
|
|
19
|
+
allow_inside?: boolean;
|
|
20
|
+
new_item?: {
|
|
21
|
+
parent_id: string | null;
|
|
22
|
+
form: ReactNode;
|
|
23
|
+
} | null;
|
|
24
|
+
on_context_menu?: (event: MouseEvent<HTMLElement>, item: Item) => void;
|
|
25
|
+
accepts_external?: (event: DragEvent<HTMLElement>, item: Item) => boolean;
|
|
26
|
+
on_external_drop?: (event: DragEvent<HTMLElement>, item: Item) => void;
|
|
27
|
+
}
|
|
28
|
+
export declare function Tree<Item extends TreeItem>({ items, label, render_item, render_extra, name_of, collapsed, on_collapsed_change, selected_id, selected_ids, on_select, on_activate, row_class: class_of, on_move, can_drop, allow_inside, new_item, on_context_menu, accepts_external, on_external_drop, }: TreeProps<Item>): import("react").JSX.Element;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// A tree of rows: fold and unfold, walk it with the arrow keys, and reorder it by dragging or with Alt and the arrow keys.
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { by_position, can_drop as is_outside_subtree, key_drop, move_for_drop, nest, placement_at, } from "../tree.js";
|
|
5
|
+
const KEY_MOVES = { ArrowUp: "up", ArrowDown: "down", ArrowRight: "indent", ArrowLeft: "outdent" };
|
|
6
|
+
// The rows a person can see, top to bottom, skipping those inside folded rows.
|
|
7
|
+
function visible_nodes(nodes, collapsed) {
|
|
8
|
+
return nodes.flatMap((node) => [node, ...(collapsed.has(node.item.id) ? [] : visible_nodes(node.children, collapsed))]);
|
|
9
|
+
}
|
|
10
|
+
export function Tree({ items, label, render_item, render_extra, name_of, collapsed, on_collapsed_change, selected_id = null, selected_ids, on_select, on_activate, row_class: class_of, on_move, can_drop, allow_inside = true, new_item = null, on_context_menu, accepts_external, on_external_drop, }) {
|
|
11
|
+
const [focused_id, set_focused_id] = useState(null);
|
|
12
|
+
const [dragged_id, set_dragged_id] = useState(null);
|
|
13
|
+
const [drop_target, set_drop_target] = useState(null);
|
|
14
|
+
const row_elements = useRef(new Map());
|
|
15
|
+
const moves_focus = useRef(false);
|
|
16
|
+
const roots = nest([...items].sort(by_position), items);
|
|
17
|
+
const shown = visible_nodes(roots, collapsed);
|
|
18
|
+
const is_selected = (id) => selected_id === id || Boolean(selected_ids?.has(id));
|
|
19
|
+
const first_selected = shown.find((node) => selected_ids?.has(node.item.id))?.item.id ?? null;
|
|
20
|
+
const tab_stop = [focused_id, selected_id, first_selected].find((id) => id !== null && shown.some((node) => node.item.id === id)) ?? shown[0]?.item.id;
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!moves_focus.current || focused_id === null)
|
|
23
|
+
return;
|
|
24
|
+
moves_focus.current = false;
|
|
25
|
+
row_elements.current.get(focused_id)?.focus();
|
|
26
|
+
}, [focused_id, items]);
|
|
27
|
+
// ── Folding ────────────────────────────────────────────────────────────────
|
|
28
|
+
function set_collapsed(id, is_collapsed) {
|
|
29
|
+
if (collapsed.has(id) === is_collapsed)
|
|
30
|
+
return;
|
|
31
|
+
const next = new Set(collapsed);
|
|
32
|
+
if (is_collapsed)
|
|
33
|
+
next.add(id);
|
|
34
|
+
else
|
|
35
|
+
next.delete(id);
|
|
36
|
+
on_collapsed_change(next);
|
|
37
|
+
}
|
|
38
|
+
// ── Moving ─────────────────────────────────────────────────────────────────
|
|
39
|
+
function is_allowed(dragged, target, placement) {
|
|
40
|
+
if (placement === "inside" && !allow_inside)
|
|
41
|
+
return false;
|
|
42
|
+
return is_outside_subtree(dragged.id, target.id, items) && (can_drop?.(dragged, target, placement) ?? true);
|
|
43
|
+
}
|
|
44
|
+
// A row dropped into a folded one unfolds it, so the moved row stays in sight.
|
|
45
|
+
function move(item, target, placement) {
|
|
46
|
+
if (placement === "inside")
|
|
47
|
+
set_collapsed(target.id, false);
|
|
48
|
+
on_move(item, move_for_drop(item, target, placement, items));
|
|
49
|
+
}
|
|
50
|
+
function placement_over(event, target) {
|
|
51
|
+
const dragged = items.find((item) => item.id === dragged_id);
|
|
52
|
+
if (!dragged)
|
|
53
|
+
return null;
|
|
54
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
55
|
+
const placement = placement_at(box.height > 0 ? (event.clientY - box.top) / box.height : 0.5, allow_inside);
|
|
56
|
+
return is_allowed(dragged, target, placement) ? placement : null;
|
|
57
|
+
}
|
|
58
|
+
// A drag from outside the tree, such as a task, lands inside the row that accepts it.
|
|
59
|
+
function accepts_from_outside(event, target) {
|
|
60
|
+
return dragged_id === null && Boolean(accepts_external?.(event, target));
|
|
61
|
+
}
|
|
62
|
+
function drag_over(event, target) {
|
|
63
|
+
const external = accepts_from_outside(event, target);
|
|
64
|
+
const placement = external ? "inside" : placement_over(event, target);
|
|
65
|
+
if (!placement)
|
|
66
|
+
return;
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
// An outside drag keeps the effect its source allowed, which may not include a move.
|
|
69
|
+
if (event.dataTransfer && !external)
|
|
70
|
+
event.dataTransfer.dropEffect = "move";
|
|
71
|
+
if (drop_target?.id !== target.id || drop_target.placement !== placement)
|
|
72
|
+
set_drop_target({ id: target.id, placement });
|
|
73
|
+
}
|
|
74
|
+
function drop(event, target) {
|
|
75
|
+
if (accepts_from_outside(event, target)) {
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
end_drag();
|
|
78
|
+
on_external_drop?.(event, target);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const placement = placement_over(event, target);
|
|
82
|
+
const dragged = items.find((item) => item.id === dragged_id);
|
|
83
|
+
end_drag();
|
|
84
|
+
if (!placement || !dragged)
|
|
85
|
+
return;
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
move(dragged, target, placement);
|
|
88
|
+
}
|
|
89
|
+
function end_drag() {
|
|
90
|
+
set_dragged_id(null);
|
|
91
|
+
set_drop_target(null);
|
|
92
|
+
}
|
|
93
|
+
// ── Keyboard ───────────────────────────────────────────────────────────────
|
|
94
|
+
function focus_row(id) {
|
|
95
|
+
if (id === undefined)
|
|
96
|
+
return;
|
|
97
|
+
moves_focus.current = true;
|
|
98
|
+
set_focused_id(id);
|
|
99
|
+
}
|
|
100
|
+
function key_down(event) {
|
|
101
|
+
const row = event.target.closest("[role='treeitem']");
|
|
102
|
+
if (row !== event.target)
|
|
103
|
+
return;
|
|
104
|
+
const index = shown.findIndex((node) => node.item.id === row.dataset.id);
|
|
105
|
+
const node = shown[index];
|
|
106
|
+
if (!node)
|
|
107
|
+
return;
|
|
108
|
+
const { item } = node;
|
|
109
|
+
const is_open = node.children.length > 0 && !collapsed.has(item.id);
|
|
110
|
+
if (event.altKey && on_move && KEY_MOVES[event.key]) {
|
|
111
|
+
const key_target = key_drop(item, KEY_MOVES[event.key], items);
|
|
112
|
+
if (key_target && is_allowed(item, key_target.target, key_target.placement)) {
|
|
113
|
+
move(item, key_target.target, key_target.placement);
|
|
114
|
+
focus_row(item.id);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else if (event.altKey || event.ctrlKey || event.metaKey) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
else if (event.key === "ArrowDown")
|
|
121
|
+
focus_row(shown[index + 1]?.item.id);
|
|
122
|
+
else if (event.key === "ArrowUp")
|
|
123
|
+
focus_row(shown[index - 1]?.item.id);
|
|
124
|
+
else if (event.key === "Home")
|
|
125
|
+
focus_row(shown[0]?.item.id);
|
|
126
|
+
else if (event.key === "End")
|
|
127
|
+
focus_row(shown.at(-1)?.item.id);
|
|
128
|
+
else if (event.key === "ArrowRight") {
|
|
129
|
+
if (is_open)
|
|
130
|
+
focus_row(node.children[0].item.id);
|
|
131
|
+
else if (node.children.length > 0)
|
|
132
|
+
set_collapsed(item.id, false);
|
|
133
|
+
else
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
else if (event.key === "ArrowLeft") {
|
|
137
|
+
if (is_open)
|
|
138
|
+
set_collapsed(item.id, true);
|
|
139
|
+
else if (item.parent_id !== null && shown.some((each) => each.item.id === item.parent_id))
|
|
140
|
+
focus_row(item.parent_id);
|
|
141
|
+
else
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
else if ((event.key === "Enter" || event.key === " ") && on_select)
|
|
145
|
+
on_select(item);
|
|
146
|
+
else
|
|
147
|
+
return;
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
}
|
|
150
|
+
// ── Rows ───────────────────────────────────────────────────────────────────
|
|
151
|
+
function new_item_row(parent_id) {
|
|
152
|
+
if (!new_item || new_item.parent_id !== parent_id)
|
|
153
|
+
return null;
|
|
154
|
+
return _jsx("li", { role: "none", className: "tree-new", children: new_item.form });
|
|
155
|
+
}
|
|
156
|
+
function branch(node, depth) {
|
|
157
|
+
const { item, children } = node;
|
|
158
|
+
const has_children = children.length > 0;
|
|
159
|
+
const is_collapsed = collapsed.has(item.id);
|
|
160
|
+
const name = name_of?.(item) ?? "row";
|
|
161
|
+
const new_child = new_item_row(item.id);
|
|
162
|
+
const row_class = [
|
|
163
|
+
"tree-row",
|
|
164
|
+
class_of?.(item),
|
|
165
|
+
dragged_id === item.id && "dragging",
|
|
166
|
+
drop_target?.id === item.id && `drop-${drop_target.placement}`,
|
|
167
|
+
].filter(Boolean).join(" ");
|
|
168
|
+
return (_jsxs("li", { ref: (element) => { if (element)
|
|
169
|
+
row_elements.current.set(item.id, element);
|
|
170
|
+
else
|
|
171
|
+
row_elements.current.delete(item.id); }, role: "treeitem", className: "tree-item", "data-id": item.id, "aria-level": depth + 1, "aria-expanded": has_children ? !is_collapsed : undefined, "aria-selected": on_select || selected_ids ? is_selected(item.id) : undefined, tabIndex: tab_stop === item.id ? 0 : -1, onFocus: (event) => { if (event.target === event.currentTarget)
|
|
172
|
+
set_focused_id(item.id); }, children: [_jsxs("div", { className: row_class, draggable: on_move ? true : undefined, onDragStart: (event) => {
|
|
173
|
+
event.dataTransfer?.setData("text/plain", item.id);
|
|
174
|
+
if (event.dataTransfer)
|
|
175
|
+
event.dataTransfer.effectAllowed = "move";
|
|
176
|
+
set_dragged_id(item.id);
|
|
177
|
+
}, onDragEnd: end_drag, onDragOver: (event) => drag_over(event, item), onDragLeave: () => { if (drop_target?.id === item.id)
|
|
178
|
+
set_drop_target(null); }, onDrop: (event) => drop(event, item), onClick: () => { focus_row(item.id); on_select?.(item); }, onDoubleClick: on_activate && (() => on_activate(item)), onContextMenu: on_context_menu && ((event) => on_context_menu(event, item)), children: [has_children
|
|
179
|
+
? (_jsx("button", { type: "button", className: "tree-toggle", tabIndex: -1, "aria-label": is_collapsed ? `Expand ${name}` : `Collapse ${name}`, onClick: (event) => { event.stopPropagation(); set_collapsed(item.id, !is_collapsed); }, children: _jsx("span", { "aria-hidden": "true", children: is_collapsed ? "▸" : "▾" }) }))
|
|
180
|
+
: _jsx("span", { className: "tree-toggle", "aria-hidden": "true" }), _jsx("span", { className: "tree-label", children: render_item(item) }), render_extra && _jsx("span", { className: "tree-extra", children: render_extra(item) })] }), ((has_children && !is_collapsed) || new_child) && (_jsxs("ul", { role: "group", className: "tree-children", children: [!is_collapsed && children.map((child) => branch(child, depth + 1)), new_child] }))] }, item.id));
|
|
181
|
+
}
|
|
182
|
+
return (_jsxs("ul", { role: "tree", className: "tree", "aria-label": label, "aria-multiselectable": selected_ids ? true : undefined, onKeyDown: key_down, children: [roots.map((node) => branch(node, 0)), new_item_row(null)] }));
|
|
183
|
+
}
|