1import { S as SvelteComponent, i as init, s as safe_not_equal, f as element, q as create_component, m as space, b as attr, c as insert, u as mount_component, d as append, v as transition_in, w as transition_out, e as detach, x as destroy_component, A as createEventDispatcher, h as text, j as set_data, a6 as tick, D as binding_callbacks, a3 as set_input_value, I as action_destroyer, l as listen, g as is_function, r as run_all, a4 as flush, L as assign, M as StatusTracker, J as bind, N as get_spread_update, O as get_spread_object, G as add_flush_callback, F as bubble } from './index.230aa104.js'; 2import { B as Block } from './Block.67caaa62.js'; 3import { g as get_styles } from './styles.db46e346.js'; 4import { B as BlockTitle } from './BlockTitle.8a7e0497.js'; 5 6/* home/runner/work/gradio/gradio/ui/packages/form/src/Textbox.svelte generated by Svelte v3.49.0 */ 7 8function create_default_slot$1(ctx) { 9 let t; 10 11 return { 12 c() { 13 t = text(/*label*/ ctx[3]); 14 }, 15 m(target, anchor) { 16 insert(target, t, anchor); 17 }, 18 p(ctx, dirty) { 19 if (dirty & /*label*/ 8) set_data(t, /*label*/ ctx[3]); 20 }, 21 d(detaching) { 22 if (detaching) detach(t); 23 } 24 }; 25} 26 27// (80:1) {:else} 28function create_else_block(ctx) { 29 let textarea; 30 let textarea_class_value; 31 let text_area_resize_action; 32 let mounted; 33 let dispose; 34 35 return { 36 c() { 37 textarea = element("textarea"); 38 attr(textarea, "data-testid", "textbox"); 39 attr(textarea, "class", textarea_class_value = "scroll-hide block gr-box gr-input w-full gr-text-input " + /*classes*/ ctx[8]); 40 attr(textarea, "placeholder", /*placeholder*/ ctx[2]); 41 attr(textarea, "rows", /*lines*/ ctx[1]); 42 textarea.disabled = /*disabled*/ ctx[4]; 43 }, 44 m(target, anchor) { 45 insert(target, textarea, anchor); 46 set_input_value(textarea, /*value*/ ctx[0]); 47 /*textarea_binding*/ ctx[15](textarea); 48 49 if (!mounted) { 50 dispose = [ 51 action_destroyer(text_area_resize_action = /*text_area_resize*/ ctx[10].call(null, textarea, /*value*/ ctx[0])), 52 listen(textarea, "input", /*textarea_input_handler*/ ctx[14]) 53 ]; 54 55 mounted = true; 56 } 57 }, 58 p(ctx, dirty) { 59 if (dirty & /*classes*/ 256 && textarea_class_value !== (textarea_class_value = "scroll-hide block gr-box gr-input w-full gr-text-input " + /*classes*/ ctx[8])) { 60 attr(textarea, "class", textarea_class_value); 61 } 62 63 if (dirty & /*placeholder*/ 4) { 64 attr(textarea, "placeholder", /*placeholder*/ ctx[2]); 65 } 66 67 if (dirty & /*lines*/ 2) { 68 attr(textarea, "rows", /*lines*/ ctx[1]); 69 } 70 71 if (dirty & /*disabled*/ 16) { 72 textarea.disabled = /*disabled*/ ctx[4]; 73 } 74 75 if (text_area_resize_action && is_function(text_area_resize_action.update) && dirty & /*value*/ 1) text_area_resize_action.update.call(null, /*value*/ ctx[0]); 76 77 if (dirty & /*value*/ 1) { 78 set_input_value(textarea, /*value*/ ctx[0]); 79 } 80 }, 81 d(detaching) { 82 if (detaching) detach(textarea); 83 /*textarea_binding*/ ctx[15](null); 84 mounted = false; 85 run_all(dispose); 86 } 87 }; 88} 89 90// (69:1) {#if lines === 1 && max_lines === 1} 91function create_if_block(ctx) { 92 let input; 93 let input_class_value; 94 let mounted; 95 let dispose; 96 97 return { 98 c() { 99 input = element("input"); 100 attr(input, "data-testid", "textbox"); 101 attr(input, "type", "text"); 102 attr(input, "class", input_class_value = "scroll-hide block gr-box gr-input w-full gr-text-input " + /*classes*/ ctx[8]); 103 attr(input, "placeholder", /*placeholder*/ ctx[2]); 104 input.disabled = /*disabled*/ ctx[4]; 105 }, 106 m(target, anchor) { 107 insert(target, input, anchor); 108 set_input_value(input, /*value*/ ctx[0]); 109 /*input_binding*/ ctx[13](input); 110 111 if (!mounted) { 112 dispose = [ 113 listen(input, "input", /*input_input_handler*/ ctx[12]), 114 listen(input, "keypress", /*handle_keypress*/ ctx[9]) 115 ]; 116 117 mounted = true; 118 } 119 }, 120 p(ctx, dirty) { 121 if (dirty & /*classes*/ 256 && input_class_value !== (input_class_value = "scroll-hide block gr-box gr-input w-full gr-text-input " + /*classes*/ ctx[8])) { 122 attr(input, "class", input_class_value); 123 } 124 125 if (dirty & /*placeholder*/ 4) { 126 attr(input, "placeholder", /*placeholder*/ ctx[2]); 127 } 128
129 if (dirty & /*disabled*/ 16) { 130 input.disabled = /*disabled*/ ctx[4]; 131 } 132 133 if (dirty & /*value*/ 1 && input.value !== /*value*/ ctx[0]) { 134 set_input_value(input, /*value*/ ctx[0]); 135 } 136 }, 137 d(detaching) { 138 if (detaching) detach(input); 139 /*input_binding*/ ctx[13](null); 140 mounted = false; 141 run_all(dispose); 142 } 143 }; 144} 145 146function create_fragment$1(ctx) { 147 let label_1; 148 let blocktitle; 149 let t; 150 let current; 151 152 blocktitle = new BlockTitle({ 153 props: { 154 show_label: /*show_label*/ ctx[5], 155 $$slots: { default: [create_default_slot$1] }, 156 $$scope: { ctx } 157 } 158 }); 159 160 function select_block_type(ctx, dirty) { 161 if (/*lines*/ ctx[1] === 1 && /*max_lines*/ ctx[6] === 1) return create_if_block; 162 return create_else_block; 163 } 164 165 let current_block_type = select_block_type(ctx); 166 let if_block = current_block_type(ctx); 167 168 return { 169 c() { 170 label_1 = element("label"); 171 create_component(blocktitle.$$.fragment); 172 t = space(); 173 if_block.c(); 174 attr(label_1, "class", "block w-full"); 175 }, 176 m(target, anchor) { 177 insert(target, label_1, anchor); 178 mount_component(blocktitle, label_1, null); 179 append(label_1, t); 180 if_block.m(label_1, null); 181 current = true; 182 }, 183 p(ctx, [dirty]) { 184 const blocktitle_changes = {}; 185 if (dirty & /*show_label*/ 32) blocktitle_changes.show_label = /*show_label*/ ctx[5]; 186 187 if (dirty & /*$$scope, label*/ 524296) { 188 blocktitle_changes.$$scope = { dirty, ctx }; 189 } 190 191 blocktitle.$set(blocktitle_changes); 192 193 if (current_block_type === (current_block_type = select_block_type(ctx)) && if_block) { 194 if_block.p(ctx, dirty); 195 } else { 196 if_block.d(1); 197 if_block = current_block_type(ctx); 198 199 if (if_block) { 200 if_block.c(); 201 if_block.m(label_1, null); 202 } 203 } 204 }, 205 i(local) { 206 if (current) return; 207 transition_in(blocktitle.$$.fragment, local); 208 current = true; 209 }, 210 o(local) { 211 transition_out(blocktitle.$$.fragment, local); 212 current = false; 213 }, 214 d(detaching) { 215 if (detaching) detach(label_1); 216 destroy_component(blocktitle); 217 if_block.d(); 218 } 219 }; 220} 221 222function instance$1($$self, $$props, $$invalidate) { 223 let classes; 224 let { value = "" } = $$props; 225 let { style = {} } = $$props; 226 let { lines = 1 } = $$props; 227 let { placeholder = "Type here..." } = $$props; 228 let { label } = $$props; 229 let { disabled = false } = $$props; 230 let { show_label = true } = $$props; 231 let { max_lines } = $$props; 232 let el; 233 const dispatch = createEventDispatcher(); 234 235 function handle_change(val) { 236 dispatch("change", val); 237 } 238 239 async function handle_keypress(e) { 240 await tick(); 241 242 if (e.key === "Enter" && lines === 1) { 243 e.preventDefault(); 244 dispatch("submit"); 245 } 246 } 247 248 async function resize(event) { 249 await tick(); 250 if (lines === max_lines) return; 251 252 let max = max_lines === false 253 ? false 254 : max_lines === undefined ? 21 * 11 : 21 * (max_lines + 1); // default 255 256 let min = 21 * (lines + 1); 257 const target = event.target; 258 target.style.height = "1px"; 259 let scroll_height; 260 261 if (max && target.scrollHeight > max) { 262 scroll_height = max; 263 } else if (target.scrollHeight < min) { 264 scroll_height = min; 265 } else { 266 scroll_height = target.scrollHeight; 267 } 268 269 target.style.height = `${scroll_height}px`; 270 } 271 272 function text_area_resize(el, value) { 273 if (lines === max_lines) return; 274 el.style.overflowY = "scroll"; 275 el.addEventListener("input", resize); 276 if (!value.trim()) return; 277 resize({ target: el }); 278 279 return { 280 destroy: () => el.removeEventListener("input", resize) 281 }; 282 } 283 284 function input_input_handler() { 285 value = this.value; 286 $$invalidate(0, value); 287 } 288 289 function input_binding($$value) { 290 binding_callbacks[$$value ? 'unshift' : 'push'](() => { 291 el = $$value; 292 $$invalidate(7, el); 293 }); 294 } 295 296 function textarea_input_handler() { 297 value = this.value; 298 $$invalidate(0, value); 299 } 300 301 function textarea_binding($$value) { 302 binding_callbacks[$$value ? 'unshift' : 'push'](() => { 303 el = $$value; 304 $$invalidate(7, el); 305 }); 306 } 307 308 $$self.$$set = $$props => {
309 if ('value' in $$props) $$invalidate(0, value = $$props.value); 310 if ('style' in $$props) $$invalidate(11, style = $$props.style); 311 if ('lines' in $$props) $$invalidate(1, lines = $$props.lines); 312 if ('placeholder' in $$props) $$invalidate(2, placeholder = $$props.placeholder); 313 if ('label' in $$props) $$invalidate(3, label = $$props.label); 314 if ('disabled' in $$props) $$invalidate(4, disabled = $$props.disabled); 315 if ('show_label' in $$props) $$invalidate(5, show_label = $$props.show_label); 316 if ('max_lines' in $$props) $$invalidate(6, max_lines = $$props.max_lines); 317 }; 318 319 $$self.$$.update = () => { 320 if ($$self.$$.dirty & /*value, el, lines, max_lines*/ 195) { 321 (el && lines !== max_lines && resize({ target: el })); 322 } 323 324 if ($$self.$$.dirty & /*value*/ 1) { 325 handle_change(value); 326 } 327 328 if ($$self.$$.dirty & /*style*/ 2048) { 329 $$invalidate(8, { classes } = get_styles(style, ["rounded", "border"]), classes); 330 } 331 }; 332 333 return [ 334 value, 335 lines, 336 placeholder, 337 label, 338 disabled, 339 show_label, 340 max_lines, 341 el, 342 classes, 343 handle_keypress, 344 text_area_resize, 345 style, 346 input_input_handler, 347 input_binding, 348 textarea_input_handler, 349 textarea_binding 350 ]; 351} 352 353class Textbox$2 extends SvelteComponent { 354 constructor(options) { 355 super(); 356 357 init(this, options, instance$1, create_fragment$1, safe_not_equal, { 358 value: 0, 359 style: 11, 360 lines: 1, 361 placeholder: 2, 362 label: 3, 363 disabled: 4, 364 show_label: 5, 365 max_lines: 6 366 }); 367 } 368} 369 370/* src/components/Textbox/Textbox.svelte generated by Svelte v3.49.0 */ 371 372function create_default_slot(ctx) { 373 let statustracker; 374 let t; 375 let textbox; 376 let updating_value; 377 let current; 378 const statustracker_spread_levels = [/*loading_status*/ ctx[10]]; 379 let statustracker_props = {}; 380 381 for (let i = 0; i < statustracker_spread_levels.length; i += 1) { 382 statustracker_props = assign(statustracker_props, statustracker_spread_levels[i]); 383 } 384 385 statustracker = new StatusTracker({ props: statustracker_props }); 386 387 function textbox_value_binding(value) { 388 /*textbox_value_binding*/ ctx[12](value); 389 } 390 391 let textbox_props = { 392 style: /*style*/ ctx[9], 393 label: /*label*/ ctx[1], 394 show_label: /*show_label*/ ctx[7], 395 lines: /*lines*/ ctx[4], 396 max_lines: !/*max_lines*/ ctx[8] && /*mode*/ ctx[11] === "static" 397 ? /*lines*/ ctx[4] + 1 398 : /*max_lines*/ ctx[8], 399 placeholder: /*placeholder*/ ctx[5], 400 disabled: /*mode*/ ctx[11] === "static" 401 }; 402 403 if (/*value*/ ctx[0] !== void 0) { 404 textbox_props.value = /*value*/ ctx[0]; 405 } 406 407 textbox = new Textbox$2({ props: textbox_props }); 408 binding_callbacks.push(() => bind(textbox, 'value', textbox_value_binding)); 409 textbox.$on("change", /*change_handler*/ ctx[13]); 410 textbox.$on("submit", /*submit_handler*/ ctx[14]); 411 412 return { 413 c() { 414 create_component(statustracker.$$.fragment); 415 t = space(); 416 create_component(textbox.$$.fragment); 417 }, 418 m(target, anchor) { 419 mount_component(statustracker, target, anchor); 420 insert(target, t, anchor); 421 mount_component(textbox, target, anchor); 422 current = true; 423 }, 424 p(ctx, dirty) { 425 const statustracker_changes = (dirty & /*loading_status*/ 1024) 426 ? get_spread_update(statustracker_spread_levels, [get_spread_object(/*loading_status*/ ctx[10])]) 427 : {}; 428 429 statustracker.$set(statustracker_changes); 430 const textbox_changes = {}; 431 if (dirty & /*style*/ 512) textbox_changes.style = /*style*/ ctx[9]; 432 if (dirty & /*label*/ 2) textbox_changes.label = /*label*/ ctx[1]; 433 if (dirty & /*show_label*/ 128) textbox_changes.show_label = /*show_label*/ ctx[7]; 434 if (dirty & /*lines*/ 16) textbox_changes.lines = /*lines*/ ctx[4]; 435 436 if (dirty & /*max_lines, mode, lines*/ 2320) textbox_changes.max_lines = !/*max_lines*/ ctx[8] && /*mode*/ ctx[11] === "static" 437 ? /*lines*/ ctx[4] + 1 438 : /*max_lines*/ ctx[8]; 439 440 if (dirty & /*placeholder*/ 32) textbox_changes.placeholder = /*placeholder*/ ctx[5]; 441 if (dirty & /*mode*/ 2048) textbox_changes.disabled = /*mode*/ ctx[11] === "static"; 442 443 if (!updating_value && dirty & /*value*/ 1) { 444 updating_value = true; 445 textbox_changes.value = /*value*/ ctx[0]; 446 add_flush_callback(() => updating_value = false); 447 } 448 449 textbox.$set(textbox_changes); 450 }, 451 i(local) { 452 if (current) return; 453 transition_in(statustracker.$$.fragment, local); 454 transition_in(textbox.$$.fragment, local); 455 current = true; 456 }, 457 o(local) { 458 transition_out(statustracker.$$.fragment, local); 459 transition_out(textbox.$$.fragment, local); 460 current = false;
461 }, 462 d(detaching) { 463 destroy_component(statustracker, detaching); 464 if (detaching) detach(t); 465 destroy_component(textbox, detaching); 466 } 467 }; 468} 469 470function create_fragment(ctx) { 471 let block; 472 let current; 473 474 block = new Block({ 475 props: { 476 visible: /*visible*/ ctx[3], 477 form_position: /*form_position*/ ctx[6], 478 elem_id: /*elem_id*/ ctx[2], 479 disable: typeof /*style*/ ctx[9].container === "boolean" && !/*style*/ ctx[9].container, 480 $$slots: { default: [create_default_slot] }, 481 $$scope: { ctx } 482 } 483 }); 484 485 return { 486 c() { 487 create_component(block.$$.fragment); 488 }, 489 m(target, anchor) { 490 mount_component(block, target, anchor); 491 current = true; 492 }, 493 p(ctx, [dirty]) { 494 const block_changes = {}; 495 if (dirty & /*visible*/ 8) block_changes.visible = /*visible*/ ctx[3]; 496 if (dirty & /*form_position*/ 64) block_changes.form_position = /*form_position*/ ctx[6]; 497 if (dirty & /*elem_id*/ 4) block_changes.elem_id = /*elem_id*/ ctx[2]; 498 if (dirty & /*style*/ 512) block_changes.disable = typeof /*style*/ ctx[9].container === "boolean" && !/*style*/ ctx[9].container; 499 500 if (dirty & /*$$scope, style, label, show_label, lines, max_lines, mode, placeholder, value, loading_status*/ 36787) { 501 block_changes.$$scope = { dirty, ctx }; 502 } 503 504 block.$set(block_changes); 505 }, 506 i(local) { 507 if (current) return; 508 transition_in(block.$$.fragment, local); 509 current = true; 510 }, 511 o(local) { 512 transition_out(block.$$.fragment, local); 513 current = false; 514 }, 515 d(detaching) { 516 destroy_component(block, detaching); 517 } 518 }; 519} 520 521function instance($$self, $$props, $$invalidate) { 522 let { label = "Textbox" } = $$props; 523 let { elem_id = "" } = $$props; 524 let { visible = true } = $$props; 525 let { value = "" } = $$props; 526 let { lines } = $$props; 527 let { placeholder = "" } = $$props; 528 let { form_position = "single" } = $$props; 529 let { show_label } = $$props; 530 let { max_lines } = $$props; 531 let { style = {} } = $$props; 532 let { loading_status } = $$props; 533 let { mode } = $$props; 534 535 function textbox_value_binding(value$1) { 536 value = value$1; 537 $$invalidate(0, value); 538 } 539 540 function change_handler(event) { 541 bubble.call(this, $$self, event); 542 } 543 544 function submit_handler(event) { 545 bubble.call(this, $$self, event); 546 } 547 548 $$self.$$set = $$props => {
549 if ('label' in $$props) $$invalidate(1, label = $$props.label); 550 if ('elem_id' in $$props) $$invalidate(2, elem_id = $$props.elem_id); 551 if ('visible' in $$props) $$invalidate(3, visible = $$props.visible); 552 if ('value' in $$props) $$invalidate(0, value = $$props.value); 553 if ('lines' in $$props) $$invalidate(4, lines = $$props.lines); 554 if ('placeholder' in $$props) $$invalidate(5, placeholder = $$props.placeholder); 555 if ('form_position' in $$props) $$invalidate(6, form_position = $$props.form_position); 556 if ('show_label' in $$props) $$invalidate(7, show_label = $$props.show_label); 557 if ('max_lines' in $$props) $$invalidate(8, max_lines = $$props.max_lines); 558 if ('style' in $$props) $$invalidate(9, style = $$props.style); 559 if ('loading_status' in $$props) $$invalidate(10, loading_status = $$props.loading_status); 560 if ('mode' in $$props) $$invalidate(11, mode = $$props.mode); 561 }; 562 563 return [ 564 value, 565 label, 566 elem_id, 567 visible, 568 lines, 569 placeholder, 570 form_position, 571 show_label, 572 max_lines, 573 style, 574 loading_status, 575 mode, 576 textbox_value_binding, 577 change_handler, 578 submit_handler 579 ]; 580} 581 582class Textbox extends SvelteComponent { 583 constructor(options) { 584 super(); 585 586 init(this, options, instance, create_fragment, safe_not_equal, { 587 label: 1, 588 elem_id: 2, 589 visible: 3, 590 value: 0, 591 lines: 4, 592 placeholder: 5, 593 form_position: 6, 594 show_label: 7, 595 max_lines: 8, 596 style: 9, 597 loading_status: 10, 598 mode: 11 599 }); 600 } 601 602 get label() { 603 return this.$$.ctx[1]; 604 } 605 606 set label(label) { 607 this.$$set({ label }); 608 flush(); 609 } 610 611 get elem_id() { 612 return this.$$.ctx[2]; 613 } 614 615 set elem_id(elem_id) { 616 this.$$set({ elem_id }); 617 flush(); 618 } 619 620 get visible() { 621 return this.$$.ctx[3]; 622 } 623 624 set visible(visible) { 625 this.$$set({ visible }); 626 flush(); 627 } 628 629 get value() { 630 return this.$$.ctx[0]; 631 } 632 633 set value(value) { 634 this.$$set({ value }); 635 flush(); 636 } 637 638 get lines() { 639 return this.$$.ctx[4]; 640 } 641 642 set lines(lines) { 643 this.$$set({ lines }); 644 flush(); 645 } 646 647 get placeholder() { 648 return this.$$.ctx[5]; 649 } 650 651 set placeholder(placeholder) { 652 this.$$set({ placeholder }); 653 flush(); 654 } 655 656 get form_position() { 657 return this.$$.ctx[6]; 658 } 659 660 set form_position(form_position) { 661 this.$$set({ form_position }); 662 flush(); 663 } 664 665 get show_label() { 666 return this.$$.ctx[7]; 667 } 668 669 set show_label(show_label) { 670 this.$$set({ show_label }); 671 flush(); 672 } 673 674 get max_lines() { 675 return this.$$.ctx[8]; 676 } 677 678 set max_lines(max_lines) { 679 this.$$set({ max_lines }); 680 flush(); 681 } 682 683 get style() { 684 return this.$$.ctx[9]; 685 } 686 687 set style(style) { 688 this.$$set({ style }); 689 flush(); 690 } 691 692 get loading_status() { 693 return this.$$.ctx[10]; 694 } 695 696 set loading_status(loading_status) { 697 this.$$set({ loading_status }); 698 flush(); 699 } 700 701 get mode() { 702 return this.$$.ctx[11]; 703 } 704 705 set mode(mode) { 706 this.$$set({ mode }); 707 flush(); 708 } 709} 710 711var Textbox$1 = Textbox; 712 713const modes = ["static", "dynamic"]; 714 715export { Textbox$1 as Component, modes };
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.