@gradio/dataframe 0.23.0 → 0.23.2
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/CHANGELOG.md +26 -0
- package/Dataframe.test.ts +316 -4
- package/Index.svelte +0 -1
- package/dist/Index.svelte +0 -1
- package/dist/shared/BooleanCell.svelte +0 -1
- package/dist/shared/DataCell.svelte +88 -3
- package/dist/shared/DataCell.svelte.d.ts +1 -0
- package/dist/shared/EditableCell.svelte +52 -29
- package/dist/shared/EditableCell.svelte.d.ts +2 -0
- package/dist/shared/HeaderCell.svelte +67 -5
- package/dist/shared/HeaderCell.svelte.d.ts +4 -0
- package/dist/shared/Table.svelte +166 -50
- package/dist/shared/column_measurement.svelte.d.ts +1 -0
- package/dist/shared/column_measurement.svelte.js +86 -13
- package/package.json +7 -7
- package/shared/BooleanCell.svelte +0 -1
- package/shared/DataCell.svelte +88 -3
- package/shared/EditableCell.svelte +52 -29
- package/shared/HeaderCell.svelte +67 -5
- package/shared/Table.svelte +166 -50
- package/shared/column_measurement.svelte.ts +98 -14
package/dist/shared/Table.svelte
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { tick, onMount } from "svelte";
|
|
14
14
|
import { Upload } from "@gradio/upload";
|
|
15
15
|
|
|
16
|
+
import { MarkdownCode } from "@gradio/markdown-code";
|
|
16
17
|
import HeaderCell from "./HeaderCell.svelte";
|
|
17
18
|
import DataCell from "./DataCell.svelte";
|
|
18
19
|
import EmptyRowButton from "./EmptyRowButton.svelte";
|
|
@@ -147,7 +148,7 @@
|
|
|
147
148
|
id: `col_${j}`,
|
|
148
149
|
accessorKey: `col_${j}`,
|
|
149
150
|
header: header_value,
|
|
150
|
-
size:
|
|
151
|
+
size: 150,
|
|
151
152
|
minSize: 45,
|
|
152
153
|
filterFn: gradio_filter_fn,
|
|
153
154
|
meta: {
|
|
@@ -263,6 +264,82 @@
|
|
|
263
264
|
return Array.isArray(datatype) ? (datatype[col] ?? "str") : datatype;
|
|
264
265
|
}
|
|
265
266
|
|
|
267
|
+
type SizingEntry = { val: string; col_idx: number; dtype: Datatype };
|
|
268
|
+
|
|
269
|
+
// heading multipliers for markdown/html block elements that render
|
|
270
|
+
// at a larger font size than body text.
|
|
271
|
+
const HEADING_MULT = [2.2, 1.7, 1.4, 1.2, 1.1, 1.05];
|
|
272
|
+
|
|
273
|
+
function md_visual_length(s: string): number {
|
|
274
|
+
const heading = s.match(/^\s*(#{1,6})\s+(.+)/);
|
|
275
|
+
if (heading) {
|
|
276
|
+
const lvl = heading[1].length;
|
|
277
|
+
const text = heading[2].replace(/[*_`[\]()]/g, "");
|
|
278
|
+
return text.length * HEADING_MULT[lvl - 1];
|
|
279
|
+
}
|
|
280
|
+
return s.replace(/[*_`#[\]()]/g, "").length;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function html_visual_length(s: string): number {
|
|
284
|
+
const stripped = s.replace(/<[^>]+>/g, "").length;
|
|
285
|
+
const h = s.match(/<h([1-6])\b/i);
|
|
286
|
+
if (h) return stripped * HEADING_MULT[parseInt(h[1]) - 1];
|
|
287
|
+
return stripped;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// mirror EditableCell.truncate_text so the sizing row reserves width
|
|
291
|
+
// for the truncated ("…") string, not the full source
|
|
292
|
+
function apply_truncation(s: string, dtype: Datatype): string {
|
|
293
|
+
if (
|
|
294
|
+
max_chars &&
|
|
295
|
+
max_chars > 0 &&
|
|
296
|
+
dtype !== "image" &&
|
|
297
|
+
s.length > max_chars
|
|
298
|
+
) {
|
|
299
|
+
return s.slice(0, max_chars) + "...";
|
|
300
|
+
}
|
|
301
|
+
return s;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// find the widest rendered value per visible column for the sizing row
|
|
305
|
+
function compute_sizing_row(): SizingEntry[] {
|
|
306
|
+
const headers = header_groups[0]?.headers ?? [];
|
|
307
|
+
return headers.map((header) => {
|
|
308
|
+
const col_idx = (header.column.columnDef.meta as any)?.colIndex ?? 0;
|
|
309
|
+
const dtype = get_dtype(col_idx);
|
|
310
|
+
const accessor = `col_${col_idx}`;
|
|
311
|
+
|
|
312
|
+
if (dtype === "bool") {
|
|
313
|
+
return { val: "false", col_idx, dtype };
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const visual_len =
|
|
317
|
+
dtype === "markdown"
|
|
318
|
+
? md_visual_length
|
|
319
|
+
: dtype === "html"
|
|
320
|
+
? html_visual_length
|
|
321
|
+
: (s: string) => s.length;
|
|
322
|
+
|
|
323
|
+
let best = "";
|
|
324
|
+
let best_len = -1;
|
|
325
|
+
for (const r of rows) {
|
|
326
|
+
const row_idx = r.original._index;
|
|
327
|
+
const rendered = editable
|
|
328
|
+
? r.original[accessor]
|
|
329
|
+
: (display_value?.[row_idx]?.[col_idx] ??
|
|
330
|
+
values?.[row_idx]?.[col_idx]);
|
|
331
|
+
if (rendered == null) continue;
|
|
332
|
+
const v = apply_truncation(String(rendered), dtype);
|
|
333
|
+
const len = visual_len(v);
|
|
334
|
+
if (len > best_len) {
|
|
335
|
+
best_len = len;
|
|
336
|
+
best = v;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return { val: best, col_idx, dtype };
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
266
343
|
function get_display_value(row: number, col: number): string {
|
|
267
344
|
if (display_value?.[row]?.[col] !== undefined)
|
|
268
345
|
return display_value[row][col];
|
|
@@ -291,7 +368,13 @@
|
|
|
291
368
|
row: number,
|
|
292
369
|
col: number
|
|
293
370
|
): void {
|
|
294
|
-
|
|
371
|
+
const col_is_static =
|
|
372
|
+
!editable ||
|
|
373
|
+
static_columns.includes(col) ||
|
|
374
|
+
static_columns.includes(resolved_headers[col]);
|
|
375
|
+
if (!col_is_static) {
|
|
376
|
+
event.preventDefault();
|
|
377
|
+
}
|
|
295
378
|
event.stopPropagation();
|
|
296
379
|
|
|
297
380
|
const coord: CellCoordinate = [row, col];
|
|
@@ -332,7 +415,9 @@
|
|
|
332
415
|
col_value: values?.map((r) => r[col]) ?? []
|
|
333
416
|
} as any);
|
|
334
417
|
|
|
335
|
-
|
|
418
|
+
if (!col_is_static) {
|
|
419
|
+
tick().then(() => parent?.focus());
|
|
420
|
+
}
|
|
336
421
|
}
|
|
337
422
|
|
|
338
423
|
function handle_cell_dblclick(
|
|
@@ -340,15 +425,14 @@
|
|
|
340
425
|
row: number,
|
|
341
426
|
col: number
|
|
342
427
|
): void {
|
|
343
|
-
event.preventDefault();
|
|
344
|
-
event.stopPropagation();
|
|
345
|
-
if (!editable) return;
|
|
346
428
|
const col_is_static =
|
|
429
|
+
!editable ||
|
|
347
430
|
static_columns.includes(col) ||
|
|
348
431
|
static_columns.includes(resolved_headers[col]);
|
|
349
|
-
if (
|
|
350
|
-
|
|
351
|
-
|
|
432
|
+
if (col_is_static) return;
|
|
433
|
+
event.preventDefault();
|
|
434
|
+
event.stopPropagation();
|
|
435
|
+
editing = [row, col];
|
|
352
436
|
}
|
|
353
437
|
|
|
354
438
|
function handle_blur(detail: {
|
|
@@ -529,14 +613,29 @@
|
|
|
529
613
|
active_cell_menu = null;
|
|
530
614
|
}
|
|
531
615
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
616
|
+
function handle_select_all(col: number, checked: boolean): void {
|
|
617
|
+
const new_values = values.map((row) => {
|
|
618
|
+
const new_row = [...row];
|
|
619
|
+
new_row[col] = checked;
|
|
620
|
+
return new_row;
|
|
621
|
+
});
|
|
622
|
+
values = new_values;
|
|
623
|
+
push_change(new_values);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
function get_select_all_state(
|
|
627
|
+
col: number
|
|
628
|
+
): "checked" | "unchecked" | "indeterminate" {
|
|
629
|
+
if (!values.length) return "unchecked";
|
|
630
|
+
let true_count = 0;
|
|
631
|
+
for (const row of values) {
|
|
632
|
+
const v = row[col];
|
|
633
|
+
if (v === true || v === "true" || v === "True") true_count++;
|
|
634
|
+
}
|
|
635
|
+
if (true_count === 0) return "unchecked";
|
|
636
|
+
if (true_count === values.length) return "checked";
|
|
637
|
+
return "indeterminate";
|
|
638
|
+
}
|
|
540
639
|
|
|
541
640
|
function commit_filter(): void {
|
|
542
641
|
if (!global_filter || show_search !== "filter") return;
|
|
@@ -581,13 +680,22 @@
|
|
|
581
680
|
if (selected) {
|
|
582
681
|
const [row, col] = selected;
|
|
583
682
|
|
|
683
|
+
if (
|
|
684
|
+
editing &&
|
|
685
|
+
(e.key === "ArrowUp" ||
|
|
686
|
+
e.key === "ArrowDown" ||
|
|
687
|
+
e.key === "ArrowLeft" ||
|
|
688
|
+
e.key === "ArrowRight")
|
|
689
|
+
) {
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
|
|
584
693
|
switch (e.key) {
|
|
585
694
|
case "ArrowUp":
|
|
586
695
|
e.preventDefault();
|
|
587
696
|
if (row > 0) {
|
|
588
697
|
selected = [row - 1, col];
|
|
589
698
|
selected_cells = [selected];
|
|
590
|
-
editing = false;
|
|
591
699
|
virtualizer.instance.scrollToIndex(row - 1, { align: "auto" });
|
|
592
700
|
}
|
|
593
701
|
break;
|
|
@@ -596,7 +704,6 @@
|
|
|
596
704
|
if (row < num_rows - 1) {
|
|
597
705
|
selected = [row + 1, col];
|
|
598
706
|
selected_cells = [selected];
|
|
599
|
-
editing = false;
|
|
600
707
|
virtualizer.instance.scrollToIndex(row + 1, { align: "auto" });
|
|
601
708
|
}
|
|
602
709
|
break;
|
|
@@ -605,7 +712,6 @@
|
|
|
605
712
|
if (col > 0) {
|
|
606
713
|
selected = [row, col - 1];
|
|
607
714
|
selected_cells = [selected];
|
|
608
|
-
editing = false;
|
|
609
715
|
}
|
|
610
716
|
break;
|
|
611
717
|
case "ArrowRight":
|
|
@@ -613,7 +719,6 @@
|
|
|
613
719
|
if (col < num_cols - 1) {
|
|
614
720
|
selected = [row, col + 1];
|
|
615
721
|
selected_cells = [selected];
|
|
616
|
-
editing = false;
|
|
617
722
|
}
|
|
618
723
|
break;
|
|
619
724
|
case "Tab": {
|
|
@@ -758,6 +863,7 @@
|
|
|
758
863
|
|
|
759
864
|
let header_row_el: HTMLTableRowElement;
|
|
760
865
|
let header_table_el: HTMLTableElement;
|
|
866
|
+
let viewport_width = $state(0);
|
|
761
867
|
|
|
762
868
|
const measurement = create_column_measurement({
|
|
763
869
|
header_row_el: () => header_row_el,
|
|
@@ -766,6 +872,7 @@
|
|
|
766
872
|
row_data: () => row_data,
|
|
767
873
|
show_row_numbers: () => show_row_numbers,
|
|
768
874
|
column_widths: () => column_widths,
|
|
875
|
+
viewport_width: () => viewport_width,
|
|
769
876
|
on_resize: undefined
|
|
770
877
|
});
|
|
771
878
|
|
|
@@ -828,11 +935,11 @@
|
|
|
828
935
|
bind:this={parent}
|
|
829
936
|
class="table-wrap"
|
|
830
937
|
class:dragging={is_dragging}
|
|
831
|
-
class:no-wrap={!wrap}
|
|
832
938
|
class:menu-open={active_cell_menu || active_header_menu}
|
|
833
939
|
onkeydown={handle_keydown}
|
|
834
940
|
role="grid"
|
|
835
941
|
tabindex="0"
|
|
942
|
+
style="--df-max-col-width: {viewport_width}px;"
|
|
836
943
|
>
|
|
837
944
|
<Upload
|
|
838
945
|
{upload}
|
|
@@ -850,6 +957,7 @@
|
|
|
850
957
|
class="virtual-table-viewport"
|
|
851
958
|
class:disable-scroll={disable_scroll}
|
|
852
959
|
bind:this={scroll_container}
|
|
960
|
+
bind:clientWidth={viewport_width}
|
|
853
961
|
onscroll={handle_scroll}
|
|
854
962
|
style="max-height: {max_height}px;"
|
|
855
963
|
role="grid"
|
|
@@ -875,6 +983,8 @@
|
|
|
875
983
|
is_selected={selected_header === col_idx}
|
|
876
984
|
is_static={!!(header.column.columnDef.meta as any)
|
|
877
985
|
?.isStatic}
|
|
986
|
+
is_bool={get_dtype(col_idx) === "bool"}
|
|
987
|
+
select_all_state={get_select_all_state(col_idx)}
|
|
878
988
|
sort_direction={get_sort_info(col_idx).direction}
|
|
879
989
|
sort_priority={get_sort_info(col_idx).priority}
|
|
880
990
|
multi_sort={sorting.length > 1}
|
|
@@ -886,36 +996,39 @@
|
|
|
886
996
|
{editable}
|
|
887
997
|
{max_chars}
|
|
888
998
|
{i18n}
|
|
999
|
+
wrap_text={wrap}
|
|
889
1000
|
onclick={handle_header_click}
|
|
890
1001
|
on_menu_click={toggle_header_menu}
|
|
891
1002
|
on_end_edit={end_header_edit}
|
|
1003
|
+
on_select_all={handle_select_all}
|
|
892
1004
|
/>
|
|
893
1005
|
{/each}
|
|
894
1006
|
{/each}
|
|
895
1007
|
</tr>
|
|
896
1008
|
</thead>
|
|
897
|
-
|
|
1009
|
+
|
|
898
1010
|
<tbody class="sizing-body" aria-hidden="true">
|
|
899
1011
|
{#if rows.length > 0}
|
|
900
|
-
{@const sizing_row =
|
|
901
|
-
const cells = row.getVisibleCells();
|
|
902
|
-
cells.forEach((cell, i) => {
|
|
903
|
-
const val = String(cell.getValue() ?? "");
|
|
904
|
-
if (!widest[i] || val.length > widest[i].length) {
|
|
905
|
-
widest[i] = val;
|
|
906
|
-
}
|
|
907
|
-
});
|
|
908
|
-
return widest;
|
|
909
|
-
}, [] as string[])}
|
|
1012
|
+
{@const sizing_row = compute_sizing_row()}
|
|
910
1013
|
<tr>
|
|
911
1014
|
{#if show_row_numbers}
|
|
912
1015
|
<td class="row-number-cell">{rows.length}</td>
|
|
913
1016
|
{/if}
|
|
914
|
-
{#each sizing_row as
|
|
915
|
-
{@const dtype = get_dtype(ci)}
|
|
1017
|
+
{#each sizing_row as entry (entry.col_idx)}
|
|
916
1018
|
<td
|
|
917
1019
|
><div class="cell-wrap">
|
|
918
|
-
{#if dtype === "
|
|
1020
|
+
{#if entry.dtype === "markdown"}
|
|
1021
|
+
<MarkdownCode
|
|
1022
|
+
message={entry.val}
|
|
1023
|
+
{latex_delimiters}
|
|
1024
|
+
{line_breaks}
|
|
1025
|
+
chatbot={false}
|
|
1026
|
+
/>
|
|
1027
|
+
{:else if entry.dtype === "html"}
|
|
1028
|
+
{@html entry.val}
|
|
1029
|
+
{:else}
|
|
1030
|
+
{entry.val}
|
|
1031
|
+
{/if}
|
|
919
1032
|
</div></td
|
|
920
1033
|
>
|
|
921
1034
|
{/each}
|
|
@@ -981,14 +1094,19 @@
|
|
|
981
1094
|
editing[1] === col_idx
|
|
982
1095
|
)}
|
|
983
1096
|
is_flash={copy_flash && is_sel}
|
|
984
|
-
is_static={
|
|
1097
|
+
is_static={!editable ||
|
|
1098
|
+
!!(cell.column.columnDef.meta as any)?.isStatic}
|
|
985
1099
|
show_menu_button={editable &&
|
|
1100
|
+
!(cell.column.columnDef.meta as any)?.isStatic &&
|
|
986
1101
|
selected_cells.length === 1 &&
|
|
987
1102
|
selected_cells[0][0] === row_idx &&
|
|
988
1103
|
selected_cells[0][1] === col_idx}
|
|
989
1104
|
show_selection_buttons={selected_cells.length === 1 &&
|
|
990
1105
|
selected_cells[0][0] === row_idx &&
|
|
991
1106
|
selected_cells[0][1] === col_idx}
|
|
1107
|
+
is_solo={selected_cells.length === 1 &&
|
|
1108
|
+
selected_cells[0][0] === row_idx &&
|
|
1109
|
+
selected_cells[0][1] === col_idx}
|
|
992
1110
|
is_first_column={ci === 0 && !show_row_numbers}
|
|
993
1111
|
{latex_delimiters}
|
|
994
1112
|
{line_breaks}
|
|
@@ -1002,6 +1120,10 @@
|
|
|
1002
1120
|
ondblclick={(e) =>
|
|
1003
1121
|
handle_cell_dblclick(e, row_idx, col_idx)}
|
|
1004
1122
|
oncontextmenu={(e) => {
|
|
1123
|
+
const is_static_cell = !!(
|
|
1124
|
+
cell.column.columnDef.meta as any
|
|
1125
|
+
)?.isStatic;
|
|
1126
|
+
if (!editable || is_static_cell) return;
|
|
1005
1127
|
e.preventDefault();
|
|
1006
1128
|
toggle_cell_menu(e, row_idx, col_idx);
|
|
1007
1129
|
}}
|
|
@@ -1109,7 +1231,7 @@
|
|
|
1109
1231
|
gap: var(--size-2);
|
|
1110
1232
|
position: relative;
|
|
1111
1233
|
max-width: 100%;
|
|
1112
|
-
overflow: hidden;
|
|
1234
|
+
overflow-x: hidden;
|
|
1113
1235
|
}
|
|
1114
1236
|
|
|
1115
1237
|
.table-container.fullscreen {
|
|
@@ -1229,6 +1351,12 @@
|
|
|
1229
1351
|
padding: var(--size-2);
|
|
1230
1352
|
border: none;
|
|
1231
1353
|
white-space: nowrap;
|
|
1354
|
+
max-width: var(--df-max-col-width);
|
|
1355
|
+
overflow: hidden;
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
.header-table :global(.header-cell) {
|
|
1359
|
+
max-width: var(--df-max-col-width);
|
|
1232
1360
|
}
|
|
1233
1361
|
|
|
1234
1362
|
/* Virtual body */
|
|
@@ -1304,18 +1432,6 @@
|
|
|
1304
1432
|
justify-content: center;
|
|
1305
1433
|
}
|
|
1306
1434
|
|
|
1307
|
-
.no-wrap {
|
|
1308
|
-
white-space: nowrap;
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
div:not(.no-wrap) :global(td) {
|
|
1312
|
-
overflow-wrap: anywhere;
|
|
1313
|
-
}
|
|
1314
|
-
|
|
1315
|
-
div.no-wrap :global(td) {
|
|
1316
|
-
overflow-x: hidden;
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
1435
|
.header-row {
|
|
1320
1436
|
display: flex;
|
|
1321
1437
|
justify-content: flex-end;
|
|
@@ -8,20 +8,87 @@ export function create_column_measurement(opts) {
|
|
|
8
8
|
let header_height = $state(0);
|
|
9
9
|
// use offsets (not just widths) avoids accumulated subpixel rounding errors
|
|
10
10
|
let col_lefts = $state([]);
|
|
11
|
+
function resolve_user_width(raw, vw) {
|
|
12
|
+
if (!raw || raw === "auto")
|
|
13
|
+
return null;
|
|
14
|
+
if (raw.endsWith("%")) {
|
|
15
|
+
const pct = parseFloat(raw);
|
|
16
|
+
if (!isFinite(pct) || vw <= 0)
|
|
17
|
+
return null;
|
|
18
|
+
return (pct / 100) * vw;
|
|
19
|
+
}
|
|
20
|
+
if (raw.endsWith("px")) {
|
|
21
|
+
const n = parseFloat(raw);
|
|
22
|
+
return isFinite(n) ? n : null;
|
|
23
|
+
}
|
|
24
|
+
const n = parseFloat(raw);
|
|
25
|
+
return isFinite(n) ? n : null;
|
|
26
|
+
}
|
|
27
|
+
function clear_pin(el) {
|
|
28
|
+
if (el.style.width)
|
|
29
|
+
el.style.width = "";
|
|
30
|
+
if (el.style.minWidth)
|
|
31
|
+
el.style.minWidth = "";
|
|
32
|
+
if (el.style.maxWidth)
|
|
33
|
+
el.style.maxWidth = "";
|
|
34
|
+
}
|
|
35
|
+
function pin(el, target) {
|
|
36
|
+
if (el.style.width !== target)
|
|
37
|
+
el.style.width = target;
|
|
38
|
+
if (el.style.minWidth !== target)
|
|
39
|
+
el.style.minWidth = target;
|
|
40
|
+
if (el.style.maxWidth !== target)
|
|
41
|
+
el.style.maxWidth = target;
|
|
42
|
+
}
|
|
11
43
|
function measure() {
|
|
12
44
|
const current_row_el = opts.header_row_el();
|
|
13
45
|
const current_table_el = opts.header_table_el();
|
|
14
|
-
if (!current_row_el)
|
|
46
|
+
if (!current_row_el || !current_table_el)
|
|
15
47
|
return;
|
|
16
|
-
const cells = current_row_el.querySelectorAll(".header-cell");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
48
|
+
const cells = Array.from(current_row_el.querySelectorAll(".header-cell"));
|
|
49
|
+
// sizing-body mirrors the data columns to give auto-layout a read on
|
|
50
|
+
// body-content widths. we also pin its cells so user widths are
|
|
51
|
+
// honored exactly (otherwise the sizing row's nowrap min-content
|
|
52
|
+
// forces the column wider than the user asked for).
|
|
53
|
+
const sizing_tds_all = Array.from(current_table_el.querySelectorAll(".sizing-body > tr > td"));
|
|
54
|
+
const sizing_data_tds = opts.show_row_numbers()
|
|
55
|
+
? sizing_tds_all.slice(1)
|
|
56
|
+
: sizing_tds_all;
|
|
57
|
+
cells.forEach(clear_pin);
|
|
58
|
+
sizing_data_tds.forEach(clear_pin);
|
|
59
|
+
current_table_el.style.width = "auto";
|
|
60
|
+
current_table_el.getBoundingClientRect(); // force layout flush
|
|
61
|
+
const vw = opts.viewport_width();
|
|
62
|
+
const user_widths = opts.column_widths();
|
|
63
|
+
const next_widths = cells.map((cell, i) => {
|
|
64
|
+
const resolved = resolve_user_width(user_widths[i], vw);
|
|
65
|
+
if (resolved != null)
|
|
66
|
+
return resolved;
|
|
67
|
+
// cap auto-sized columns at the viewport so a single column
|
|
68
|
+
// can never be wider than the visible scroll area
|
|
69
|
+
const measured = cell.getBoundingClientRect().width;
|
|
70
|
+
return vw > 0 ? Math.min(measured, vw) : measured;
|
|
71
|
+
});
|
|
72
|
+
cells.forEach((cell, i) => pin(cell, `${next_widths[i]}px`));
|
|
73
|
+
sizing_data_tds.forEach((cell, i) => {
|
|
74
|
+
if (next_widths[i] == null)
|
|
75
|
+
return;
|
|
76
|
+
pin(cell, `${next_widths[i]}px`);
|
|
77
|
+
});
|
|
78
|
+
// set the table width to the sum of columns so auto-layout
|
|
79
|
+
// has no extra space to redistribute
|
|
80
|
+
let table_w = next_widths.reduce((a, b) => a + b, 0);
|
|
81
|
+
if (opts.show_row_numbers()) {
|
|
82
|
+
const rn = current_row_el.querySelector(".row-number-header");
|
|
83
|
+
if (rn)
|
|
84
|
+
table_w += rn.getBoundingClientRect().width;
|
|
24
85
|
}
|
|
86
|
+
current_table_el.style.width = `${table_w}px`;
|
|
87
|
+
const after_rect = current_table_el.getBoundingClientRect();
|
|
88
|
+
col_lefts = cells.map((c) => c.getBoundingClientRect().left - after_rect.left);
|
|
89
|
+
col_widths = next_widths;
|
|
90
|
+
total_header_width = after_rect.width;
|
|
91
|
+
header_height = after_rect.height;
|
|
25
92
|
opts.on_resize?.();
|
|
26
93
|
}
|
|
27
94
|
$effect(() => {
|
|
@@ -40,6 +107,11 @@ export function create_column_measurement(opts) {
|
|
|
40
107
|
cells.forEach((cell) => ro.observe(cell));
|
|
41
108
|
return () => ro.disconnect();
|
|
42
109
|
});
|
|
110
|
+
$effect(() => {
|
|
111
|
+
opts.viewport_width();
|
|
112
|
+
opts.column_widths();
|
|
113
|
+
measure();
|
|
114
|
+
});
|
|
43
115
|
let row_num_width = $derived.by(() => {
|
|
44
116
|
if (!opts.show_row_numbers())
|
|
45
117
|
return 0;
|
|
@@ -53,10 +125,11 @@ export function create_column_measurement(opts) {
|
|
|
53
125
|
if (col_widths[index] !== undefined) {
|
|
54
126
|
return `width: ${col_widths[index]}px; flex: 0 0 ${col_widths[index]}px;`;
|
|
55
127
|
}
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
58
|
-
return `width: ${
|
|
59
|
-
|
|
128
|
+
const resolved = resolve_user_width(opts.column_widths()[index], opts.viewport_width());
|
|
129
|
+
if (resolved != null) {
|
|
130
|
+
return `width: ${resolved}px; flex: 0 0 ${resolved}px;`;
|
|
131
|
+
}
|
|
132
|
+
return "width: 150px; flex: 0 0 150px;";
|
|
60
133
|
}
|
|
61
134
|
return {
|
|
62
135
|
get col_widths() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradio/dataframe",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.2",
|
|
4
4
|
"description": "Gradio UI packages",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "",
|
|
@@ -15,15 +15,15 @@
|
|
|
15
15
|
"dequal": "^2.0.3",
|
|
16
16
|
"@tanstack/table-core": "^8.21.3",
|
|
17
17
|
"@tanstack/virtual-core": "^3.13.6",
|
|
18
|
-
"@gradio/atoms": "^0.
|
|
18
|
+
"@gradio/atoms": "^0.24.0",
|
|
19
|
+
"@gradio/checkbox": "^0.7.0",
|
|
20
|
+
"@gradio/client": "^2.2.0",
|
|
19
21
|
"@gradio/button": "^0.6.6",
|
|
20
|
-
"@gradio/checkbox": "^0.6.6",
|
|
21
|
-
"@gradio/client": "^2.1.0",
|
|
22
22
|
"@gradio/icons": "^0.15.1",
|
|
23
|
-
"@gradio/
|
|
24
|
-
"@gradio/
|
|
23
|
+
"@gradio/markdown-code": "^0.7.0",
|
|
24
|
+
"@gradio/statustracker": "^0.14.1",
|
|
25
25
|
"@gradio/utils": "^0.12.2",
|
|
26
|
-
"@gradio/
|
|
26
|
+
"@gradio/upload": "^0.17.9"
|
|
27
27
|
},
|
|
28
28
|
"exports": {
|
|
29
29
|
".": {
|