@gradio/dataframe 0.18.7 → 0.19.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.
Files changed (74) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/Example.svelte +8 -8
  3. package/Index.svelte +1 -1
  4. package/README.md +232 -37
  5. package/dist/Example.svelte +8 -8
  6. package/dist/Example.svelte.d.ts +3 -1
  7. package/dist/Index.svelte.d.ts +20 -18
  8. package/dist/shared/BooleanCell.svelte +1 -2
  9. package/dist/shared/BooleanCell.svelte.d.ts +4 -2
  10. package/dist/shared/CellMenu.svelte +4 -8
  11. package/dist/shared/CellMenu.svelte.d.ts +11 -9
  12. package/dist/shared/CellMenuButton.svelte.d.ts +2 -0
  13. package/dist/shared/CellMenuIcons.svelte.d.ts +2 -0
  14. package/dist/shared/EditableCell.svelte +6 -12
  15. package/dist/shared/EditableCell.svelte.d.ts +17 -15
  16. package/dist/shared/EmptyRowButton.svelte.d.ts +2 -0
  17. package/dist/shared/Example.svelte.d.ts +2 -0
  18. package/dist/shared/FilterMenu.svelte +2 -4
  19. package/dist/shared/FilterMenu.svelte.d.ts +3 -1
  20. package/dist/shared/RowNumber.svelte.d.ts +4 -2
  21. package/dist/shared/Table.svelte +127 -157
  22. package/dist/shared/Table.svelte.d.ts +24 -22
  23. package/dist/shared/TableCell.svelte +7 -13
  24. package/dist/shared/TableCell.svelte.d.ts +6 -4
  25. package/dist/shared/TableHeader.svelte +5 -10
  26. package/dist/shared/TableHeader.svelte.d.ts +4 -2
  27. package/dist/shared/Toolbar.svelte +3 -4
  28. package/dist/shared/Toolbar.svelte.d.ts +7 -5
  29. package/dist/shared/VirtualTable.svelte +19 -16
  30. package/dist/shared/VirtualTable.svelte.d.ts +9 -6
  31. package/dist/shared/context/dataframe_context.d.ts +1 -1
  32. package/dist/shared/context/dataframe_context.js +1 -1
  33. package/dist/shared/icons/FilterIcon.svelte.d.ts +3 -3
  34. package/dist/shared/icons/Padlock.svelte.d.ts +2 -0
  35. package/dist/shared/icons/SelectionButtons.svelte +2 -4
  36. package/dist/shared/icons/SelectionButtons.svelte.d.ts +3 -1
  37. package/dist/shared/icons/SortArrowDown.svelte.d.ts +3 -1
  38. package/dist/shared/icons/SortArrowUp.svelte.d.ts +3 -1
  39. package/dist/shared/icons/SortButtonDown.svelte.d.ts +2 -0
  40. package/dist/shared/icons/SortButtonUp.svelte.d.ts +2 -0
  41. package/dist/shared/icons/SortIcon.svelte.d.ts +4 -2
  42. package/dist/shared/utils/data_processing.d.ts +1 -1
  43. package/dist/shared/utils/drag_utils.js +1 -1
  44. package/dist/shared/utils/keyboard_utils.js +5 -3
  45. package/dist/shared/{selection_utils.d.ts → utils/selection_utils.d.ts} +1 -1
  46. package/dist/shared/{utils.d.ts → utils/utils.d.ts} +2 -2
  47. package/dist/standalone/Index.svelte +660 -0
  48. package/dist/standalone/Index.svelte.d.ts +45 -0
  49. package/dist/standalone/default_i18n.d.ts +1 -0
  50. package/dist/standalone/default_i18n.js +32 -0
  51. package/dist/standalone/stubs/Upload.svelte +18 -0
  52. package/dist/standalone/stubs/Upload.svelte.d.ts +27 -0
  53. package/dist/standalone/stubs/upload.d.ts +1 -0
  54. package/dist/standalone/stubs/upload.js +1 -0
  55. package/package.json +11 -14
  56. package/shared/CellMenu.svelte +1 -1
  57. package/shared/FilterMenu.svelte +1 -2
  58. package/shared/Table.svelte +9 -7
  59. package/shared/TableCell.svelte +2 -2
  60. package/shared/Toolbar.svelte +1 -0
  61. package/shared/VirtualTable.svelte +11 -2
  62. package/shared/context/dataframe_context.ts +1 -1
  63. package/shared/utils/data_processing.ts +1 -1
  64. package/shared/utils/drag_utils.ts +1 -1
  65. package/shared/utils/keyboard_utils.ts +5 -5
  66. package/shared/{selection_utils.ts → utils/selection_utils.ts} +1 -1
  67. package/shared/{utils.ts → utils/utils.ts} +11 -2
  68. package/standalone/Index.svelte +688 -0
  69. package/standalone/default_i18n.ts +32 -0
  70. package/standalone/stubs/Upload.svelte +19 -0
  71. package/standalone/stubs/upload.ts +1 -0
  72. package/test/table_utils.test.ts +1 -1
  73. /package/dist/shared/{selection_utils.js → utils/selection_utils.js} +0 -0
  74. /package/dist/shared/{utils.js → utils/utils.js} +0 -0
@@ -1,13 +1,13 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
- show_fullscreen_button?: boolean | undefined;
5
- show_copy_button?: boolean | undefined;
6
- show_search?: ("none" | "search" | "filter") | undefined;
7
- fullscreen?: boolean | undefined;
4
+ show_fullscreen_button?: boolean;
5
+ show_copy_button?: boolean;
6
+ show_search?: "none" | "search" | "filter";
7
+ fullscreen?: boolean;
8
8
  on_copy: () => Promise<void>;
9
9
  on_commit_filter: () => void;
10
- current_search_query?: (string | null) | undefined;
10
+ current_search_query?: string | null;
11
11
  };
12
12
  events: {
13
13
  fullscreen: CustomEvent<boolean>;
@@ -16,6 +16,8 @@ declare const __propDef: {
16
16
  [evt: string]: CustomEvent<any>;
17
17
  };
18
18
  slots: {};
19
+ exports?: {} | undefined;
20
+ bindings?: string | undefined;
19
21
  };
20
22
  export type ToolbarProps = typeof __propDef.props;
21
23
  export type ToolbarEvents = typeof __propDef.events;
@@ -1,5 +1,4 @@
1
1
  <script>import { onMount, tick, createEventDispatcher } from "svelte";
2
- import { _ } from "svelte-i18n";
3
2
  export let items = [];
4
3
  export let max_height;
5
4
  export let actual_height;
@@ -10,6 +9,7 @@ export let selected;
10
9
  export let disable_scroll = false;
11
10
  export let show_scroll_button = false;
12
11
  export let viewport;
12
+ export let label = null;
13
13
  const dispatch = createEventDispatcher();
14
14
  let height = "100%";
15
15
  let average_height = 30;
@@ -24,8 +24,7 @@ let top = 0;
24
24
  let viewport_height = 200;
25
25
  let visible = [];
26
26
  let viewport_box;
27
- $:
28
- viewport_height = viewport_box?.height || 200;
27
+ $: viewport_height = viewport_box?.height || 200;
29
28
  const is_browser = typeof window !== "undefined";
30
29
  const raf = is_browser ? window.requestAnimationFrame : (cb) => cb();
31
30
  $: {
@@ -34,6 +33,9 @@ $: {
34
33
  }
35
34
  }
36
35
  async function refresh_height_map() {
36
+ if (!viewport) {
37
+ return;
38
+ }
37
39
  if (sortedItems.length < start) {
38
40
  await scroll_to_index(sortedItems.length - 1, { behavior: "auto" });
39
41
  }
@@ -87,12 +89,10 @@ async function refresh_height_map() {
87
89
  actual_height = content_height;
88
90
  }
89
91
  }
90
- $:
91
- scroll_and_render(selected);
92
+ $: scroll_and_render(selected);
92
93
  async function scroll_and_render(n) {
93
94
  raf(async () => {
94
- if (typeof n !== "number")
95
- return;
95
+ if (typeof n !== "number") return;
96
96
  const direction = typeof n !== "number" ? false : is_in_view(n);
97
97
  if (direction === true) {
98
98
  return;
@@ -141,14 +141,12 @@ export async function scroll_to_index(index, opts, align_end = false) {
141
141
  };
142
142
  viewport.scrollTo(_opts);
143
143
  }
144
- $:
145
- sortedItems = items;
146
- $:
147
- visible = is_browser ? sortedItems.slice(start, end).map((data, i) => {
148
- return { index: i + start, data };
149
- }) : sortedItems.slice(0, max_height / sortedItems.length * average_height + 1).map((data, i) => {
150
- return { index: i + start, data };
151
- });
144
+ $: sortedItems = items;
145
+ $: visible = is_browser ? sortedItems.slice(start, end).map((data, i) => {
146
+ return { index: i + start, data };
147
+ }) : sortedItems.slice(0, max_height / sortedItems.length * average_height + 1).map((data, i) => {
148
+ return { index: i + start, data };
149
+ });
152
150
  onMount(() => {
153
151
  rows = contents.children;
154
152
  mounted = true;
@@ -165,6 +163,9 @@ onMount(() => {
165
163
  on:scroll={refresh_height_map}
166
164
  style="height: {height}; --bw-svt-p-top: {top}px; --bw-svt-p-bottom: {bottom}px; --bw-svt-head-height: {head_height}px; --bw-svt-foot-height: {foot_height}px; --bw-svt-avg-row-height: {average_height}px; --max-height: {max_height}px"
167
165
  >
166
+ {#if label && label.length !== 0}
167
+ <caption class="sr-only">{label}</caption>
168
+ {/if}
168
169
  <thead class="thead" bind:offsetHeight={head_height}>
169
170
  <slot name="thead" />
170
171
  </thead>
@@ -172,7 +173,9 @@ onMount(() => {
172
173
  {#if visible.length && visible[0].data.length}
173
174
  {#each visible as item (item.data[0].id)}
174
175
  <slot name="tbody" item={item.data} index={item.index}>
175
- Missing Table Row
176
+ <tr>
177
+ <td>Missing Table Row</td>
178
+ </tr>
176
179
  </slot>
177
180
  {/each}
178
181
  {/if}
@@ -1,17 +1,18 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
- items?: any[][] | undefined;
4
+ items?: any[][];
5
5
  max_height: number;
6
6
  actual_height: number;
7
7
  table_scrollbar_width: number;
8
- start?: number | undefined;
9
- end?: number | undefined;
8
+ start?: number;
9
+ end?: number;
10
10
  selected: number | false;
11
- disable_scroll?: boolean | undefined;
12
- show_scroll_button?: boolean | undefined;
11
+ disable_scroll?: boolean;
12
+ show_scroll_button?: boolean;
13
13
  viewport: HTMLTableElement;
14
- scroll_to_index?: ((index: number, opts: ScrollToOptions, align_end?: boolean) => Promise<void>) | undefined;
14
+ label?: string | null;
15
+ scroll_to_index?: (index: number, opts: ScrollToOptions, align_end?: boolean) => Promise<void>;
15
16
  };
16
17
  events: {
17
18
  scroll_top: CustomEvent<number>;
@@ -26,6 +27,8 @@ declare const __propDef: {
26
27
  };
27
28
  tfoot: {};
28
29
  };
30
+ exports?: {} | undefined;
31
+ bindings?: string | undefined;
29
32
  };
30
33
  export type VirtualTableProps = typeof __propDef.props;
31
34
  export type VirtualTableEvents = typeof __propDef.events;
@@ -1,5 +1,5 @@
1
1
  import { writable } from "svelte/store";
2
- import { get_next_cell_coordinates, get_range_selection, move_cursor } from "../selection_utils";
2
+ import { get_next_cell_coordinates, get_range_selection, move_cursor } from "../utils/selection_utils";
3
3
  export declare const DATAFRAME_KEY: unique symbol;
4
4
  export type SortDirection = "asc" | "desc";
5
5
  export type FilterDatatype = "string" | "number";
@@ -3,7 +3,7 @@ import { dequal } from "dequal";
3
3
  import { writable, get } from "svelte/store";
4
4
  import { sort_table_data } from "../utils/table_utils";
5
5
  import { tick } from "svelte";
6
- import { handle_selection, get_next_cell_coordinates, get_range_selection, move_cursor } from "../selection_utils";
6
+ import { handle_selection, get_next_cell_coordinates, get_range_selection, move_cursor } from "../utils/selection_utils";
7
7
  export const DATAFRAME_KEY = Symbol("dataframe");
8
8
  function create_actions(state, context) {
9
9
  const update_state = (updater) => state.update((s) => ({ ...s, ...updater(s) }));
@@ -1,12 +1,12 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  declare const __propDef: {
3
- props: {
4
- [x: string]: never;
5
- };
3
+ props: Record<string, never>;
6
4
  events: {
7
5
  [evt: string]: CustomEvent<any>;
8
6
  };
9
7
  slots: {};
8
+ exports?: {} | undefined;
9
+ bindings?: string | undefined;
10
10
  };
11
11
  export type FilterIconProps = typeof __propDef.props;
12
12
  export type FilterIconEvents = typeof __propDef.events;
@@ -19,5 +19,7 @@ declare const __propDef: {
19
19
  [evt: string]: CustomEvent<any>;
20
20
  };
21
21
  slots: {};
22
+ exports?: undefined;
23
+ bindings?: undefined;
22
24
  };
23
25
  export {};
@@ -1,10 +1,8 @@
1
1
  <script>export let position;
2
2
  export let coords;
3
3
  export let on_click = null;
4
- $:
5
- is_first_position = position === "column" ? coords[0] === 0 : coords[1] === 0;
6
- $:
7
- direction = position === "column" ? is_first_position ? "down" : "up" : is_first_position ? "right" : "left";
4
+ $: is_first_position = position === "column" ? coords[0] === 0 : coords[1] === 0;
5
+ $: direction = position === "column" ? is_first_position ? "down" : "up" : is_first_position ? "right" : "left";
8
6
  </script>
9
7
 
10
8
  <button
@@ -3,12 +3,14 @@ declare const __propDef: {
3
3
  props: {
4
4
  position: "column" | "row";
5
5
  coords: [number, number];
6
- on_click?: ((() => void) | null) | undefined;
6
+ on_click?: (() => void) | null;
7
7
  };
8
8
  events: {
9
9
  [evt: string]: CustomEvent<any>;
10
10
  };
11
11
  slots: {};
12
+ exports?: {} | undefined;
13
+ bindings?: string | undefined;
12
14
  };
13
15
  export type SelectionButtonsProps = typeof __propDef.props;
14
16
  export type SelectionButtonsEvents = typeof __propDef.events;
@@ -1,12 +1,14 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
- size?: number | undefined;
4
+ size?: number;
5
5
  };
6
6
  events: {
7
7
  [evt: string]: CustomEvent<any>;
8
8
  };
9
9
  slots: {};
10
+ exports?: {} | undefined;
11
+ bindings?: string | undefined;
10
12
  };
11
13
  export type SortArrowDownProps = typeof __propDef.props;
12
14
  export type SortArrowDownEvents = typeof __propDef.events;
@@ -1,12 +1,14 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
- size?: number | undefined;
4
+ size?: number;
5
5
  };
6
6
  events: {
7
7
  [evt: string]: CustomEvent<any>;
8
8
  };
9
9
  slots: {};
10
+ exports?: {} | undefined;
11
+ bindings?: string | undefined;
10
12
  };
11
13
  export type SortArrowUpProps = typeof __propDef.props;
12
14
  export type SortArrowUpEvents = typeof __propDef.events;
@@ -19,5 +19,7 @@ declare const __propDef: {
19
19
  [evt: string]: CustomEvent<any>;
20
20
  };
21
21
  slots: {};
22
+ exports?: undefined;
23
+ bindings?: undefined;
22
24
  };
23
25
  export {};
@@ -19,5 +19,7 @@ declare const __propDef: {
19
19
  [evt: string]: CustomEvent<any>;
20
20
  };
21
21
  slots: {};
22
+ exports?: undefined;
23
+ bindings?: undefined;
22
24
  };
23
25
  export {};
@@ -2,8 +2,8 @@ import { SvelteComponent } from "svelte";
2
2
  import type { I18nFormatter } from "@gradio/utils";
3
3
  declare const __propDef: {
4
4
  props: {
5
- direction?: (("asc" | "desc") | null) | undefined;
6
- priority?: (number | null) | undefined;
5
+ direction?: ("asc" | "desc") | null;
6
+ priority?: number | null;
7
7
  i18n: I18nFormatter;
8
8
  };
9
9
  events: {
@@ -12,6 +12,8 @@ declare const __propDef: {
12
12
  [evt: string]: CustomEvent<any>;
13
13
  };
14
14
  slots: {};
15
+ exports?: {} | undefined;
16
+ bindings?: string | undefined;
15
17
  };
16
18
  export type SortIconProps = typeof __propDef.props;
17
19
  export type SortIconEvents = typeof __propDef.events;
@@ -1,4 +1,4 @@
1
- import type { Headers, HeadersWithIDs } from "../utils";
1
+ import type { Headers, HeadersWithIDs } from "./utils";
2
2
  export declare function make_headers(_head: Headers, col_count: [number, "fixed" | "dynamic"], els: Record<string, {
3
3
  cell: null | HTMLTableCellElement;
4
4
  input: null | HTMLTextAreaElement;
@@ -1,4 +1,4 @@
1
- import { get_range_selection } from "../selection_utils";
1
+ import { get_range_selection } from "../utils/selection_utils";
2
2
  export function create_drag_handlers(state, set_is_dragging, set_selected_cells, set_selected, handle_cell_click, show_row_numbers, parent_element) {
3
3
  const start_drag = (event, row, col) => {
4
4
  const target = event.target;
@@ -1,5 +1,5 @@
1
1
  import { dequal } from "dequal/lite";
2
- import { handle_delete_key } from "../selection_utils";
2
+ import { handle_delete_key } from "../utils/selection_utils";
3
3
  import { tick } from "svelte";
4
4
  import { get } from "svelte/store";
5
5
  import { copy_table_data } from "./table_utils";
@@ -8,6 +8,9 @@ async function save_cell_value(input_value, ctx, row, col) {
8
8
  return;
9
9
  const old_value = ctx.data[row][col].value;
10
10
  ctx.data[row][col].value = input_value;
11
+ if (ctx.data[row][col].display_value !== undefined) {
12
+ ctx.data[row][col].display_value = input_value;
13
+ }
11
14
  if (old_value !== input_value && ctx.dispatch) {
12
15
  ctx.dispatch("change", {
13
16
  data: ctx.data.map((row) => row.map((cell) => cell.value)),
@@ -173,8 +176,7 @@ function handle_default_key(event, ctx, i, j) {
173
176
  if (!state.config.editable)
174
177
  return false;
175
178
  const editing = state.ui_state.editing;
176
- if ((!editing || (editing && dequal(editing, [i, j]))) &&
177
- event.key.length === 1) {
179
+ if (event.key.length === 1 && (!editing || !dequal(editing, [i, j]))) {
178
180
  ctx.actions.set_editing([i, j]);
179
181
  return true;
180
182
  }
@@ -1,4 +1,4 @@
1
- import type { CellCoordinate } from "./types";
1
+ import type { CellCoordinate } from "./../types";
2
2
  export type CellData = {
3
3
  id: string;
4
4
  value: string | number;
@@ -1,6 +1,6 @@
1
1
  export type Headers = string[];
2
2
  export type Data = (string | number)[][];
3
- export type Datatype = "str" | "markdown" | "html" | "number" | "bool" | "date";
3
+ export type Datatype = "str" | "number" | "bool" | "date" | "markdown" | "html" | "image";
4
4
  export type Metadata = {
5
5
  [key: string]: string[][] | null;
6
6
  } | null;
@@ -11,7 +11,7 @@ export type HeadersWithIDs = {
11
11
  export type DataframeValue = {
12
12
  data: Data;
13
13
  headers: Headers;
14
- metadata: Metadata;
14
+ metadata?: Metadata;
15
15
  };
16
16
  /**
17
17
  * Coerce a value to a given type.