1import { p as prop, d as bind_this, i as if_block, a as set_attribute, r as rest_props } from './i18n-CMo5lpzy.js'; 2import { R as push, S as first_child, a as append, t as template_effect, T as pop, X as sibling, W as from_html, au as prepare_files, M as tick, aj as delegate, a6 as comment, w as get, a5 as user_derived, v as proxy, y as user_effect, a7 as text, a0 as set_text, a8 as next } from './index-BvBk1Iap.js'; 3import { G as Gradio } from './utils.svelte-CYLB_jIA.js'; 4import { s as snippet } from './snippet-Bl5YVoCg.js'; 5import { B as Button } from './Button-CH2w4_A4.js'; 6import './clone-DaB-S2nH.js'; 7import './Image-CDw5qb5O.js'; 8import './misc-ByVveAau.js'; 9/* empty css */ 10import './ScrollFade.svelte_svelte_type_style_lang-Xm-PLg9E.js'; 11/* empty css */ 12 13var root_3 = from_html(`<img class="button-icon svelte-94gmgt"/>`); 14var root_2 = from_html(`<!> <!>`, 1); 15var root_1 = from_html(`<input class="hide svelte-94gmgt" type="file"/> <!>`, 1); 16 17function UploadButton($$anchor, $$props) { 18 push($$props, true); 19 20 let elem_id = prop($$props, 'elem_id', 3, ""), 21 elem_classes = prop($$props, 'elem_classes', 19, () => []), 22 visible = prop($$props, 'visible', 3, true), 23 file_types = prop($$props, 'file_types', 19, () => []), 24 size = prop($$props, 'size', 3, "lg"), 25 icon = prop($$props, 'icon', 3, null), 26 scale = prop($$props, 'scale', 3, null), 27 min_width = prop($$props, 'min_width', 3, undefined), 28 variant = prop($$props, 'variant', 3, "secondary"), 29 disabled = prop($$props, 'disabled', 3, false), 30 max_file_size = prop($$props, 'max_file_size', 3, null); 31 32 let hidden_upload; 33 34 let accept_file_types = user_derived(() => { 35 if (file_types() == null) { 36 return null; 37 } 38 39 const mapped = file_types().map((x) => { 40 if (x.startsWith(".")) { 41 return x; 42 } 43 44 return x + "/*"; 45 }); 46 47 return mapped.join(", "); 48 }); 49 50 function open_file_upload() { 51 $$props.onclick?.(); 52 hidden_upload.click(); 53 } 54 55 async function load_files(files) { 56 let _files = Array.from(files); 57 58 if (!files.length) { 59 return; 60 } 61 62 if ($$props.file_count === "single") { 63 _files = [files[0]]; 64 } 65 66 let all_file_data = await prepare_files(_files); 67 68 await tick(); 69 70 try { 71 all_file_data = (await $$props.upload(all_file_data, $$props.root, undefined, max_file_size() ?? Infinity))?.filter((x) => x !== null); 72 } catch(e) { 73 $$props.onerror?.(e.message); 74 75 return; 76 } 77 78 const new_value = $$props.file_count === "single" ? all_file_data?.[0] : all_file_data; 79 80 $$props.onchange?.(new_value); 81 $$props.onupload?.(new_value); 82 } 83 84 async function load_files_from_upload(e) { 85 const target = e.target; 86 87 if (!target.files) return; 88 89 await load_files(target.files); 90 } 91 92 function clear_input_value(e) { 93 const target = e.target; 94 95 if (target.value) target.value = ""; 96 } 97 98 var fragment = root_1(); 99 var input = first_child(fragment); 100 101 input.__change = load_files_from_upload; 102 input.__click = clear_input_value; 103 bind_this(input, ($$value) => hidden_upload = $$value, () => hidden_upload); 104 105 var node = sibling(input, 2); 106 107 Button(node, { 108 get size() { 109 return size(); 110 }, 111 112 get variant() { 113 return variant(); 114 }, 115 116 get elem_id() { 117 return elem_id(); 118 }, 119 120 get elem_classes() { 121 return elem_classes(); 122 }, 123 124 get visible() { 125 return visible(); 126 }, 127 onclick: open_file_upload, 128 get scale() { 129 return scale(); 130 }, 131 132 get min_width() { 133 return min_width(); 134 }, 135 136 get disabled() { 137 return disabled(); 138 }, 139 140 children: ($$anchor, $$slotProps) => { 141 var fragment_1 = root_2(); 142 var node_1 = first_child(fragment_1); 143 144 { 145 var consequent = ($$anchor) => { 146 var img = root_3(); 147 148 template_effect(() => { 149 set_attribute(img, 'src', icon().url); 150 set_attribute(img, 'alt', `${$$props.value} icon`); 151 }); 152 153 append($$anchor, img); 154 }; 155 156 if_block(node_1, ($$render) => { 157 if (icon()) $$render(consequent); 158 }); 159 } 160 161 var node_2 = sibling(node_1, 2); 162 163 { 164 var consequent_1 = ($$anchor) => { 165 var fragment_2 = comment(); 166 var node_3 = first_child(fragment_2); 167 168 snippet(node_3, () => $$props.children); 169 append($$anchor, fragment_2); 170 }; 171 172 if_block(node_2, ($$render) => { 173 if ($$props.children) $$render(consequent_1); 174 }); 175 } 176 177 append($$anchor, fragment_1); 178 }, 179 $$slots: { default: true } 180 }); 181 182 template_effect(() => { 183 set_attribute(input, 'accept', get(accept_file_types)); 184 input.multiple = $$props.file_count === "multiple" || undefined; 185 input.webkitdirectory = $$props.file_count === "directory" || undefined; 186 set_attribute(input, 'mozdirectory', $$props.file_count === "directory" || undefined); 187 set_attribute(input, 'data-testid', `${$$props.label ?? ''}-upload-button`); 188 }); 189 190 append($$anchor, fragment); 191 pop(); 192} 193 194delegate(['change', 'click']); 195 196function Index($$anchor, $$props) { 197 push($$props, true); 198 199 const props = rest_props($$props, ['$$slots', '$$events', '$$legacy']); 200 const gradio = new Gradio(props); 201 let value = proxy(gradio.props.value); 202 203 user_effect(() => { 204 if (value !== gradio.props.value) { 205 gradio.props.value = value; 206 } 207 }); 208 209 async function handle_event(detail, event) { 210 gradio.props.value = detail; 211 gradio.dispatch(event); 212 } 213 214 const disabled = user_derived(() => !gradio.shared.interactive); 215 216 UploadButton($$anchor, { 217 get elem_id() { 218 return gradio.shared.elem_id; 219 }, 220 221 get elem_classes() { 222 return gradio.shared.elem_classes; 223 }, 224 225 get visible() { 226 return gradio.shared.visible; 227 }, 228 229 get file_count() { 230 return gradio.props.file_count; 231 }, 232 233 get file_types() { 234 return gradio.props.file_types; 235 }, 236 237 get size() { 238 return gradio.props.size; 239 }, 240 241 get scale() { 242 return gradio.shared.scale; 243 }, 244 245 get icon() { 246 return gradio.props.icon; 247 }, 248 249 get min_width() { 250 return gradio.shared.min_width; 251 }, 252 253 get root() { 254 return gradio.shared.root; 255 }, 256 257 get value() { 258 return value; 259 }, 260 261 get disabled() { 262 return get(disabled); 263 }, 264 265 get variant() { 266 return gradio.props.variant; 267 }, 268 269 get label() { 270 return gradio.shared.label; 271 }, 272 273 get max_file_size() { 274 return gradio.shared.max_file_size; 275 }, 276 onclick: () => gradio.dispatch("click"),
277 onchange: (detail) => handle_event(detail, "change"), 278 onupload: (detail) => handle_event(detail, "upload"), 279 onerror: (detail) => { 280 gradio.dispatch("error", detail); 281 }, 282 upload: (...args) => gradio.shared.client.upload(...args), 283 children: ($$anchor, $$slotProps) => { 284 next(); 285 286 var text$1 = text(); 287 288 template_effect(() => set_text(text$1, gradio.shared.label ?? "")); 289 append($$anchor, text$1); 290 }, 291 $$slots: { default: true } 292 }); 293 294 pop(); 295} 296 297export { UploadButton as BaseUploadButton, Index as default }; 298//# sourceMappingURL=Index-C_TyKbH0.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.