1import { d as dsvFormat } from './dsv-a37bb3db.js'; 2 3var csv = dsvFormat(","); 4var csvParseRows = csv.parseRows; 5 6var tsv = dsvFormat("\t"); 7var tsvParseRows = tsv.parseRows; 8 9const Example_svelte_svelte_type_style_lang = ''; 10 11/* home/runner/work/gradio/gradio/js/dataframe/Example.svelte generated by Svelte v4.2.2 */ 12const { 13 SvelteComponent, 14 append, 15 attr, 16 destroy_each, 17 detach, 18 element, 19 empty, 20 ensure_array_like, 21 init, 22 insert, 23 listen, 24 noop, 25 run_all, 26 safe_not_equal, 27 set_data, 28 space, 29 text, 30 toggle_class 31} = window.__gradio__svelte__internal; 32function get_each_context(ctx, list, i) { 33 const child_ctx = ctx.slice(); 34 child_ctx[11] = list[i]; 35 child_ctx[13] = i; 36 return child_ctx; 37} 38 39function get_each_context_1(ctx, list, i) { 40 const child_ctx = ctx.slice(); 41 child_ctx[14] = list[i]; 42 child_ctx[16] = i; 43 return child_ctx; 44} 45 46// (48:0) {#if loaded} 47function create_if_block(ctx) { 48 let div; 49 let mounted; 50 let dispose; 51 52 function select_block_type(ctx, dirty) { 53 if (typeof /*loaded_value*/ ctx[6] === "string") return create_if_block_1; 54 return create_else_block; 55 } 56 57 let current_block_type = select_block_type(ctx); 58 let if_block = current_block_type(ctx); 59 60 return { 61 c() { 62 div = element("div"); 63 if_block.c(); 64 attr(div, "class", "svelte-1cib1xd"); 65 toggle_class(div, "table", /*type*/ ctx[1] === "table"); 66 toggle_class(div, "gallery", /*type*/ ctx[1] === "gallery"); 67 toggle_class(div, "selected", /*selected*/ ctx[2]); 68 }, 69 m(target, anchor) { 70 insert(target, div, anchor); 71 if_block.m(div, null); 72 73 if (!mounted) { 74 dispose = [ 75 listen(div, "mouseenter", /*mouseenter_handler*/ ctx[9]), 76 listen(div, "mouseleave", /*mouseleave_handler*/ ctx[10]) 77 ]; 78 79 mounted = true; 80 } 81 }, 82 p(ctx, dirty) { 83 if (current_block_type === (current_block_type = select_block_type(ctx)) && if_block) { 84 if_block.p(ctx, dirty); 85 } else { 86 if_block.d(1); 87 if_block = current_block_type(ctx); 88 89 if (if_block) { 90 if_block.c(); 91 if_block.m(div, null); 92 } 93 } 94 95 if (dirty & /*type*/ 2) { 96 toggle_class(div, "table", /*type*/ ctx[1] === "table"); 97 } 98 99 if (dirty & /*type*/ 2) { 100 toggle_class(div, "gallery", /*type*/ ctx[1] === "gallery"); 101 } 102 103 if (dirty & /*selected*/ 4) { 104 toggle_class(div, "selected", /*selected*/ ctx[2]); 105 } 106 }, 107 d(detaching) { 108 if (detaching) { 109 detach(div); 110 } 111 112 if_block.d(); 113 mounted = false; 114 run_all(dispose); 115 } 116 }; 117} 118 119// (60:2) {:else} 120function create_else_block(ctx) { 121 let table; 122 let t; 123 let each_value = ensure_array_like(/*loaded_value*/ ctx[6].slice(0, 3)); 124 let each_blocks = []; 125 126 for (let i = 0; i < each_value.length; i += 1) { 127 each_blocks[i] = create_each_block(get_each_context(ctx, each_value, i)); 128 } 129 130 let if_block = /*value*/ ctx[0].length > 3 && create_if_block_2(ctx); 131 132 return { 133 c() { 134 table = element("table"); 135 136 for (let i = 0; i < each_blocks.length; i += 1) { 137 each_blocks[i].c(); 138 } 139 140 t = space(); 141 if (if_block) if_block.c(); 142 attr(table, "class", " svelte-1cib1xd"); 143 }, 144 m(target, anchor) { 145 insert(target, table, anchor); 146 147 for (let i = 0; i < each_blocks.length; i += 1) { 148 if (each_blocks[i]) { 149 each_blocks[i].m(table, null); 150 } 151 } 152 153 append(table, t); 154 if (if_block) if_block.m(table, null); 155 }, 156 p(ctx, dirty) { 157 if (dirty & /*loaded_value*/ 64) { 158 each_value = ensure_array_like(/*loaded_value*/ ctx[6].slice(0, 3)); 159 let i; 160 161 for (i = 0; i < each_value.length; i += 1) { 162 const child_ctx = get_each_context(ctx, each_value, i); 163 164 if (each_blocks[i]) { 165 each_blocks[i].p(child_ctx, dirty); 166 } else { 167 each_blocks[i] = create_each_block(child_ctx); 168 each_blocks[i].c(); 169 each_blocks[i].m(table, t); 170 } 171 } 172 173 for (; i < each_blocks.length; i += 1) { 174 each_blocks[i].d(1); 175 } 176 177 each_blocks.length = each_value.length; 178 } 179 180 if (/*value*/ ctx[0].length > 3) { 181 if (if_block) { 182 if_block.p(ctx, dirty); 183 } else { 184 if_block = create_if_block_2(ctx); 185 if_block.c(); 186 if_block.m(table, null); 187 } 188 } else if (if_block) { 189 if_block.d(1); 190 if_block = null; 191 } 192 }, 193 d(detaching) { 194 if (detaching) { 195 detach(table); 196 } 197 198 destroy_each(each_blocks, detaching); 199 if (if_block) if_block.d(); 200 } 201 }; 202} 203 204// (58:2) {#if typeof loaded_value === "string"} 205function create_if_block_1(ctx) { 206 let t; 207 208 return { 209 c() { 210 t = text(/*loaded_value*/ ctx[6]); 211 }, 212 m(target, anchor) { 213 insert(target, t, anchor); 214 }, 215 p(ctx, dirty) {
216 if (dirty & /*loaded_value*/ 64) set_data(t, /*loaded_value*/ ctx[6]); 217 }, 218 d(detaching) { 219 if (detaching) { 220 detach(t); 221 } 222 } 223 }; 224} 225 226// (64:6) {#each row.slice(0, 3) as cell, j} 227function create_each_block_1(ctx) { 228 let td; 229 let t_value = /*cell*/ ctx[14] + ""; 230 let t; 231 232 return { 233 c() { 234 td = element("td"); 235 t = text(t_value); 236 attr(td, "class", "svelte-1cib1xd"); 237 }, 238 m(target, anchor) { 239 insert(target, td, anchor); 240 append(td, t); 241 }, 242 p(ctx, dirty) { 243 if (dirty & /*loaded_value*/ 64 && t_value !== (t_value = /*cell*/ ctx[14] + "")) set_data(t, t_value); 244 }, 245 d(detaching) { 246 if (detaching) { 247 detach(td); 248 } 249 } 250 }; 251} 252 253// (67:6) {#if row.length > 3} 254function create_if_block_3(ctx) { 255 let td; 256 257 return { 258 c() { 259 td = element("td"); 260 td.textContent = "â¦"; 261 attr(td, "class", "svelte-1cib1xd"); 262 }, 263 m(target, anchor) { 264 insert(target, td, anchor); 265 }, 266 d(detaching) { 267 if (detaching) { 268 detach(td); 269 } 270 } 271 }; 272} 273 274// (62:4) {#each loaded_value.slice(0, 3) as row, i} 275function create_each_block(ctx) { 276 let tr; 277 let t; 278 let each_value_1 = ensure_array_like(/*row*/ ctx[11].slice(0, 3)); 279 let each_blocks = []; 280 281 for (let i = 0; i < each_value_1.length; i += 1) { 282 each_blocks[i] = create_each_block_1(get_each_context_1(ctx, each_value_1, i)); 283 } 284 285 let if_block = /*row*/ ctx[11].length > 3 && create_if_block_3(); 286 287 return { 288 c() { 289 tr = element("tr"); 290 291 for (let i = 0; i < each_blocks.length; i += 1) { 292 each_blocks[i].c(); 293 } 294 295 t = space(); 296 if (if_block) if_block.c(); 297 }, 298 m(target, anchor) { 299 insert(target, tr, anchor); 300 301 for (let i = 0; i < each_blocks.length; i += 1) { 302 if (each_blocks[i]) { 303 each_blocks[i].m(tr, null); 304 } 305 } 306 307 append(tr, t); 308 if (if_block) if_block.m(tr, null); 309 }, 310 p(ctx, dirty) { 311 if (dirty & /*loaded_value*/ 64) { 312 each_value_1 = ensure_array_like(/*row*/ ctx[11].slice(0, 3)); 313 let i; 314 315 for (i = 0; i < each_value_1.length; i += 1) { 316 const child_ctx = get_each_context_1(ctx, each_value_1, i); 317 318 if (each_blocks[i]) { 319 each_blocks[i].p(child_ctx, dirty); 320 } else { 321 each_blocks[i] = create_each_block_1(child_ctx); 322 each_blocks[i].c(); 323 each_blocks[i].m(tr, t); 324 } 325 } 326 327 for (; i < each_blocks.length; i += 1) { 328 each_blocks[i].d(1); 329 } 330 331 each_blocks.length = each_value_1.length; 332 } 333 334 if (/*row*/ ctx[11].length > 3) { 335 if (if_block) ; else { 336 if_block = create_if_block_3(); 337 if_block.c(); 338 if_block.m(tr, null); 339 } 340 } else if (if_block) { 341 if_block.d(1); 342 if_block = null; 343 } 344 }, 345 d(detaching) { 346 if (detaching) { 347 detach(tr); 348 } 349 350 destroy_each(each_blocks, detaching); 351 if (if_block) if_block.d(); 352 } 353 }; 354} 355 356// (72:4) {#if value.length > 3} 357function create_if_block_2(ctx) { 358 let div; 359 360 return { 361 c() { 362 div = element("div"); 363 attr(div, "class", "overlay svelte-1cib1xd"); 364 toggle_class(div, "odd", /*index*/ ctx[3] % 2 != 0); 365 toggle_class(div, "even", /*index*/ ctx[3] % 2 == 0); 366 toggle_class(div, "button", /*type*/ ctx[1] === "gallery"); 367 }, 368 m(target, anchor) { 369 insert(target, div, anchor); 370 }, 371 p(ctx, dirty) { 372 if (dirty & /*index*/ 8) { 373 toggle_class(div, "odd", /*index*/ ctx[3] % 2 != 0); 374 } 375 376 if (dirty & /*index*/ 8) { 377 toggle_class(div, "even", /*index*/ ctx[3] % 2 == 0); 378 } 379 380 if (dirty & /*type*/ 2) { 381 toggle_class(div, "button", /*type*/ ctx[1] === "gallery"); 382 } 383 }, 384 d(detaching) { 385 if (detaching) { 386 detach(div); 387 } 388 } 389 }; 390} 391 392function create_fragment(ctx) { 393 let if_block_anchor; 394 let if_block = /*loaded*/ ctx[4] && create_if_block(ctx); 395 396 return { 397 c() { 398 if (if_block) if_block.c(); 399 if_block_anchor = empty(); 400 }, 401 m(target, anchor) { 402 if (if_block) if_block.m(target, anchor); 403 insert(target, if_block_anchor, anchor); 404 }, 405 p(ctx, [dirty]) { 406 if (/*loaded*/ ctx[4]) { 407 if (if_block) { 408 if_block.p(ctx, dirty); 409 } else { 410 if_block = create_if_block(ctx); 411 if_block.c(); 412 if_block.m(if_block_anchor.parentNode, if_block_anchor); 413 } 414 } else if (if_block) { 415 if_block.d(1); 416 if_block = null; 417 } 418 }, 419 i: noop, 420 o: noop, 421 d(detaching) { 422 if (detaching) { 423 detach(if_block_anchor); 424 } 425 426 if (if_block) if_block.d(detaching); 427 } 428 }; 429} 430
431function instance($$self, $$props, $$invalidate) { 432 let { gradio } = $$props; 433 let { value } = $$props; 434 let { samples_dir } = $$props; 435 let { type } = $$props; 436 let { selected = false } = $$props; 437 let { index } = $$props; 438 let hovered = false; 439 let loaded_value = value; 440 let loaded = Array.isArray(loaded_value); 441 const mouseenter_handler = () => $$invalidate(5, hovered = true); 442 const mouseleave_handler = () => $$invalidate(5, hovered = false); 443 444 $$self.$$set = $$props => { 445 if ('gradio' in $$props) $$invalidate(7, gradio = $$props.gradio); 446 if ('value' in $$props) $$invalidate(0, value = $$props.value); 447 if ('samples_dir' in $$props) $$invalidate(8, samples_dir = $$props.samples_dir); 448 if ('type' in $$props) $$invalidate(1, type = $$props.type); 449 if ('selected' in $$props) $$invalidate(2, selected = $$props.selected); 450 if ('index' in $$props) $$invalidate(3, index = $$props.index); 451 }; 452 453 $$self.$$.update = () => { 454 if ($$self.$$.dirty & /*loaded, value, samples_dir, gradio*/ 401) { 455 if (!loaded && typeof value === "string" && (/\.[a-zA-Z]+$/).test(value)) { 456 fetch(samples_dir + value).then(v => v.text()).then(v => { 457 try { 458 if (value.endsWith("csv")) { 459 const small_df = v.split("\n").slice(0, 4).map(v => v.split(",").slice(0, 4).join(",")).join("\n"); 460 $$invalidate(6, loaded_value = csvParseRows(small_df)); 461 } else if (value.endsWith("tsv")) { 462 const small_df = v.split("\n").slice(0, 4).map(v => v.split("\t").slice(0, 4).join("\t")).join("\n"); 463 $$invalidate(6, loaded_value = tsvParseRows(small_df)); 464 } else { 465 throw new Error(gradio.i18n("dataframe.incorrect_format")); 466 } 467 468 $$invalidate(4, loaded = true); 469 } catch(e) { 470 console.error(e); 471 } 472 }).catch(e => { 473 $$invalidate(6, loaded_value = value); 474 $$invalidate(4, loaded = true); 475 }); 476 } 477 } 478 }; 479 480 return [ 481 value, 482 type, 483 selected, 484 index, 485 loaded, 486 hovered, 487 loaded_value, 488 gradio, 489 samples_dir, 490 mouseenter_handler, 491 mouseleave_handler 492 ]; 493} 494 495class Example extends SvelteComponent { 496 constructor(options) { 497 super(); 498 499 init(this, options, instance, create_fragment, safe_not_equal, { 500 gradio: 7, 501 value: 0, 502 samples_dir: 8, 503 type: 1, 504 selected: 2, 505 index: 3 506 }); 507 } 508} 509 510export { Example as default }; 511//# sourceMappingURL=Example-7d6bb9b6.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.