@gradio/dataframe 0.19.2 → 0.19.4

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 (39) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/Index.svelte +3 -1
  3. package/dist/Index.svelte +1 -0
  4. package/dist/Index.svelte.d.ts +6 -3
  5. package/dist/shared/BooleanCell.svelte +1 -2
  6. package/dist/shared/BooleanCell.svelte.d.ts +1 -1
  7. package/dist/shared/EditableCell.svelte +7 -18
  8. package/dist/shared/EditableCell.svelte.d.ts +2 -1
  9. package/dist/shared/Table.svelte +23 -13
  10. package/dist/shared/Table.svelte.d.ts +4 -2
  11. package/dist/shared/TableCell.svelte.d.ts +2 -1
  12. package/dist/shared/TableHeader.svelte +57 -0
  13. package/dist/shared/TableHeader.svelte.d.ts +7 -0
  14. package/dist/shared/context/dataframe_context.d.ts +9 -8
  15. package/dist/shared/context/dataframe_context.js +9 -1
  16. package/dist/shared/types.d.ts +2 -1
  17. package/dist/shared/utils/data_processing.d.ts +5 -4
  18. package/dist/shared/utils/data_processing.js +4 -2
  19. package/dist/shared/utils/filter_utils.d.ts +5 -4
  20. package/dist/shared/utils/keyboard_utils.js +1 -1
  21. package/dist/shared/utils/selection_utils.d.ts +3 -3
  22. package/dist/shared/utils/sort_utils.d.ts +4 -4
  23. package/dist/shared/utils/table_utils.d.ts +2 -2
  24. package/dist/shared/utils/utils.d.ts +8 -2
  25. package/package.json +8 -8
  26. package/shared/BooleanCell.svelte +2 -5
  27. package/shared/EditableCell.svelte +12 -20
  28. package/shared/Table.svelte +43 -27
  29. package/shared/TableCell.svelte +2 -1
  30. package/shared/TableHeader.svelte +62 -0
  31. package/shared/context/dataframe_context.ts +20 -13
  32. package/shared/types.ts +3 -1
  33. package/shared/utils/data_processing.ts +10 -5
  34. package/shared/utils/filter_utils.ts +5 -4
  35. package/shared/utils/keyboard_utils.ts +1 -6
  36. package/shared/utils/selection_utils.ts +3 -3
  37. package/shared/utils/sort_utils.ts +4 -4
  38. package/shared/utils/table_utils.ts +8 -2
  39. package/shared/utils/utils.ts +10 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # @gradio/dataframe
2
2
 
3
+ ## 0.19.4
4
+
5
+ ### Fixes
6
+
7
+ - [#11648](https://github.com/gradio-app/gradio/pull/11648) [`57d8d65`](https://github.com/gradio-app/gradio/commit/57d8d6598645e438337c78c1c8e0759f876fb193) - Dataframe Edit Event. Thanks @deckar01!
8
+
9
+ ### Dependency updates
10
+
11
+ - @gradio/markdown-code@0.5.2
12
+
13
+ ## 0.19.3
14
+
15
+ ### Features
16
+
17
+ - [#11891](https://github.com/gradio-app/gradio/pull/11891) [`8d06ab7`](https://github.com/gradio-app/gradio/commit/8d06ab7d899cb8b1ab2a9575f19b8960999aba78) - Add select all checkbox for boolean columns in Dataframe. Thanks @abidlabs!
18
+
19
+ ### Fixes
20
+
21
+ - [#11784](https://github.com/gradio-app/gradio/pull/11784) [`d9dd3f5`](https://github.com/gradio-app/gradio/commit/d9dd3f54b7fb34cf7118e549d39fc63937ca3489) - Add "hidden" option to component's `visible` kwarg to render but visually hide the component. Thanks @pngwn!
22
+
23
+ ### Dependency updates
24
+
25
+ - @gradio/statustracker@0.11.1
26
+ - @gradio/atoms@0.18.0
27
+ - @gradio/checkbox@0.4.30
28
+ - @gradio/client@1.19.0
29
+ - @gradio/upload@0.17.0
30
+ - @gradio/button@0.5.13
31
+
3
32
  ## 0.19.2
4
33
 
5
34
  ### Dependency updates
package/Index.svelte CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  export let elem_id = "";
18
18
  export let elem_classes: string[] = [];
19
- export let visible = true;
19
+ export let visible: boolean | "hidden" = true;
20
20
  export let value: DataframeValue = {
21
21
  data: [["", "", ""]],
22
22
  headers: ["1", "2", "3"],
@@ -41,6 +41,7 @@
41
41
  input: never;
42
42
  clear_status: LoadingStatus;
43
43
  search: string | null;
44
+ edit: SelectData;
44
45
  }>;
45
46
  export let latex_delimiters: {
46
47
  left: string;
@@ -95,6 +96,7 @@
95
96
  }}
96
97
  on:input={(e) => gradio.dispatch("input")}
97
98
  on:select={(e) => gradio.dispatch("select", e.detail)}
99
+ on:edit={(e) => gradio.dispatch("edit", e.detail)}
98
100
  on:fullscreen={({ detail }) => {
99
101
  fullscreen = detail;
100
102
  }}
package/dist/Index.svelte CHANGED
@@ -78,6 +78,7 @@ export let fullscreen = false;
78
78
  }}
79
79
  on:input={(e) => gradio.dispatch("input")}
80
80
  on:select={(e) => gradio.dispatch("select", e.detail)}
81
+ on:edit={(e) => gradio.dispatch("edit", e.detail)}
81
82
  on:fullscreen={({ detail }) => {
82
83
  fullscreen = detail;
83
84
  }}
@@ -8,7 +8,7 @@ declare const __propDef: {
8
8
  props: {
9
9
  elem_id?: string;
10
10
  elem_classes?: string[];
11
- visible?: boolean;
11
+ visible?: boolean | "hidden";
12
12
  value?: DataframeValue;
13
13
  value_is_output?: boolean;
14
14
  col_count: [number, "fixed" | "dynamic"];
@@ -28,6 +28,7 @@ declare const __propDef: {
28
28
  input: never;
29
29
  clear_status: LoadingStatus;
30
30
  search: string | null;
31
+ edit: SelectData;
31
32
  }>;
32
33
  latex_delimiters: {
33
34
  left: string;
@@ -63,9 +64,9 @@ export default class Index extends SvelteComponent<IndexProps, IndexEvents, Inde
63
64
  get elem_classes(): string[] | undefined;
64
65
  /**accessor*/
65
66
  set elem_classes(_: string[] | undefined);
66
- get visible(): boolean | undefined;
67
+ get visible(): boolean | "hidden" | undefined;
67
68
  /**accessor*/
68
- set visible(_: boolean | undefined);
69
+ set visible(_: boolean | "hidden" | undefined);
69
70
  get value(): DataframeValue | undefined;
70
71
  /**accessor*/
71
72
  set value(_: DataframeValue | undefined);
@@ -111,6 +112,7 @@ export default class Index extends SvelteComponent<IndexProps, IndexEvents, Inde
111
112
  input: never;
112
113
  clear_status: LoadingStatus;
113
114
  search: string | null;
115
+ edit: SelectData;
114
116
  }>;
115
117
  /**accessor*/
116
118
  set gradio(_: Gradio<{
@@ -119,6 +121,7 @@ export default class Index extends SvelteComponent<IndexProps, IndexEvents, Inde
119
121
  input: never;
120
122
  clear_status: LoadingStatus;
121
123
  search: string | null;
124
+ edit: SelectData;
122
125
  }>);
123
126
  get latex_delimiters(): {
124
127
  left: string;
@@ -2,7 +2,6 @@
2
2
  export let value = false;
3
3
  export let editable = true;
4
4
  export let on_change;
5
- $: bool_value = typeof value === "string" ? value.toLowerCase() === "true" : !!value;
6
5
  function handle_change(event) {
7
6
  if (editable) {
8
7
  on_change(event.detail);
@@ -12,7 +11,7 @@ function handle_change(event) {
12
11
 
13
12
  <div class="bool-cell" role="button" tabindex="-1">
14
13
  <BaseCheckbox
15
- bind:value={bool_value}
14
+ bind:value
16
15
  label=""
17
16
  interactive={editable}
18
17
  on:change={handle_change}
@@ -1,7 +1,7 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
- value?: boolean | string;
4
+ value?: boolean;
5
5
  editable?: boolean;
6
6
  on_change: (value: boolean) => void;
7
7
  };
@@ -48,18 +48,11 @@ function handle_blur(event) {
48
48
  function handle_keydown(event) {
49
49
  dispatch("keydown", event);
50
50
  }
51
- function handle_bool_change(new_value) {
52
- value = new_value.toString();
53
- dispatch("blur", {
54
- blur_event: {
55
- target: {
56
- type: "checkbox",
57
- checked: new_value,
58
- value: new_value.toString()
59
- }
60
- },
61
- coords
62
- });
51
+ function commit_change(checked) {
52
+ handle_blur({ target: { value } });
53
+ }
54
+ $: if (!edit) {
55
+ handle_blur({ target: { value } });
63
56
  }
64
57
  </script>
65
58
 
@@ -80,12 +73,8 @@ function handle_bool_change(new_value) {
80
73
  />
81
74
  {/if}
82
75
 
83
- {#if datatype === "bool"}
84
- <BooleanCell
85
- value={String(display_content)}
86
- {editable}
87
- on_change={handle_bool_change}
88
- />
76
+ {#if datatype === "bool" && typeof value === "boolean"}
77
+ <BooleanCell bind:value {editable} on_change={commit_change} />
89
78
  {:else}
90
79
  <span
91
80
  class:dragging={is_dragging}
@@ -1,9 +1,10 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  import type { I18nFormatter } from "@gradio/utils";
3
+ import type { CellValue } from "./types";
3
4
  declare const __propDef: {
4
5
  props: {
5
6
  edit: boolean;
6
- value?: string | number;
7
+ value?: CellValue;
7
8
  display_value?: string | null;
8
9
  styling?: string;
9
10
  header?: boolean;
@@ -28,7 +28,6 @@ import {
28
28
  handle_file_upload
29
29
  } from "./utils/table_utils";
30
30
  import { make_headers, process_data } from "./utils/data_processing";
31
- import { cast_value_to_type } from "./utils/utils";
32
31
  import { handle_keydown, handle_cell_blur } from "./utils/keyboard_utils";
33
32
  import {
34
33
  create_drag_handlers
@@ -180,7 +179,8 @@ $: if (!dequal(values, old_val)) {
180
179
  els,
181
180
  data_binding,
182
181
  make_id,
183
- display_value
182
+ display_value,
183
+ datatype
184
184
  );
185
185
  old_val = JSON.parse(JSON.stringify(values));
186
186
  if (is_reset || is_different_structure) {
@@ -235,26 +235,18 @@ $: if ($df_state.current_search_query !== void 0) {
235
235
  filtered_to_original_map = [];
236
236
  }
237
237
  let previous_headers = _headers.map((h) => h.value);
238
- let previous_data = data.map((row) => row.map((cell) => String(cell.value)));
238
+ let previous_data = data.map((row) => row.map((cell) => cell.value));
239
239
  $: {
240
240
  if (data || _headers) {
241
241
  df_actions.trigger_change(
242
- data.map(
243
- (row, rowIdx) => row.map((cell, colIdx) => {
244
- const dtype = Array.isArray(datatype) ? datatype[colIdx] : datatype;
245
- return {
246
- ...cell,
247
- value: cast_value_to_type(cell.value, dtype)
248
- };
249
- })
250
- ),
242
+ data,
251
243
  _headers,
252
244
  previous_data,
253
245
  previous_headers,
254
246
  value_is_output,
255
247
  dispatch
256
248
  );
257
- previous_data = data.map((row) => row.map((cell) => String(cell.value)));
249
+ previous_data = data.map((row) => row.map((cell) => cell.value));
258
250
  previous_headers = _headers.map((h) => h.value);
259
251
  }
260
252
  }
@@ -572,6 +564,18 @@ function add_col_at(index, position) {
572
564
  export function reset_sort_state() {
573
565
  df_actions.reset_sort_state();
574
566
  }
567
+ function handle_select_all(col, checked) {
568
+ data = data.map((row) => {
569
+ const new_row = [...row];
570
+ if (new_row[col]) {
571
+ new_row[col] = {
572
+ ...new_row[col],
573
+ value: checked.toString()
574
+ };
575
+ }
576
+ return new_row;
577
+ });
578
+ }
575
579
  let is_dragging = false;
576
580
  let drag_start = null;
577
581
  let mouse_down_pos = null;
@@ -683,6 +687,9 @@ function get_cell_display_value(row, col) {
683
687
  {i18n}
684
688
  bind:el={els[id].input}
685
689
  {col_count}
690
+ datatype={Array.isArray(datatype) ? datatype[i] : datatype}
691
+ {data}
692
+ on_select_all={handle_select_all}
686
693
  />
687
694
  {/each}
688
695
  </tr>
@@ -786,6 +793,9 @@ function get_cell_display_value(row, col) {
786
793
  {i18n}
787
794
  bind:el={els[id].input}
788
795
  {col_count}
796
+ datatype={Array.isArray(datatype) ? datatype[i] : datatype}
797
+ {data}
798
+ on_select_all={handle_select_all}
789
799
  />
790
800
  {/each}
791
801
  </tr>
@@ -2,14 +2,15 @@ import { SvelteComponent } from "svelte";
2
2
  import type { SelectData } from "@gradio/utils";
3
3
  import type { I18nFormatter } from "js/core/src/gradio_helper";
4
4
  import { type Client } from "@gradio/client";
5
- import type { Headers, DataframeValue, Datatype } from "./utils/utils";
5
+ import type { Headers, DataframeValue, Datatype, EditData } from "./utils/utils";
6
+ import type { CellValue } from "./types";
6
7
  declare const __propDef: {
7
8
  props: {
8
9
  datatype: Datatype | Datatype[];
9
10
  label?: string | null;
10
11
  show_label?: boolean;
11
12
  headers?: Headers;
12
- values?: (string | number)[][];
13
+ values?: CellValue[][];
13
14
  col_count: [number, "fixed" | "dynamic"];
14
15
  row_count: [number, "fixed" | "dynamic"];
15
16
  latex_delimiters: {
@@ -46,6 +47,7 @@ declare const __propDef: {
46
47
  input: CustomEvent<undefined>;
47
48
  select: CustomEvent<SelectData>;
48
49
  search: CustomEvent<string | null>;
50
+ edit: CustomEvent<EditData>;
49
51
  } & {
50
52
  [evt: string]: CustomEvent<any>;
51
53
  };
@@ -1,9 +1,10 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  import type { I18nFormatter } from "js/core/src/gradio_helper";
3
3
  import type { Datatype } from "./utils/utils";
4
+ import type { CellValue } from "./types";
4
5
  declare const __propDef: {
5
6
  props: {
6
- value: string | number;
7
+ value: CellValue;
7
8
  index: number;
8
9
  j: number;
9
10
  actual_pinned_columns: number;
@@ -5,8 +5,10 @@ import Padlock from "./icons/Padlock.svelte";
5
5
  import SortArrowUp from "./icons/SortArrowUp.svelte";
6
6
  import SortArrowDown from "./icons/SortArrowDown.svelte";
7
7
  import CellMenuIcons from "./CellMenuIcons.svelte";
8
+ import { BaseCheckbox } from "@gradio/checkbox";
8
9
  export let value;
9
10
  export let i;
11
+ export let datatype = "str";
10
12
  export let actual_pinned_columns;
11
13
  export let header_edit;
12
14
  export let selected_header;
@@ -25,7 +27,19 @@ export let i18n;
25
27
  export let el;
26
28
  export let is_static;
27
29
  export let col_count;
30
+ export let data = [];
31
+ export let on_select_all = void 0;
28
32
  $: can_add_columns = col_count && col_count[1] === "dynamic";
33
+ $: is_bool_column = datatype === "bool";
34
+ $: select_all_state = (() => {
35
+ if (!is_bool_column || data.length === 0) return "unchecked";
36
+ const true_count = data.filter(
37
+ (row) => row[i]?.value === true || row[i]?.value === "true"
38
+ ).length;
39
+ if (true_count === 0) return "unchecked";
40
+ if (true_count === data.length) return "checked";
41
+ return "indeterminate";
42
+ })();
29
43
  $: sort_index = sort_columns.findIndex((item) => item.col === i);
30
44
  $: filter_index = filter_columns.findIndex((item) => item.col === i);
31
45
  $: sort_priority = sort_index !== -1 ? sort_index + 1 : null;
@@ -65,6 +79,33 @@ function get_header_position(col_index) {
65
79
  >
66
80
  <div class="cell-wrap">
67
81
  <div class="header-content">
82
+ {#if is_bool_column && editable && on_select_all}
83
+ <div
84
+ class="select-all-checkbox"
85
+ role="button"
86
+ tabindex="0"
87
+ on:click|stopPropagation
88
+ on:keydown|stopPropagation={(e) => {
89
+ if (e.key === "Enter" || e.key === " ") {
90
+ e.preventDefault();
91
+ }
92
+ }}
93
+ on:mousedown|stopPropagation
94
+ >
95
+ <BaseCheckbox
96
+ value={select_all_state === "checked"}
97
+ indeterminate={select_all_state === "indeterminate"}
98
+ label=""
99
+ interactive={true}
100
+ on:select={() => {
101
+ if (on_select_all) {
102
+ const new_value = select_all_state !== "checked";
103
+ on_select_all(i, new_value);
104
+ }
105
+ }}
106
+ />
107
+ </div>
108
+ {/if}
68
109
  <button
69
110
  class="header-button"
70
111
  on:click={(event) => handle_header_click(event, i)}
@@ -256,4 +297,20 @@ function get_header_position(col_index) {
256
297
  z-index: 5;
257
298
  border-right: none;
258
299
  }
300
+
301
+ .select-all-checkbox {
302
+ display: flex;
303
+ align-items: center;
304
+ justify-content: center;
305
+ margin-right: var(--size-1);
306
+ flex-shrink: 0;
307
+ }
308
+
309
+ .select-all-checkbox :global(label) {
310
+ margin: 0;
311
+ }
312
+
313
+ .select-all-checkbox :global(span) {
314
+ display: none;
315
+ }
259
316
  </style>
@@ -2,10 +2,12 @@ import { SvelteComponent } from "svelte";
2
2
  import type { I18nFormatter } from "js/core/src/gradio_helper";
3
3
  import type { SortDirection } from "./context/dataframe_context";
4
4
  import type { FilterDatatype } from "./context/dataframe_context";
5
+ import type { Datatype } from "./utils/utils";
5
6
  declare const __propDef: {
6
7
  props: {
7
8
  value: string;
8
9
  i: number;
10
+ datatype?: Datatype;
9
11
  actual_pinned_columns: number;
10
12
  header_edit: number | false;
11
13
  selected_header: number | false;
@@ -36,8 +38,13 @@ declare const __propDef: {
36
38
  el: HTMLTextAreaElement | null;
37
39
  is_static: boolean;
38
40
  col_count: [number, "fixed" | "dynamic"];
41
+ data?: any[];
42
+ on_select_all?: ((col: number, checked: boolean) => void) | undefined;
39
43
  };
40
44
  events: {
45
+ click: MouseEvent;
46
+ mousedown: MouseEvent;
47
+ } & {
41
48
  [evt: string]: CustomEvent<any>;
42
49
  };
43
50
  slots: {};
@@ -1,4 +1,5 @@
1
1
  import { writable } from "svelte/store";
2
+ import type { CellValue } from "../types";
2
3
  import { get_next_cell_coordinates, get_range_selection, move_cursor } from "../utils/selection_utils";
3
4
  export declare const DATAFRAME_KEY: unique symbol;
4
5
  export type SortDirection = "asc" | "desc";
@@ -18,7 +19,7 @@ interface DataFrameState {
18
19
  max_height: number;
19
20
  column_widths: string[];
20
21
  max_chars?: number;
21
- static_columns?: (string | number)[];
22
+ static_columns?: CellValue[];
22
23
  };
23
24
  current_search_query: string | null;
24
25
  sort_state: {
@@ -30,7 +31,7 @@ interface DataFrameState {
30
31
  initial_data: {
31
32
  data: {
32
33
  id: string;
33
- value: string | number;
34
+ value: CellValue;
34
35
  }[][];
35
36
  display_value: string[][] | null;
36
37
  styling: string[][] | null;
@@ -46,7 +47,7 @@ interface DataFrameState {
46
47
  initial_data: {
47
48
  data: {
48
49
  id: string;
49
- value: string | number;
50
+ value: CellValue;
50
51
  }[][];
51
52
  display_value: string[][] | null;
52
53
  styling: string[][] | null;
@@ -105,7 +106,7 @@ interface DataFrameActions {
105
106
  data: any[][];
106
107
  headers: string[];
107
108
  };
108
- trigger_change: (data: any[][], headers: any[], previous_data: string[][], previous_headers: string[], value_is_output: boolean, dispatch: (e: "change" | "input", detail?: any) => void) => Promise<void>;
109
+ trigger_change: (data: any[][], headers: any[], previous_data: any[][], previous_headers: string[], value_is_output: boolean, dispatch: (e: "change" | "input" | "edit", detail?: any) => void) => Promise<void>;
109
110
  reset_sort_state: () => void;
110
111
  reset_filter_state: () => void;
111
112
  set_active_cell_menu: (menu: {
@@ -169,10 +170,10 @@ export interface DataFrameContext {
169
170
  input: HTMLTextAreaElement | null;
170
171
  }>;
171
172
  parent_element?: HTMLElement;
172
- get_data_at?: (row: number, col: number) => string | number;
173
- get_column?: (col: number) => (string | number)[];
174
- get_row?: (row: number) => (string | number)[];
175
- dispatch?: (e: "change" | "select" | "search", detail?: any) => void;
173
+ get_data_at?: (row: number, col: number) => CellValue;
174
+ get_column?: (col: number) => CellValue[];
175
+ get_row?: (row: number) => CellValue[];
176
+ dispatch?: (e: "change" | "select" | "search" | "edit", detail?: any) => void;
176
177
  }
177
178
  export declare function create_dataframe_context(config: DataFrameState["config"]): DataFrameContext;
178
179
  export declare function get_dataframe_context(): DataFrameContext;
@@ -152,7 +152,7 @@ function create_actions(state, context) {
152
152
  if (s.current_search_query)
153
153
  return;
154
154
  const current_headers = headers.map((h) => h.value);
155
- const current_data = data.map((row) => row.map((cell) => String(cell.value)));
155
+ const current_data = data.map((row) => row.map((cell) => cell.value));
156
156
  if (!dequal(current_data, previous_data) ||
157
157
  !dequal(current_headers, previous_headers)) {
158
158
  if (!dequal(current_headers, previous_headers)) {
@@ -166,6 +166,14 @@ function create_actions(state, context) {
166
166
  headers: current_headers,
167
167
  metadata: null
168
168
  });
169
+ const index = s.ui_state.selected;
170
+ if (index) {
171
+ dispatch("edit", {
172
+ index,
173
+ value: data[index[0]][index[1]].value,
174
+ previous_value: previous_data[index[0]][index[1]]
175
+ });
176
+ }
169
177
  if (!value_is_output)
170
178
  dispatch("input");
171
179
  }
@@ -5,9 +5,10 @@ export interface HeadersWithIDs {
5
5
  id: string;
6
6
  value: string;
7
7
  }
8
+ export type CellValue = string | number | boolean;
8
9
  export interface TableCell {
9
10
  id: string;
10
- value: string | number;
11
+ value: CellValue;
11
12
  }
12
13
  export type TableData = TableCell[][];
13
14
  export type CountConfig = [number, "fixed" | "dynamic"];
@@ -1,13 +1,14 @@
1
- import type { Headers, HeadersWithIDs } from "./utils";
1
+ import type { Datatype, Headers, HeadersWithIDs } from "./utils";
2
+ import type { CellValue } from "../types";
2
3
  export declare function make_headers(_head: Headers, col_count: [number, "fixed" | "dynamic"], els: Record<string, {
3
4
  cell: null | HTMLTableCellElement;
4
5
  input: null | HTMLTextAreaElement;
5
6
  }>, make_id: () => string): HeadersWithIDs;
6
- export declare function process_data(values: (string | number)[][], els: Record<string, {
7
+ export declare function process_data(values: CellValue[][], els: Record<string, {
7
8
  cell: null | HTMLTableCellElement;
8
9
  input: null | HTMLTextAreaElement;
9
- }>, data_binding: Record<string, any>, make_id: () => string, display_value?: string[][] | null): {
10
+ }>, data_binding: Record<string, any>, make_id: () => string, display_value: (string[][] | null) | undefined, datatype: Datatype | Datatype[]): {
10
11
  id: string;
11
- value: string | number;
12
+ value: CellValue;
12
13
  display_value?: string;
13
14
  }[][];
@@ -1,3 +1,4 @@
1
+ import { cast_value_to_type } from "./utils";
1
2
  export function make_headers(_head, col_count, els, make_id) {
2
3
  let _h = _head || [];
3
4
  if (col_count[1] === "fixed" && _h.length < col_count[0]) {
@@ -21,7 +22,7 @@ export function make_headers(_head, col_count, els, make_id) {
21
22
  return { id: _id, value: h ?? "" };
22
23
  });
23
24
  }
24
- export function process_data(values, els, data_binding, make_id, display_value = null) {
25
+ export function process_data(values, els, data_binding, make_id, display_value = null, datatype) {
25
26
  if (!values || values.length === 0) {
26
27
  return [];
27
28
  }
@@ -34,9 +35,10 @@ export function process_data(values, els, data_binding, make_id, display_value =
34
35
  if (display === undefined) {
35
36
  display = String(value);
36
37
  }
38
+ const dtype = Array.isArray(datatype) ? datatype[j] : datatype;
37
39
  return {
38
40
  id: _id,
39
- value,
41
+ value: cast_value_to_type(value, dtype),
40
42
  display_value: display
41
43
  };
42
44
  });
@@ -1,7 +1,8 @@
1
+ import type { CellValue } from "../types";
1
2
  export type FilterDatatype = "string" | "number";
2
3
  export declare function filter_data(data: {
3
4
  id: string;
4
- value: string | number;
5
+ value: CellValue;
5
6
  }[][], filter_columns: {
6
7
  col: number;
7
8
  datatype: FilterDatatype;
@@ -10,7 +11,7 @@ export declare function filter_data(data: {
10
11
  }[]): number[];
11
12
  export declare function filter_data_and_preserve_selection(data: {
12
13
  id: string;
13
- value: string | number;
14
+ value: CellValue;
14
15
  }[][], display_value: string[][] | null, styling: string[][] | null, filter_columns: {
15
16
  col: number;
16
17
  datatype: FilterDatatype;
@@ -18,10 +19,10 @@ export declare function filter_data_and_preserve_selection(data: {
18
19
  value: string;
19
20
  }[], selected: [number, number] | false, get_current_indices: (id: string, data: {
20
21
  id: string;
21
- value: string | number;
22
+ value: CellValue;
22
23
  }[][]) => [number, number], original_data?: {
23
24
  id: string;
24
- value: string | number;
25
+ value: CellValue;
25
26
  }[][], original_display_value?: string[][] | null, original_styling?: string[][] | null): {
26
27
  data: typeof data;
27
28
  selected: [number, number] | false;
@@ -26,7 +26,7 @@ export async function handle_cell_blur(event, ctx, coords) {
26
26
  const input_el = event.target;
27
27
  if (!input_el || input_el.value === undefined)
28
28
  return;
29
- await save_cell_value(input_el.type === "checkbox" ? String(input_el.checked) : input_el.value, ctx, coords[0], coords[1]);
29
+ await save_cell_value(input_el.value, ctx, coords[0], coords[1]);
30
30
  }
31
31
  function handle_header_navigation(event, ctx) {
32
32
  const state = get(ctx.state);
@@ -1,7 +1,7 @@
1
- import type { CellCoordinate } from "./../types";
1
+ import type { CellCoordinate, CellValue } from "./../types";
2
2
  export type CellData = {
3
3
  id: string;
4
- value: string | number;
4
+ value: CellValue;
5
5
  };
6
6
  export declare function is_cell_in_selection(coords: [number, number], selected_cells: [number, number][]): boolean;
7
7
  export declare function is_cell_selected(cell: CellCoordinate, selected_cells: CellCoordinate[]): string;
@@ -21,7 +21,7 @@ export declare function select_column(data: any[][], col: number): CellCoordinat
21
21
  export declare function select_row(data: any[][], row: number): CellCoordinate[];
22
22
  export declare function calculate_selection_positions(selected: CellCoordinate, data: {
23
23
  id: string;
24
- value: string | number;
24
+ value: CellValue;
25
25
  }[][], els: Record<string, {
26
26
  cell: HTMLTableCellElement | null;
27
27
  }>, parent: HTMLElement, table: HTMLElement): {
@@ -1,4 +1,4 @@
1
- import type { Headers } from "../types";
1
+ import type { Headers, CellValue } from "../types";
2
2
  export type SortDirection = "asc" | "desc";
3
3
  export declare function get_sort_status(name: string, sort_columns: {
4
4
  col: number;
@@ -6,20 +6,20 @@ export declare function get_sort_status(name: string, sort_columns: {
6
6
  }[], headers: Headers): "none" | "asc" | "desc";
7
7
  export declare function sort_data(data: {
8
8
  id: string;
9
- value: string | number;
9
+ value: CellValue;
10
10
  }[][], sort_columns: {
11
11
  col: number;
12
12
  direction: SortDirection;
13
13
  }[]): number[];
14
14
  export declare function sort_data_and_preserve_selection(data: {
15
15
  id: string;
16
- value: string | number;
16
+ value: CellValue;
17
17
  }[][], display_value: string[][] | null, styling: string[][] | null, sort_columns: {
18
18
  col: number;
19
19
  direction: SortDirection;
20
20
  }[], selected: [number, number] | false, get_current_indices: (id: string, data: {
21
21
  id: string;
22
- value: string | number;
22
+ value: CellValue;
23
23
  }[][]) => [number, number]): {
24
24
  data: typeof data;
25
25
  selected: [number, number] | false;