@gradio/dataframe 0.16.5 → 0.17.1

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 (87) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/Dataframe.stories.svelte +202 -9
  3. package/Index.svelte +7 -13
  4. package/dist/Index.svelte +5 -9
  5. package/dist/Index.svelte.d.ts +9 -2
  6. package/dist/shared/CellMenu.svelte +91 -10
  7. package/dist/shared/CellMenu.svelte.d.ts +6 -0
  8. package/dist/shared/CellMenuButton.svelte +45 -0
  9. package/dist/shared/CellMenuButton.svelte.d.ts +16 -0
  10. package/dist/shared/CellMenuIcons.svelte +79 -0
  11. package/dist/shared/EditableCell.svelte +83 -14
  12. package/dist/shared/EditableCell.svelte.d.ts +12 -3
  13. package/dist/shared/EmptyRowButton.svelte +28 -0
  14. package/dist/shared/EmptyRowButton.svelte.d.ts +16 -0
  15. package/dist/shared/RowNumber.svelte +40 -0
  16. package/dist/shared/RowNumber.svelte.d.ts +17 -0
  17. package/dist/shared/Table.svelte +564 -1121
  18. package/dist/shared/Table.svelte.d.ts +4 -0
  19. package/dist/shared/TableCell.svelte +291 -0
  20. package/dist/shared/TableCell.svelte.d.ts +57 -0
  21. package/dist/shared/TableHeader.svelte +239 -0
  22. package/dist/shared/TableHeader.svelte.d.ts +45 -0
  23. package/dist/shared/Toolbar.svelte +18 -8
  24. package/dist/shared/VirtualTable.svelte +66 -19
  25. package/dist/shared/VirtualTable.svelte.d.ts +4 -0
  26. package/dist/shared/context/keyboard_context.d.ts +37 -0
  27. package/dist/shared/context/keyboard_context.js +12 -0
  28. package/dist/shared/context/selection_context.d.ts +32 -0
  29. package/dist/shared/context/selection_context.js +107 -0
  30. package/dist/shared/context/table_context.d.ts +141 -0
  31. package/dist/shared/context/table_context.js +375 -0
  32. package/dist/shared/icons/Padlock.svelte +24 -0
  33. package/dist/shared/icons/Padlock.svelte.d.ts +23 -0
  34. package/dist/shared/icons/SelectionButtons.svelte +85 -0
  35. package/dist/shared/icons/SelectionButtons.svelte.d.ts +18 -0
  36. package/dist/shared/icons/SortArrowDown.svelte +24 -0
  37. package/dist/shared/icons/SortArrowDown.svelte.d.ts +16 -0
  38. package/dist/shared/icons/SortArrowUp.svelte +24 -0
  39. package/dist/shared/icons/SortArrowUp.svelte.d.ts +16 -0
  40. package/dist/shared/icons/SortButtonDown.svelte +14 -0
  41. package/dist/shared/icons/SortButtonDown.svelte.d.ts +23 -0
  42. package/dist/shared/icons/SortButtonUp.svelte +15 -0
  43. package/dist/shared/icons/SortButtonUp.svelte.d.ts +23 -0
  44. package/dist/shared/icons/SortIcon.svelte +46 -68
  45. package/dist/shared/icons/SortIcon.svelte.d.ts +3 -2
  46. package/dist/shared/selection_utils.d.ts +2 -1
  47. package/dist/shared/selection_utils.js +39 -10
  48. package/dist/shared/utils/data_processing.d.ts +13 -0
  49. package/dist/shared/utils/data_processing.js +45 -0
  50. package/dist/shared/utils/drag_utils.d.ts +15 -0
  51. package/dist/shared/utils/drag_utils.js +57 -0
  52. package/dist/shared/utils/keyboard_utils.d.ts +2 -0
  53. package/dist/shared/utils/keyboard_utils.js +186 -0
  54. package/dist/shared/utils/sort_utils.d.ts +22 -3
  55. package/dist/shared/utils/sort_utils.js +44 -24
  56. package/dist/shared/utils/table_utils.d.ts +6 -5
  57. package/dist/shared/utils/table_utils.js +13 -56
  58. package/package.json +7 -7
  59. package/shared/CellMenu.svelte +90 -10
  60. package/shared/CellMenuButton.svelte +46 -0
  61. package/shared/CellMenuIcons.svelte +79 -0
  62. package/shared/EditableCell.svelte +97 -18
  63. package/shared/EmptyRowButton.svelte +29 -0
  64. package/shared/RowNumber.svelte +41 -0
  65. package/shared/Table.svelte +604 -1235
  66. package/shared/TableCell.svelte +324 -0
  67. package/shared/TableHeader.svelte +256 -0
  68. package/shared/Toolbar.svelte +19 -8
  69. package/shared/VirtualTable.svelte +72 -19
  70. package/shared/context/keyboard_context.ts +65 -0
  71. package/shared/context/selection_context.ts +168 -0
  72. package/shared/context/table_context.ts +625 -0
  73. package/shared/icons/Padlock.svelte +24 -0
  74. package/shared/icons/SelectionButtons.svelte +93 -0
  75. package/shared/icons/SortArrowDown.svelte +25 -0
  76. package/shared/icons/SortArrowUp.svelte +25 -0
  77. package/shared/icons/SortButtonDown.svelte +14 -0
  78. package/shared/icons/SortButtonUp.svelte +15 -0
  79. package/shared/icons/SortIcon.svelte +47 -70
  80. package/shared/selection_utils.ts +39 -13
  81. package/shared/utils/data_processing.ts +72 -0
  82. package/shared/utils/drag_utils.ts +92 -0
  83. package/shared/utils/keyboard_utils.ts +238 -0
  84. package/shared/utils/sort_utils.test.ts +262 -14
  85. package/shared/utils/sort_utils.ts +67 -31
  86. package/shared/utils/table_utils.test.ts +66 -45
  87. package/shared/utils/table_utils.ts +16 -86
@@ -0,0 +1,16 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ on_click: (event: MouseEvent) => void;
5
+ };
6
+ events: {
7
+ [evt: string]: CustomEvent<any>;
8
+ };
9
+ slots: {};
10
+ };
11
+ export type CellMenuButtonProps = typeof __propDef.props;
12
+ export type CellMenuButtonEvents = typeof __propDef.events;
13
+ export type CellMenuButtonSlots = typeof __propDef.slots;
14
+ export default class CellMenuButton extends SvelteComponent<CellMenuButtonProps, CellMenuButtonEvents, CellMenuButtonSlots> {
15
+ }
16
+ export {};
@@ -109,4 +109,83 @@
109
109
  stroke-linecap="round"
110
110
  />
111
111
  </svg>
112
+ {:else if icon == "sort-asc"}
113
+ <svg viewBox="0 0 24 24" width="16" height="16">
114
+ <path
115
+ d="M8 16L12 12L16 16"
116
+ stroke="currentColor"
117
+ stroke-width="2"
118
+ fill="none"
119
+ stroke-linecap="round"
120
+ stroke-linejoin="round"
121
+ />
122
+ <path
123
+ d="M12 12V19"
124
+ stroke="currentColor"
125
+ stroke-width="2"
126
+ stroke-linecap="round"
127
+ />
128
+ <path
129
+ d="M5 7H19"
130
+ stroke="currentColor"
131
+ stroke-width="2"
132
+ stroke-linecap="round"
133
+ />
134
+ </svg>
135
+ {:else if icon == "sort-desc"}
136
+ <svg viewBox="0 0 24 24" width="16" height="16">
137
+ <path
138
+ d="M8 12L12 16L16 12"
139
+ stroke="currentColor"
140
+ stroke-width="2"
141
+ fill="none"
142
+ stroke-linecap="round"
143
+ stroke-linejoin="round"
144
+ />
145
+ <path
146
+ d="M12 16V9"
147
+ stroke="currentColor"
148
+ stroke-width="2"
149
+ stroke-linecap="round"
150
+ />
151
+ <path
152
+ d="M5 5H19"
153
+ stroke="currentColor"
154
+ stroke-width="2"
155
+ stroke-linecap="round"
156
+ />
157
+ </svg>
158
+ {:else if icon == "clear-sort"}
159
+ <svg viewBox="0 0 24 24" width="16" height="16">
160
+ <path
161
+ d="M5 5H19"
162
+ stroke="currentColor"
163
+ stroke-width="2"
164
+ stroke-linecap="round"
165
+ />
166
+ <path
167
+ d="M5 9H15"
168
+ stroke="currentColor"
169
+ stroke-width="2"
170
+ stroke-linecap="round"
171
+ />
172
+ <path
173
+ d="M5 13H11"
174
+ stroke="currentColor"
175
+ stroke-width="2"
176
+ stroke-linecap="round"
177
+ />
178
+ <path
179
+ d="M5 17H7"
180
+ stroke="currentColor"
181
+ stroke-width="2"
182
+ stroke-linecap="round"
183
+ />
184
+ <path
185
+ d="M17 17L21 21M21 17L17 21"
186
+ stroke="currentColor"
187
+ stroke-width="2"
188
+ stroke-linecap="round"
189
+ />
190
+ </svg>
112
191
  {/if}
@@ -1,5 +1,6 @@
1
1
  <script>import { createEventDispatcher } from "svelte";
2
2
  import { MarkdownCode } from "@gradio/markdown-code";
3
+ import SelectionButtons from "./icons/SelectionButtons.svelte";
3
4
  export let edit;
4
5
  export let value = "";
5
6
  export let display_value = null;
@@ -10,21 +11,37 @@ export let latex_delimiters;
10
11
  export let clear_on_focus = false;
11
12
  export let line_breaks = true;
12
13
  export let editable = true;
14
+ export let is_static = false;
13
15
  export let root;
14
16
  export let max_chars = null;
17
+ export let components = {};
18
+ export let i18n;
19
+ export let is_dragging = false;
20
+ export let show_selection_buttons = false;
21
+ export let coords = null;
22
+ export let on_select_column = null;
23
+ export let on_select_row = null;
15
24
  const dispatch = createEventDispatcher();
16
25
  let is_expanded = false;
17
26
  export let el;
18
27
  $:
19
28
  _value = value;
20
- function truncate_text(text, max_length = null) {
29
+ function truncate_text(text, max_length = null, is_image = false) {
30
+ if (is_image)
31
+ return String(text);
21
32
  const str = String(text);
22
- if (!max_length || str.length <= max_length)
33
+ if (!max_length || max_length <= 0)
34
+ return str;
35
+ if (str.length <= max_length)
23
36
  return str;
24
37
  return str.slice(0, max_length) + "...";
25
38
  }
26
39
  $:
27
- display_text = is_expanded ? value : truncate_text(display_value || value, max_chars);
40
+ should_truncate = !edit && !is_expanded && max_chars !== null && max_chars > 0;
41
+ $:
42
+ display_content = editable ? value : display_value !== null ? display_value : value;
43
+ $:
44
+ display_text = should_truncate ? truncate_text(display_content, max_chars, datatype === "image") : display_content;
28
45
  function use_focus(node) {
29
46
  if (clear_on_focus) {
30
47
  _value = "";
@@ -60,7 +77,10 @@ function handle_click() {
60
77
 
61
78
  {#if edit}
62
79
  <input
80
+ readonly={is_static}
81
+ aria-readonly={is_static}
63
82
  role="textbox"
83
+ aria-label={is_static ? "Cell is read-only" : "Edit cell"}
64
84
  bind:this={el}
65
85
  bind:value={_value}
66
86
  class:header
@@ -75,6 +95,7 @@ function handle_click() {
75
95
  {/if}
76
96
 
77
97
  <span
98
+ class:dragging={is_dragging}
78
99
  on:click={handle_click}
79
100
  on:keydown={handle_keydown}
80
101
  tabindex="0"
@@ -85,9 +106,22 @@ function handle_click() {
85
106
  on:focus|preventDefault
86
107
  style={styling}
87
108
  data-editable={editable}
109
+ data-max-chars={max_chars}
110
+ data-expanded={is_expanded}
88
111
  placeholder=" "
112
+ class:text={datatype === "str"}
89
113
  >
90
- {#if datatype === "html"}
114
+ {#if datatype === "image" && components.image}
115
+ <svelte:component
116
+ this={components.image}
117
+ value={{ url: display_text }}
118
+ show_label={false}
119
+ label="cell-image"
120
+ show_download_button={false}
121
+ {i18n}
122
+ gradio={{ dispatch: () => {} }}
123
+ />
124
+ {:else if datatype === "html"}
91
125
  {@html display_text}
92
126
  {:else if datatype === "markdown"}
93
127
  <MarkdownCode
@@ -98,23 +132,36 @@ function handle_click() {
98
132
  {root}
99
133
  />
100
134
  {:else}
101
- {editable ? display_text : display_value || display_text}
135
+ {display_text}
102
136
  {/if}
103
137
  </span>
138
+ {#if show_selection_buttons && coords && on_select_column && on_select_row}
139
+ <SelectionButtons
140
+ position="column"
141
+ {coords}
142
+ on_click={() => on_select_column(coords[1])}
143
+ />
144
+ <SelectionButtons
145
+ position="row"
146
+ {coords}
147
+ on_click={() => on_select_row(coords[0])}
148
+ />
149
+ {/if}
104
150
 
105
151
  <style>
152
+ .dragging {
153
+ cursor: crosshair !important;
154
+ }
155
+
106
156
  input {
107
157
  position: absolute;
108
- top: var(--size-2);
109
- right: var(--size-2);
110
- bottom: var(--size-2);
111
- left: var(--size-2);
112
158
  flex: 1 1 0%;
113
159
  transform: translateX(-0.1px);
114
160
  outline: none;
115
161
  border: none;
116
162
  background: transparent;
117
163
  cursor: text;
164
+ width: calc(100% - var(--size-2));
118
165
  }
119
166
 
120
167
  span {
@@ -129,25 +176,37 @@ function handle_click() {
129
176
  cursor: text;
130
177
  width: 100%;
131
178
  height: 100%;
179
+ overflow: hidden;
180
+ text-overflow: ellipsis;
181
+ white-space: nowrap;
182
+ }
183
+
184
+ span.text:not(.expanded) {
185
+ overflow: hidden;
186
+ text-overflow: ellipsis;
187
+ white-space: nowrap;
132
188
  }
133
189
 
134
- span.expanded {
190
+ span.text.expanded {
135
191
  height: auto;
136
192
  min-height: 100%;
137
193
  white-space: pre-wrap;
138
194
  word-break: break-word;
139
- white-space: normal;
195
+ overflow: visible;
140
196
  }
141
197
 
142
198
  .multiline {
143
- white-space: pre-line;
199
+ white-space: pre;
200
+ overflow: hidden;
201
+ text-overflow: ellipsis;
144
202
  }
145
203
 
146
204
  .header {
147
205
  transform: translateX(0);
148
206
  font-weight: var(--weight-bold);
149
- white-space: normal;
150
- word-break: break-word;
207
+ white-space: nowrap;
208
+ overflow: hidden;
209
+ text-overflow: ellipsis;
151
210
  margin-left: var(--size-1);
152
211
  }
153
212
 
@@ -155,4 +214,14 @@ function handle_click() {
155
214
  opacity: 0;
156
215
  pointer-events: none;
157
216
  }
217
+
218
+ span :global(img) {
219
+ max-height: 100px;
220
+ width: auto;
221
+ object-fit: contain;
222
+ }
223
+
224
+ input:read-only {
225
+ cursor: not-allowed;
226
+ }
158
227
  </style>
@@ -1,4 +1,5 @@
1
1
  import { SvelteComponent } from "svelte";
2
+ import type { I18nFormatter } from "@gradio/utils";
2
3
  declare const __propDef: {
3
4
  props: {
4
5
  edit: boolean;
@@ -6,7 +7,7 @@ declare const __propDef: {
6
7
  display_value?: (string | null) | undefined;
7
8
  styling?: string | undefined;
8
9
  header?: boolean | undefined;
9
- datatype?: ("str" | "markdown" | "html" | "number" | "bool" | "date") | undefined;
10
+ datatype?: ("str" | "markdown" | "html" | "number" | "bool" | "date" | "image") | undefined;
10
11
  latex_delimiters: {
11
12
  left: string;
12
13
  right: string;
@@ -15,8 +16,16 @@ declare const __propDef: {
15
16
  clear_on_focus?: boolean | undefined;
16
17
  line_breaks?: boolean | undefined;
17
18
  editable?: boolean | undefined;
19
+ is_static?: boolean | undefined;
18
20
  root: string;
19
21
  max_chars?: (number | null) | undefined;
22
+ components?: Record<string, any> | undefined;
23
+ i18n: I18nFormatter;
24
+ is_dragging?: boolean | undefined;
25
+ show_selection_buttons?: boolean | undefined;
26
+ coords?: ([number, number] | null) | undefined;
27
+ on_select_column?: (((col: number) => void) | null) | undefined;
28
+ on_select_row?: (((row: number) => void) | null) | undefined;
20
29
  el: HTMLInputElement | null;
21
30
  };
22
31
  events: {
@@ -24,8 +33,8 @@ declare const __propDef: {
24
33
  mouseup: MouseEvent;
25
34
  click: MouseEvent;
26
35
  focus: FocusEvent;
27
- blur: CustomEvent<any>;
28
- keydown: CustomEvent<any>;
36
+ blur: CustomEvent<void>;
37
+ keydown: CustomEvent<KeyboardEvent>;
29
38
  } & {
30
39
  [evt: string]: CustomEvent<any>;
31
40
  };
@@ -0,0 +1,28 @@
1
+ <script>export let on_click;
2
+ </script>
3
+
4
+ <button class="add-row-button" on:click={on_click} aria-label="Add row">
5
+ +
6
+ </button>
7
+
8
+ <style>
9
+ .add-row-button {
10
+ width: 100%;
11
+ padding: var(--size-1);
12
+ background: transparent;
13
+ border: 1px dashed var(--border-color-primary);
14
+ border-radius: var(--radius-sm);
15
+ color: var(--body-text-color);
16
+ cursor: pointer;
17
+ transition: all 150ms;
18
+ margin-top: var(--size-2);
19
+ z-index: 10;
20
+ position: relative;
21
+ pointer-events: auto;
22
+ }
23
+
24
+ .add-row-button:hover {
25
+ background: var(--background-fill-secondary);
26
+ border-style: solid;
27
+ }
28
+ </style>
@@ -0,0 +1,16 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ on_click: () => void;
5
+ };
6
+ events: {
7
+ [evt: string]: CustomEvent<any>;
8
+ };
9
+ slots: {};
10
+ };
11
+ export type EmptyRowButtonProps = typeof __propDef.props;
12
+ export type EmptyRowButtonEvents = typeof __propDef.events;
13
+ export type EmptyRowButtonSlots = typeof __propDef.slots;
14
+ export default class EmptyRowButton extends SvelteComponent<EmptyRowButtonProps, EmptyRowButtonEvents, EmptyRowButtonSlots> {
15
+ }
16
+ export {};
@@ -0,0 +1,40 @@
1
+ <script>export let index = null;
2
+ export let is_header = false;
3
+ </script>
4
+
5
+ {#if is_header}
6
+ <th tabindex="-1" class="row-number">
7
+ <div class="cell-wrap">
8
+ <div class="header-content">
9
+ <div class="header-text"></div>
10
+ </div>
11
+ </div>
12
+ </th>
13
+ {:else}
14
+ <td class="row-number" tabindex="-1" data-row={index} data-col="row-number">
15
+ {index !== null ? index + 1 : ""}
16
+ </td>
17
+ {/if}
18
+
19
+ <style>
20
+ .row-number {
21
+ text-align: center;
22
+ padding: var(--size-1);
23
+ min-width: var(--size-12);
24
+ width: var(--size-12);
25
+ overflow: hidden;
26
+ text-overflow: ellipsis;
27
+ white-space: nowrap;
28
+ font-weight: var(--weight-semibold);
29
+ background: var(--table-even-background-fill);
30
+ border-right: 1px solid var(--border-color-primary);
31
+ }
32
+
33
+ :global(tr:nth-child(odd)) .row-number {
34
+ background: var(--table-odd-background-fill);
35
+ }
36
+
37
+ :global(tr:nth-child(even)) .row-number {
38
+ background: var(--table-even-background-fill);
39
+ }
40
+ </style>
@@ -0,0 +1,17 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ index?: (number | null) | undefined;
5
+ is_header?: boolean | undefined;
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {};
11
+ };
12
+ export type RowNumberProps = typeof __propDef.props;
13
+ export type RowNumberEvents = typeof __propDef.events;
14
+ export type RowNumberSlots = typeof __propDef.slots;
15
+ export default class RowNumber extends SvelteComponent<RowNumberProps, RowNumberEvents, RowNumberSlots> {
16
+ }
17
+ export {};