Upload folder using huggingface_hub
Browse files
6.13.0/dataframe/Index.svelte
CHANGED
|
@@ -83,7 +83,6 @@
|
|
| 83 |
min_width={gradio.shared.min_width}
|
| 84 |
padding={false}
|
| 85 |
container={false}
|
| 86 |
-
overflow_behavior="visible"
|
| 87 |
{fullscreen}
|
| 88 |
>
|
| 89 |
<StatusTracker
|
|
|
|
| 83 |
min_width={gradio.shared.min_width}
|
| 84 |
padding={false}
|
| 85 |
container={false}
|
|
|
|
| 86 |
{fullscreen}
|
| 87 |
>
|
| 88 |
<StatusTracker
|
6.13.0/dataframe/shared/DataCell.svelte
CHANGED
|
@@ -20,6 +20,7 @@
|
|
| 20 |
show_menu_button = false,
|
| 21 |
show_selection_buttons = false,
|
| 22 |
is_first_column = false,
|
|
|
|
| 23 |
latex_delimiters,
|
| 24 |
line_breaks = true,
|
| 25 |
editable = true,
|
|
@@ -50,6 +51,7 @@
|
|
| 50 |
show_menu_button?: boolean;
|
| 51 |
show_selection_buttons?: boolean;
|
| 52 |
is_first_column?: boolean;
|
|
|
|
| 53 |
latex_delimiters: { left: string; right: string; display: boolean }[];
|
| 54 |
line_breaks?: boolean;
|
| 55 |
editable?: boolean;
|
|
@@ -71,6 +73,20 @@
|
|
| 71 |
} = $props();
|
| 72 |
|
| 73 |
let is_selected = $derived(selection_classes !== "");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
</script>
|
| 75 |
|
| 76 |
<div
|
|
@@ -78,6 +94,7 @@
|
|
| 78 |
class:flash={is_flash}
|
| 79 |
class:first-column={is_first_column}
|
| 80 |
class:static={is_static}
|
|
|
|
| 81 |
data-row={row_idx}
|
| 82 |
data-col={col_idx}
|
| 83 |
data-testid={`cell-${row_idx}-${col_idx}`}
|
|
@@ -87,7 +104,7 @@
|
|
| 87 |
{oncontextmenu}
|
| 88 |
style="{col_style} {cell_style}"
|
| 89 |
>
|
| 90 |
-
<div class="cell-wrap">
|
| 91 |
<EditableCell
|
| 92 |
{value}
|
| 93 |
{display_value}
|
|
@@ -107,6 +124,7 @@
|
|
| 107 |
{on_select_row}
|
| 108 |
{is_dragging}
|
| 109 |
{wrap_text}
|
|
|
|
| 110 |
/>
|
| 111 |
{#if show_menu_button}
|
| 112 |
<CellMenuButton on_click={on_menu_click} />
|
|
@@ -122,9 +140,10 @@
|
|
| 122 |
inset 1px 0 0 var(--border-color-primary),
|
| 123 |
inset 0 0 0 1px var(--ring-color);
|
| 124 |
padding: 0;
|
| 125 |
-
overflow:
|
| 126 |
box-sizing: border-box;
|
| 127 |
user-select: none;
|
|
|
|
| 128 |
}
|
| 129 |
|
| 130 |
.body-cell.static {
|
|
@@ -152,6 +171,65 @@
|
|
| 152 |
position: relative;
|
| 153 |
}
|
| 154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
.body-cell.cell-selected.no-top {
|
| 156 |
--sel-top: inset 0 0 0 0 transparent;
|
| 157 |
}
|
|
@@ -189,7 +267,7 @@
|
|
| 189 |
padding: var(--size-2);
|
| 190 |
box-sizing: border-box;
|
| 191 |
gap: var(--size-1);
|
| 192 |
-
overflow:
|
| 193 |
min-width: 0;
|
| 194 |
height: 100%;
|
| 195 |
}
|
|
|
|
| 20 |
show_menu_button = false,
|
| 21 |
show_selection_buttons = false,
|
| 22 |
is_first_column = false,
|
| 23 |
+
is_solo = false,
|
| 24 |
latex_delimiters,
|
| 25 |
line_breaks = true,
|
| 26 |
editable = true,
|
|
|
|
| 51 |
show_menu_button?: boolean;
|
| 52 |
show_selection_buttons?: boolean;
|
| 53 |
is_first_column?: boolean;
|
| 54 |
+
is_solo?: boolean;
|
| 55 |
latex_delimiters: { left: string; right: string; display: boolean }[];
|
| 56 |
line_breaks?: boolean;
|
| 57 |
editable?: boolean;
|
|
|
|
| 73 |
} = $props();
|
| 74 |
|
| 75 |
let is_selected = $derived(selection_classes !== "");
|
| 76 |
+
|
| 77 |
+
// lock the cell-wrap's height to its pre-selection value so the
|
| 78 |
+
// row doesn't shift when the span goes position: absolute.
|
| 79 |
+
let wrap_el: HTMLDivElement | undefined = $state();
|
| 80 |
+
let locked_height = $state("");
|
| 81 |
+
|
| 82 |
+
// pre is weird but runs _before_ DOM updates
|
| 83 |
+
$effect.pre(() => {
|
| 84 |
+
if (is_solo && wrap_el) {
|
| 85 |
+
locked_height = `height: ${wrap_el.offsetHeight}px;`;
|
| 86 |
+
} else {
|
| 87 |
+
locked_height = "";
|
| 88 |
+
}
|
| 89 |
+
});
|
| 90 |
</script>
|
| 91 |
|
| 92 |
<div
|
|
|
|
| 94 |
class:flash={is_flash}
|
| 95 |
class:first-column={is_first_column}
|
| 96 |
class:static={is_static}
|
| 97 |
+
class:cell-solo={is_solo}
|
| 98 |
data-row={row_idx}
|
| 99 |
data-col={col_idx}
|
| 100 |
data-testid={`cell-${row_idx}-${col_idx}`}
|
|
|
|
| 104 |
{oncontextmenu}
|
| 105 |
style="{col_style} {cell_style}"
|
| 106 |
>
|
| 107 |
+
<div class="cell-wrap" bind:this={wrap_el} style={locked_height}>
|
| 108 |
<EditableCell
|
| 109 |
{value}
|
| 110 |
{display_value}
|
|
|
|
| 124 |
{on_select_row}
|
| 125 |
{is_dragging}
|
| 126 |
{wrap_text}
|
| 127 |
+
expanded={is_solo}
|
| 128 |
/>
|
| 129 |
{#if show_menu_button}
|
| 130 |
<CellMenuButton on_click={on_menu_click} />
|
|
|
|
| 140 |
inset 1px 0 0 var(--border-color-primary),
|
| 141 |
inset 0 0 0 1px var(--ring-color);
|
| 142 |
padding: 0;
|
| 143 |
+
overflow: hidden;
|
| 144 |
box-sizing: border-box;
|
| 145 |
user-select: none;
|
| 146 |
+
min-width: 0;
|
| 147 |
}
|
| 148 |
|
| 149 |
.body-cell.static {
|
|
|
|
| 171 |
position: relative;
|
| 172 |
}
|
| 173 |
|
| 174 |
+
.body-cell.cell-solo {
|
| 175 |
+
z-index: 10;
|
| 176 |
+
overflow: visible;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.body-cell.cell-solo .cell-wrap {
|
| 180 |
+
overflow: visible;
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
.body-cell.cell-solo :global(.cell-wrap > span) {
|
| 184 |
+
position: absolute;
|
| 185 |
+
top: 0;
|
| 186 |
+
left: 0;
|
| 187 |
+
width: 100%;
|
| 188 |
+
min-height: 100%;
|
| 189 |
+
padding: var(--size-2);
|
| 190 |
+
box-sizing: border-box;
|
| 191 |
+
white-space: normal;
|
| 192 |
+
overflow: visible;
|
| 193 |
+
text-overflow: clip;
|
| 194 |
+
overflow-wrap: break-word;
|
| 195 |
+
word-break: break-word;
|
| 196 |
+
background: var(--background-fill-primary);
|
| 197 |
+
box-shadow:
|
| 198 |
+
inset 0 2px 0 0 var(--color-accent),
|
| 199 |
+
inset 0 -2px 0 0 var(--color-accent),
|
| 200 |
+
inset 2px 0 0 0 var(--color-accent),
|
| 201 |
+
inset -2px 0 0 0 var(--color-accent),
|
| 202 |
+
0 6px 12px -4px rgba(0, 0, 0, 0.22);
|
| 203 |
+
z-index: 1;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
.body-cell.cell-solo :global(.cell-wrap > textarea) {
|
| 207 |
+
position: absolute;
|
| 208 |
+
top: 0;
|
| 209 |
+
left: 0;
|
| 210 |
+
width: 100%;
|
| 211 |
+
min-height: 100%;
|
| 212 |
+
padding: var(--size-2);
|
| 213 |
+
padding-left: var(--size-2);
|
| 214 |
+
margin: 0;
|
| 215 |
+
box-sizing: border-box;
|
| 216 |
+
transform: none;
|
| 217 |
+
background: var(--background-fill-primary);
|
| 218 |
+
box-shadow:
|
| 219 |
+
inset 0 2px 0 0 var(--color-accent),
|
| 220 |
+
inset 0 -2px 0 0 var(--color-accent),
|
| 221 |
+
inset 2px 0 0 0 var(--color-accent),
|
| 222 |
+
inset -2px 0 0 0 var(--color-accent),
|
| 223 |
+
0 6px 12px -4px rgba(0, 0, 0, 0.22);
|
| 224 |
+
z-index: 2;
|
| 225 |
+
field-sizing: content;
|
| 226 |
+
height: auto;
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
.body-cell.cell-solo :global(.selection-button) {
|
| 230 |
+
z-index: 3;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
.body-cell.cell-selected.no-top {
|
| 234 |
--sel-top: inset 0 0 0 0 transparent;
|
| 235 |
}
|
|
|
|
| 267 |
padding: var(--size-2);
|
| 268 |
box-sizing: border-box;
|
| 269 |
gap: var(--size-1);
|
| 270 |
+
overflow: hidden;
|
| 271 |
min-width: 0;
|
| 272 |
height: 100%;
|
| 273 |
}
|
6.13.0/dataframe/shared/EditableCell.svelte
CHANGED
|
@@ -21,6 +21,7 @@
|
|
| 21 |
i18n,
|
| 22 |
is_dragging = false,
|
| 23 |
wrap_text = false,
|
|
|
|
| 24 |
show_selection_buttons = false,
|
| 25 |
coords,
|
| 26 |
on_select_column = null,
|
|
@@ -56,6 +57,7 @@
|
|
| 56 |
i18n: I18nFormatter;
|
| 57 |
is_dragging?: boolean;
|
| 58 |
wrap_text?: boolean;
|
|
|
|
| 59 |
show_selection_buttons?: boolean;
|
| 60 |
coords: [number, number];
|
| 61 |
on_select_column?: ((col: number) => void) | null;
|
|
@@ -81,7 +83,9 @@
|
|
| 81 |
return str.slice(0, max_length) + "...";
|
| 82 |
}
|
| 83 |
|
| 84 |
-
let should_truncate = $derived(
|
|
|
|
|
|
|
| 85 |
|
| 86 |
let display_content = $derived(
|
| 87 |
editable ? value : display_value !== null ? display_value : value
|
|
@@ -101,6 +105,22 @@
|
|
| 101 |
return {};
|
| 102 |
}
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
function handle_blur(event: FocusEvent): void {
|
| 105 |
onblur?.({
|
| 106 |
blur_event: event,
|
|
@@ -137,6 +157,7 @@
|
|
| 137 |
onmousedown={(e: MouseEvent) => e.stopPropagation()}
|
| 138 |
onclick={(e: MouseEvent) => e.stopPropagation()}
|
| 139 |
use:use_focus
|
|
|
|
| 140 |
onkeydown={handle_keydown}
|
| 141 |
class:pad_left
|
| 142 |
/>
|
|
@@ -152,7 +173,7 @@
|
|
| 152 |
role="button"
|
| 153 |
class:edit
|
| 154 |
class:expanded={edit}
|
| 155 |
-
class:
|
| 156 |
onfocus={(e) => e.preventDefault()}
|
| 157 |
style={styling}
|
| 158 |
data-editable={editable}
|
|
@@ -239,7 +260,14 @@
|
|
| 239 |
outline: none;
|
| 240 |
cursor: text;
|
| 241 |
width: 100%;
|
| 242 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
}
|
| 244 |
|
| 245 |
span.text.expanded {
|
|
@@ -250,19 +278,6 @@
|
|
| 250 |
overflow: visible;
|
| 251 |
}
|
| 252 |
|
| 253 |
-
.multiline {
|
| 254 |
-
white-space: pre;
|
| 255 |
-
overflow: hidden;
|
| 256 |
-
text-overflow: ellipsis;
|
| 257 |
-
}
|
| 258 |
-
|
| 259 |
-
.header {
|
| 260 |
-
font-weight: var(--weight-bold);
|
| 261 |
-
white-space: nowrap;
|
| 262 |
-
overflow: hidden;
|
| 263 |
-
text-overflow: ellipsis;
|
| 264 |
-
}
|
| 265 |
-
|
| 266 |
.edit {
|
| 267 |
opacity: 0;
|
| 268 |
pointer-events: none;
|
|
@@ -270,6 +285,8 @@
|
|
| 270 |
|
| 271 |
span :global(img) {
|
| 272 |
max-height: 100px;
|
|
|
|
|
|
|
| 273 |
width: auto;
|
| 274 |
object-fit: contain;
|
| 275 |
}
|
|
@@ -281,8 +298,9 @@
|
|
| 281 |
.wrap,
|
| 282 |
.wrap.expanded {
|
| 283 |
white-space: normal;
|
| 284 |
-
|
|
|
|
| 285 |
overflow-wrap: break-word;
|
| 286 |
-
word-
|
| 287 |
}
|
| 288 |
</style>
|
|
|
|
| 21 |
i18n,
|
| 22 |
is_dragging = false,
|
| 23 |
wrap_text = false,
|
| 24 |
+
expanded = false,
|
| 25 |
show_selection_buttons = false,
|
| 26 |
coords,
|
| 27 |
on_select_column = null,
|
|
|
|
| 57 |
i18n: I18nFormatter;
|
| 58 |
is_dragging?: boolean;
|
| 59 |
wrap_text?: boolean;
|
| 60 |
+
expanded?: boolean;
|
| 61 |
show_selection_buttons?: boolean;
|
| 62 |
coords: [number, number];
|
| 63 |
on_select_column?: ((col: number) => void) | null;
|
|
|
|
| 83 |
return str.slice(0, max_length) + "...";
|
| 84 |
}
|
| 85 |
|
| 86 |
+
let should_truncate = $derived(
|
| 87 |
+
!edit && !expanded && max_chars !== null && max_chars > 0
|
| 88 |
+
);
|
| 89 |
|
| 90 |
let display_content = $derived(
|
| 91 |
editable ? value : display_value !== null ? display_value : value
|
|
|
|
| 105 |
return {};
|
| 106 |
}
|
| 107 |
|
| 108 |
+
// grow the edit-mode textarea to fit its content so the overlay
|
| 109 |
+
// expands the same way the display span does.
|
| 110 |
+
function use_autosize(node: HTMLTextAreaElement): any {
|
| 111 |
+
function resize(): void {
|
| 112 |
+
node.style.height = "auto";
|
| 113 |
+
node.style.height = `${node.scrollHeight}px`;
|
| 114 |
+
}
|
| 115 |
+
node.addEventListener("input", resize);
|
| 116 |
+
requestAnimationFrame(resize);
|
| 117 |
+
return {
|
| 118 |
+
destroy() {
|
| 119 |
+
node.removeEventListener("input", resize);
|
| 120 |
+
}
|
| 121 |
+
};
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
function handle_blur(event: FocusEvent): void {
|
| 125 |
onblur?.({
|
| 126 |
blur_event: event,
|
|
|
|
| 157 |
onmousedown={(e: MouseEvent) => e.stopPropagation()}
|
| 158 |
onclick={(e: MouseEvent) => e.stopPropagation()}
|
| 159 |
use:use_focus
|
| 160 |
+
use:use_autosize
|
| 161 |
onkeydown={handle_keydown}
|
| 162 |
class:pad_left
|
| 163 |
/>
|
|
|
|
| 173 |
role="button"
|
| 174 |
class:edit
|
| 175 |
class:expanded={edit}
|
| 176 |
+
class:header
|
| 177 |
onfocus={(e) => e.preventDefault()}
|
| 178 |
style={styling}
|
| 179 |
data-editable={editable}
|
|
|
|
| 260 |
outline: none;
|
| 261 |
cursor: text;
|
| 262 |
width: 100%;
|
| 263 |
+
min-width: 0;
|
| 264 |
+
white-space: nowrap;
|
| 265 |
+
overflow: hidden;
|
| 266 |
+
text-overflow: ellipsis;
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
.header {
|
| 270 |
+
font-weight: var(--weight-bold);
|
| 271 |
}
|
| 272 |
|
| 273 |
span.text.expanded {
|
|
|
|
| 278 |
overflow: visible;
|
| 279 |
}
|
| 280 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
.edit {
|
| 282 |
opacity: 0;
|
| 283 |
pointer-events: none;
|
|
|
|
| 285 |
|
| 286 |
span :global(img) {
|
| 287 |
max-height: 100px;
|
| 288 |
+
max-width: 100%;
|
| 289 |
+
height: auto;
|
| 290 |
width: auto;
|
| 291 |
object-fit: contain;
|
| 292 |
}
|
|
|
|
| 298 |
.wrap,
|
| 299 |
.wrap.expanded {
|
| 300 |
white-space: normal;
|
| 301 |
+
overflow: visible;
|
| 302 |
+
text-overflow: clip;
|
| 303 |
overflow-wrap: break-word;
|
| 304 |
+
word-break: break-word;
|
| 305 |
}
|
| 306 |
</style>
|
6.13.0/dataframe/shared/HeaderCell.svelte
CHANGED
|
@@ -28,6 +28,7 @@
|
|
| 28 |
editable = true,
|
| 29 |
max_chars = undefined,
|
| 30 |
i18n,
|
|
|
|
| 31 |
onclick,
|
| 32 |
on_menu_click,
|
| 33 |
on_end_edit,
|
|
@@ -51,6 +52,7 @@
|
|
| 51 |
editable?: boolean;
|
| 52 |
max_chars?: number | undefined;
|
| 53 |
i18n: I18nFormatter;
|
|
|
|
| 54 |
onclick: (event: MouseEvent, col: number) => void;
|
| 55 |
on_menu_click: (event: MouseEvent, col: number) => void;
|
| 56 |
on_end_edit: (key: string) => void;
|
|
@@ -112,6 +114,7 @@
|
|
| 112 |
{is_static}
|
| 113 |
{i18n}
|
| 114 |
{max_chars}
|
|
|
|
| 115 |
coords={[col_idx, 0]}
|
| 116 |
pad_left={show_select_all ? true : false}
|
| 117 |
/>
|
|
|
|
| 28 |
editable = true,
|
| 29 |
max_chars = undefined,
|
| 30 |
i18n,
|
| 31 |
+
wrap_text = false,
|
| 32 |
onclick,
|
| 33 |
on_menu_click,
|
| 34 |
on_end_edit,
|
|
|
|
| 52 |
editable?: boolean;
|
| 53 |
max_chars?: number | undefined;
|
| 54 |
i18n: I18nFormatter;
|
| 55 |
+
wrap_text?: boolean;
|
| 56 |
onclick: (event: MouseEvent, col: number) => void;
|
| 57 |
on_menu_click: (event: MouseEvent, col: number) => void;
|
| 58 |
on_end_edit: (key: string) => void;
|
|
|
|
| 114 |
{is_static}
|
| 115 |
{i18n}
|
| 116 |
{max_chars}
|
| 117 |
+
{wrap_text}
|
| 118 |
coords={[col_idx, 0]}
|
| 119 |
pad_left={show_select_all ? true : false}
|
| 120 |
/>
|
6.13.0/dataframe/shared/Table.svelte
CHANGED
|
@@ -147,7 +147,7 @@
|
|
| 147 |
id: `col_${j}`,
|
| 148 |
accessorKey: `col_${j}`,
|
| 149 |
header: header_value,
|
| 150 |
-
size:
|
| 151 |
minSize: 45,
|
| 152 |
filterFn: gradio_filter_fn,
|
| 153 |
meta: {
|
|
@@ -603,13 +603,22 @@
|
|
| 603 |
if (selected) {
|
| 604 |
const [row, col] = selected;
|
| 605 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 606 |
switch (e.key) {
|
| 607 |
case "ArrowUp":
|
| 608 |
e.preventDefault();
|
| 609 |
if (row > 0) {
|
| 610 |
selected = [row - 1, col];
|
| 611 |
selected_cells = [selected];
|
| 612 |
-
editing = false;
|
| 613 |
virtualizer.instance.scrollToIndex(row - 1, { align: "auto" });
|
| 614 |
}
|
| 615 |
break;
|
|
@@ -618,7 +627,6 @@
|
|
| 618 |
if (row < num_rows - 1) {
|
| 619 |
selected = [row + 1, col];
|
| 620 |
selected_cells = [selected];
|
| 621 |
-
editing = false;
|
| 622 |
virtualizer.instance.scrollToIndex(row + 1, { align: "auto" });
|
| 623 |
}
|
| 624 |
break;
|
|
@@ -627,7 +635,6 @@
|
|
| 627 |
if (col > 0) {
|
| 628 |
selected = [row, col - 1];
|
| 629 |
selected_cells = [selected];
|
| 630 |
-
editing = false;
|
| 631 |
}
|
| 632 |
break;
|
| 633 |
case "ArrowRight":
|
|
@@ -635,7 +642,6 @@
|
|
| 635 |
if (col < num_cols - 1) {
|
| 636 |
selected = [row, col + 1];
|
| 637 |
selected_cells = [selected];
|
| 638 |
-
editing = false;
|
| 639 |
}
|
| 640 |
break;
|
| 641 |
case "Tab": {
|
|
@@ -780,6 +786,7 @@
|
|
| 780 |
|
| 781 |
let header_row_el: HTMLTableRowElement;
|
| 782 |
let header_table_el: HTMLTableElement;
|
|
|
|
| 783 |
|
| 784 |
const measurement = create_column_measurement({
|
| 785 |
header_row_el: () => header_row_el,
|
|
@@ -788,6 +795,7 @@
|
|
| 788 |
row_data: () => row_data,
|
| 789 |
show_row_numbers: () => show_row_numbers,
|
| 790 |
column_widths: () => column_widths,
|
|
|
|
| 791 |
on_resize: undefined
|
| 792 |
});
|
| 793 |
|
|
@@ -850,11 +858,11 @@
|
|
| 850 |
bind:this={parent}
|
| 851 |
class="table-wrap"
|
| 852 |
class:dragging={is_dragging}
|
| 853 |
-
class:no-wrap={!wrap}
|
| 854 |
class:menu-open={active_cell_menu || active_header_menu}
|
| 855 |
onkeydown={handle_keydown}
|
| 856 |
role="grid"
|
| 857 |
tabindex="0"
|
|
|
|
| 858 |
>
|
| 859 |
<Upload
|
| 860 |
{upload}
|
|
@@ -872,6 +880,7 @@
|
|
| 872 |
class="virtual-table-viewport"
|
| 873 |
class:disable-scroll={disable_scroll}
|
| 874 |
bind:this={scroll_container}
|
|
|
|
| 875 |
onscroll={handle_scroll}
|
| 876 |
style="max-height: {max_height}px;"
|
| 877 |
role="grid"
|
|
@@ -910,6 +919,7 @@
|
|
| 910 |
{editable}
|
| 911 |
{max_chars}
|
| 912 |
{i18n}
|
|
|
|
| 913 |
onclick={handle_header_click}
|
| 914 |
on_menu_click={toggle_header_menu}
|
| 915 |
on_end_edit={end_header_edit}
|
|
@@ -919,13 +929,21 @@
|
|
| 919 |
{/each}
|
| 920 |
</tr>
|
| 921 |
</thead>
|
| 922 |
-
|
| 923 |
<tbody class="sizing-body" aria-hidden="true">
|
| 924 |
{#if rows.length > 0}
|
| 925 |
{@const sizing_row = rows.reduce((widest, row) => {
|
| 926 |
const cells = row.getVisibleCells();
|
| 927 |
cells.forEach((cell, i) => {
|
| 928 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 929 |
if (!widest[i] || val.length > widest[i].length) {
|
| 930 |
widest[i] = val;
|
| 931 |
}
|
|
@@ -1016,6 +1034,9 @@
|
|
| 1016 |
show_selection_buttons={selected_cells.length === 1 &&
|
| 1017 |
selected_cells[0][0] === row_idx &&
|
| 1018 |
selected_cells[0][1] === col_idx}
|
|
|
|
|
|
|
|
|
|
| 1019 |
is_first_column={ci === 0 && !show_row_numbers}
|
| 1020 |
{latex_delimiters}
|
| 1021 |
{line_breaks}
|
|
@@ -1140,7 +1161,7 @@
|
|
| 1140 |
gap: var(--size-2);
|
| 1141 |
position: relative;
|
| 1142 |
max-width: 100%;
|
| 1143 |
-
overflow: hidden;
|
| 1144 |
}
|
| 1145 |
|
| 1146 |
.table-container.fullscreen {
|
|
@@ -1260,6 +1281,12 @@
|
|
| 1260 |
padding: var(--size-2);
|
| 1261 |
border: none;
|
| 1262 |
white-space: nowrap;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1263 |
}
|
| 1264 |
|
| 1265 |
/* Virtual body */
|
|
@@ -1335,18 +1362,6 @@
|
|
| 1335 |
justify-content: center;
|
| 1336 |
}
|
| 1337 |
|
| 1338 |
-
.no-wrap {
|
| 1339 |
-
white-space: nowrap;
|
| 1340 |
-
}
|
| 1341 |
-
|
| 1342 |
-
div:not(.no-wrap) :global(td) {
|
| 1343 |
-
overflow-wrap: anywhere;
|
| 1344 |
-
}
|
| 1345 |
-
|
| 1346 |
-
div.no-wrap :global(td) {
|
| 1347 |
-
overflow-x: hidden;
|
| 1348 |
-
}
|
| 1349 |
-
|
| 1350 |
.header-row {
|
| 1351 |
display: flex;
|
| 1352 |
justify-content: flex-end;
|
|
|
|
| 147 |
id: `col_${j}`,
|
| 148 |
accessorKey: `col_${j}`,
|
| 149 |
header: header_value,
|
| 150 |
+
size: 150,
|
| 151 |
minSize: 45,
|
| 152 |
filterFn: gradio_filter_fn,
|
| 153 |
meta: {
|
|
|
|
| 603 |
if (selected) {
|
| 604 |
const [row, col] = selected;
|
| 605 |
|
| 606 |
+
if (
|
| 607 |
+
editing &&
|
| 608 |
+
(e.key === "ArrowUp" ||
|
| 609 |
+
e.key === "ArrowDown" ||
|
| 610 |
+
e.key === "ArrowLeft" ||
|
| 611 |
+
e.key === "ArrowRight")
|
| 612 |
+
) {
|
| 613 |
+
return;
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
switch (e.key) {
|
| 617 |
case "ArrowUp":
|
| 618 |
e.preventDefault();
|
| 619 |
if (row > 0) {
|
| 620 |
selected = [row - 1, col];
|
| 621 |
selected_cells = [selected];
|
|
|
|
| 622 |
virtualizer.instance.scrollToIndex(row - 1, { align: "auto" });
|
| 623 |
}
|
| 624 |
break;
|
|
|
|
| 627 |
if (row < num_rows - 1) {
|
| 628 |
selected = [row + 1, col];
|
| 629 |
selected_cells = [selected];
|
|
|
|
| 630 |
virtualizer.instance.scrollToIndex(row + 1, { align: "auto" });
|
| 631 |
}
|
| 632 |
break;
|
|
|
|
| 635 |
if (col > 0) {
|
| 636 |
selected = [row, col - 1];
|
| 637 |
selected_cells = [selected];
|
|
|
|
| 638 |
}
|
| 639 |
break;
|
| 640 |
case "ArrowRight":
|
|
|
|
| 642 |
if (col < num_cols - 1) {
|
| 643 |
selected = [row, col + 1];
|
| 644 |
selected_cells = [selected];
|
|
|
|
| 645 |
}
|
| 646 |
break;
|
| 647 |
case "Tab": {
|
|
|
|
| 786 |
|
| 787 |
let header_row_el: HTMLTableRowElement;
|
| 788 |
let header_table_el: HTMLTableElement;
|
| 789 |
+
let viewport_width = $state(0);
|
| 790 |
|
| 791 |
const measurement = create_column_measurement({
|
| 792 |
header_row_el: () => header_row_el,
|
|
|
|
| 795 |
row_data: () => row_data,
|
| 796 |
show_row_numbers: () => show_row_numbers,
|
| 797 |
column_widths: () => column_widths,
|
| 798 |
+
viewport_width: () => viewport_width,
|
| 799 |
on_resize: undefined
|
| 800 |
});
|
| 801 |
|
|
|
|
| 858 |
bind:this={parent}
|
| 859 |
class="table-wrap"
|
| 860 |
class:dragging={is_dragging}
|
|
|
|
| 861 |
class:menu-open={active_cell_menu || active_header_menu}
|
| 862 |
onkeydown={handle_keydown}
|
| 863 |
role="grid"
|
| 864 |
tabindex="0"
|
| 865 |
+
style="--df-max-col-width: {viewport_width}px;"
|
| 866 |
>
|
| 867 |
<Upload
|
| 868 |
{upload}
|
|
|
|
| 880 |
class="virtual-table-viewport"
|
| 881 |
class:disable-scroll={disable_scroll}
|
| 882 |
bind:this={scroll_container}
|
| 883 |
+
bind:clientWidth={viewport_width}
|
| 884 |
onscroll={handle_scroll}
|
| 885 |
style="max-height: {max_height}px;"
|
| 886 |
role="grid"
|
|
|
|
| 919 |
{editable}
|
| 920 |
{max_chars}
|
| 921 |
{i18n}
|
| 922 |
+
wrap_text={wrap}
|
| 923 |
onclick={handle_header_click}
|
| 924 |
on_menu_click={toggle_header_menu}
|
| 925 |
on_end_edit={end_header_edit}
|
|
|
|
| 929 |
{/each}
|
| 930 |
</tr>
|
| 931 |
</thead>
|
| 932 |
+
|
| 933 |
<tbody class="sizing-body" aria-hidden="true">
|
| 934 |
{#if rows.length > 0}
|
| 935 |
{@const sizing_row = rows.reduce((widest, row) => {
|
| 936 |
const cells = row.getVisibleCells();
|
| 937 |
cells.forEach((cell, i) => {
|
| 938 |
+
let val = String(cell.getValue() ?? "");
|
| 939 |
+
if (
|
| 940 |
+
max_chars &&
|
| 941 |
+
max_chars > 0 &&
|
| 942 |
+
val.length > max_chars &&
|
| 943 |
+
get_dtype(i) !== "image"
|
| 944 |
+
) {
|
| 945 |
+
val = val.slice(0, max_chars) + "...";
|
| 946 |
+
}
|
| 947 |
if (!widest[i] || val.length > widest[i].length) {
|
| 948 |
widest[i] = val;
|
| 949 |
}
|
|
|
|
| 1034 |
show_selection_buttons={selected_cells.length === 1 &&
|
| 1035 |
selected_cells[0][0] === row_idx &&
|
| 1036 |
selected_cells[0][1] === col_idx}
|
| 1037 |
+
is_solo={selected_cells.length === 1 &&
|
| 1038 |
+
selected_cells[0][0] === row_idx &&
|
| 1039 |
+
selected_cells[0][1] === col_idx}
|
| 1040 |
is_first_column={ci === 0 && !show_row_numbers}
|
| 1041 |
{latex_delimiters}
|
| 1042 |
{line_breaks}
|
|
|
|
| 1161 |
gap: var(--size-2);
|
| 1162 |
position: relative;
|
| 1163 |
max-width: 100%;
|
| 1164 |
+
overflow-x: hidden;
|
| 1165 |
}
|
| 1166 |
|
| 1167 |
.table-container.fullscreen {
|
|
|
|
| 1281 |
padding: var(--size-2);
|
| 1282 |
border: none;
|
| 1283 |
white-space: nowrap;
|
| 1284 |
+
max-width: var(--df-max-col-width);
|
| 1285 |
+
overflow: hidden;
|
| 1286 |
+
}
|
| 1287 |
+
|
| 1288 |
+
.header-table :global(.header-cell) {
|
| 1289 |
+
max-width: var(--df-max-col-width);
|
| 1290 |
}
|
| 1291 |
|
| 1292 |
/* Virtual body */
|
|
|
|
| 1362 |
justify-content: center;
|
| 1363 |
}
|
| 1364 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1365 |
.header-row {
|
| 1366 |
display: flex;
|
| 1367 |
justify-content: flex-end;
|
6.13.0/dataframe/shared/column_measurement.svelte.ts
CHANGED
|
@@ -9,6 +9,7 @@ export function create_column_measurement(opts: {
|
|
| 9 |
row_data: () => any[];
|
| 10 |
show_row_numbers: () => boolean;
|
| 11 |
column_widths: () => string[];
|
|
|
|
| 12 |
on_resize?: () => void;
|
| 13 |
}): {
|
| 14 |
readonly col_widths: number[];
|
|
@@ -25,23 +26,95 @@ export function create_column_measurement(opts: {
|
|
| 25 |
// use offsets (not just widths) avoids accumulated subpixel rounding errors
|
| 26 |
let col_lefts: number[] = $state([]);
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
function measure(): void {
|
| 29 |
const current_row_el = opts.header_row_el();
|
| 30 |
const current_table_el = opts.header_table_el();
|
| 31 |
-
if (!current_row_el) return;
|
| 32 |
-
|
| 33 |
-
const cells = current_row_el.querySelectorAll<HTMLElement>(".header-cell");
|
| 34 |
-
const table_rect = current_table_el?.getBoundingClientRect();
|
| 35 |
-
const table_left = table_rect?.left ?? 0;
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
);
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
opts.on_resize?.();
|
| 46 |
}
|
| 47 |
|
|
@@ -65,6 +138,12 @@ export function create_column_measurement(opts: {
|
|
| 65 |
return () => ro.disconnect();
|
| 66 |
});
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
let row_num_width = $derived.by(() => {
|
| 69 |
if (!opts.show_row_numbers()) return 0;
|
| 70 |
const row_el = opts.header_row_el();
|
|
@@ -77,9 +156,14 @@ export function create_column_measurement(opts: {
|
|
| 77 |
if (col_widths[index] !== undefined) {
|
| 78 |
return `width: ${col_widths[index]}px; flex: 0 0 ${col_widths[index]}px;`;
|
| 79 |
}
|
| 80 |
-
const
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
}
|
| 84 |
|
| 85 |
return {
|
|
|
|
| 9 |
row_data: () => any[];
|
| 10 |
show_row_numbers: () => boolean;
|
| 11 |
column_widths: () => string[];
|
| 12 |
+
viewport_width: () => number;
|
| 13 |
on_resize?: () => void;
|
| 14 |
}): {
|
| 15 |
readonly col_widths: number[];
|
|
|
|
| 26 |
// use offsets (not just widths) avoids accumulated subpixel rounding errors
|
| 27 |
let col_lefts: number[] = $state([]);
|
| 28 |
|
| 29 |
+
function resolve_user_width(
|
| 30 |
+
raw: string | undefined,
|
| 31 |
+
vw: number
|
| 32 |
+
): number | null {
|
| 33 |
+
if (!raw || raw === "auto") return null;
|
| 34 |
+
if (raw.endsWith("%")) {
|
| 35 |
+
const pct = parseFloat(raw);
|
| 36 |
+
if (!isFinite(pct) || vw <= 0) return null;
|
| 37 |
+
return (pct / 100) * vw;
|
| 38 |
+
}
|
| 39 |
+
if (raw.endsWith("px")) {
|
| 40 |
+
const n = parseFloat(raw);
|
| 41 |
+
return isFinite(n) ? n : null;
|
| 42 |
+
}
|
| 43 |
+
const n = parseFloat(raw);
|
| 44 |
+
return isFinite(n) ? n : null;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
function clear_pin(el: HTMLElement): void {
|
| 48 |
+
if (el.style.width) el.style.width = "";
|
| 49 |
+
if (el.style.minWidth) el.style.minWidth = "";
|
| 50 |
+
if (el.style.maxWidth) el.style.maxWidth = "";
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
function pin(el: HTMLElement, target: string): void {
|
| 54 |
+
if (el.style.width !== target) el.style.width = target;
|
| 55 |
+
if (el.style.minWidth !== target) el.style.minWidth = target;
|
| 56 |
+
if (el.style.maxWidth !== target) el.style.maxWidth = target;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
function measure(): void {
|
| 60 |
const current_row_el = opts.header_row_el();
|
| 61 |
const current_table_el = opts.header_table_el();
|
| 62 |
+
if (!current_row_el || !current_table_el) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
+
const cells = Array.from(
|
| 65 |
+
current_row_el.querySelectorAll<HTMLElement>(".header-cell")
|
| 66 |
);
|
| 67 |
+
// sizing-body mirrors the data columns to give auto-layout a read on
|
| 68 |
+
// body-content widths. we also pin its cells so user widths are
|
| 69 |
+
// honored exactly (otherwise the sizing row's nowrap min-content
|
| 70 |
+
// forces the column wider than the user asked for).
|
| 71 |
+
const sizing_tds_all = Array.from(
|
| 72 |
+
current_table_el.querySelectorAll<HTMLElement>(".sizing-body > tr > td")
|
| 73 |
+
);
|
| 74 |
+
const sizing_data_tds = opts.show_row_numbers()
|
| 75 |
+
? sizing_tds_all.slice(1)
|
| 76 |
+
: sizing_tds_all;
|
| 77 |
+
|
| 78 |
+
cells.forEach(clear_pin);
|
| 79 |
+
sizing_data_tds.forEach(clear_pin);
|
| 80 |
+
current_table_el.style.width = "auto";
|
| 81 |
+
current_table_el.getBoundingClientRect(); // force layout flush
|
| 82 |
+
|
| 83 |
+
const vw = opts.viewport_width();
|
| 84 |
+
const user_widths = opts.column_widths();
|
| 85 |
+
|
| 86 |
+
const next_widths = cells.map((cell, i) => {
|
| 87 |
+
const resolved = resolve_user_width(user_widths[i], vw);
|
| 88 |
+
if (resolved != null) return resolved;
|
| 89 |
+
// cap auto-sized columns at the viewport so a single column
|
| 90 |
+
// can never be wider than the visible scroll area
|
| 91 |
+
const measured = cell.getBoundingClientRect().width;
|
| 92 |
+
return vw > 0 ? Math.min(measured, vw) : measured;
|
| 93 |
+
});
|
| 94 |
+
|
| 95 |
+
cells.forEach((cell, i) => pin(cell, `${next_widths[i]}px`));
|
| 96 |
+
sizing_data_tds.forEach((cell, i) => {
|
| 97 |
+
if (next_widths[i] == null) return;
|
| 98 |
+
pin(cell, `${next_widths[i]}px`);
|
| 99 |
+
});
|
| 100 |
+
|
| 101 |
+
// set the table width to the sum of columns so auto-layout
|
| 102 |
+
// has no extra space to redistribute
|
| 103 |
+
let table_w = next_widths.reduce((a, b) => a + b, 0);
|
| 104 |
+
if (opts.show_row_numbers()) {
|
| 105 |
+
const rn =
|
| 106 |
+
current_row_el.querySelector<HTMLElement>(".row-number-header");
|
| 107 |
+
if (rn) table_w += rn.getBoundingClientRect().width;
|
| 108 |
}
|
| 109 |
+
current_table_el.style.width = `${table_w}px`;
|
| 110 |
+
|
| 111 |
+
const after_rect = current_table_el.getBoundingClientRect();
|
| 112 |
+
col_lefts = cells.map(
|
| 113 |
+
(c) => c.getBoundingClientRect().left - after_rect.left
|
| 114 |
+
);
|
| 115 |
+
col_widths = next_widths;
|
| 116 |
+
total_header_width = after_rect.width;
|
| 117 |
+
header_height = after_rect.height;
|
| 118 |
opts.on_resize?.();
|
| 119 |
}
|
| 120 |
|
|
|
|
| 138 |
return () => ro.disconnect();
|
| 139 |
});
|
| 140 |
|
| 141 |
+
$effect(() => {
|
| 142 |
+
opts.viewport_width();
|
| 143 |
+
opts.column_widths();
|
| 144 |
+
measure();
|
| 145 |
+
});
|
| 146 |
+
|
| 147 |
let row_num_width = $derived.by(() => {
|
| 148 |
if (!opts.show_row_numbers()) return 0;
|
| 149 |
const row_el = opts.header_row_el();
|
|
|
|
| 156 |
if (col_widths[index] !== undefined) {
|
| 157 |
return `width: ${col_widths[index]}px; flex: 0 0 ${col_widths[index]}px;`;
|
| 158 |
}
|
| 159 |
+
const resolved = resolve_user_width(
|
| 160 |
+
opts.column_widths()[index],
|
| 161 |
+
opts.viewport_width()
|
| 162 |
+
);
|
| 163 |
+
if (resolved != null) {
|
| 164 |
+
return `width: ${resolved}px; flex: 0 0 ${resolved}px;`;
|
| 165 |
+
}
|
| 166 |
+
return "width: 150px; flex: 0 0 150px;";
|
| 167 |
}
|
| 168 |
|
| 169 |
return {
|