@gradio/core 1.0.0 → 1.0.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.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,16 @@
1
1
  # @gradio/core
2
+
3
+ ## 1.0.1
4
+
5
+ ### Fixes
6
+
7
+ - [#12416](https://github.com/gradio-app/gradio/pull/12416) [`7e867fd`](https://github.com/gradio-app/gradio/commit/7e867fde9070849fb474a08544c72f2522a9cbe9) - Fix custom components for gradio 6. Thanks @pngwn!
8
+ - [#12461](https://github.com/gradio-app/gradio/pull/12461) [`9a86e80`](https://github.com/gradio-app/gradio/commit/9a86e8064787029bc20b086c6f3191879f786e0f) - Fix Login Gradio 6. Thanks @freddyaboulton!
9
+
10
+ ### Dependency updates
11
+
12
+ - @gradio/utils@0.10.4
13
+
2
14
  ## 1.0.0
3
15
 
4
16
  ### Features
@@ -40,7 +40,6 @@
40
40
  import * as screen_recorder from "./screen_recorder";
41
41
 
42
42
  import { DependencyManager } from "./dependency";
43
-
44
43
  let {
45
44
  root,
46
45
  components,
@@ -138,11 +137,11 @@
138
137
  // trigger_share(title, description);
139
138
  // TODO: lets combine all of the into a log type with levels
140
139
  } else if (event === "error") {
141
- new_message("Error", data, -1, event, 10, true);
140
+ new_message("Error", data as string, -1, event, 10, true);
142
141
  } else if (event === "warning") {
143
- new_message("Warning", data, -1, event, 10, true);
142
+ new_message("Warning", data as string, -1, event, 10, true);
144
143
  } else if (event === "info") {
145
- new_message("Info", data, -1, event, 10, true);
144
+ new_message("Info", data as string, -1, event, 10, true);
146
145
  } else if (event == "clear_status") {
147
146
  app_tree.update_state(
148
147
  id,
@@ -163,7 +162,7 @@
163
162
  // so we need to pull out the correct id here.
164
163
  if (event === "select" && id in app_tree.initial_tabs) {
165
164
  // this is the id of the selected tab
166
- id = data.id;
165
+ id = (data as { id: number }).id;
167
166
  }
168
167
  dep_manager.dispatch({
169
168
  type: "event",
@@ -239,8 +238,8 @@
239
238
  if (!ApiDocs || !ApiRecorder) {
240
239
  const api_docs_module = await import("./api_docs/ApiDocs.svelte");
241
240
  const api_recorder_module = await import("./api_docs/ApiRecorder.svelte");
242
- if (!ApiDocs) ApiDocs = api_docs_module.default;
243
- if (!ApiRecorder) ApiRecorder = api_recorder_module.default;
241
+ if (!ApiDocs) ApiDocs = api_docs_module?.default;
242
+ if (!ApiRecorder) ApiRecorder = api_recorder_module?.default;
244
243
  }
245
244
  }
246
245
 
@@ -1,14 +1,14 @@
1
1
  <script lang="ts">
2
- import Form from "@gradio/form";
2
+ import { BaseForm } from "@gradio/form";
3
3
  import { BaseTextbox as Textbox } from "@gradio/textbox";
4
4
  import { BaseButton } from "@gradio/button";
5
- import Column from "@gradio/column";
5
+ import { BaseColumn } from "@gradio/column";
6
6
  import { Block } from "@gradio/atoms";
7
- import { _ } from "svelte-i18n";
8
7
  export let root: string;
9
8
  export let auth_message: string | null;
10
9
  export let app_mode: boolean;
11
10
  export let space_id: string | null;
11
+ export let i18n: (s: string) => string;
12
12
 
13
13
  let username = "";
14
14
  let password = "";
@@ -34,23 +34,23 @@
34
34
  </script>
35
35
 
36
36
  <div class="wrap" class:min-h-screen={app_mode}>
37
- <Column variant="panel" min_width={480}>
38
- <h2>{$_("login.login")}</h2>
37
+ <BaseColumn variant="panel" min_width={480}>
38
+ <h2>{i18n("login.login")}</h2>
39
39
  {#if auth_message}
40
40
  <p class="auth">{@html auth_message}</p>
41
41
  {/if}
42
42
  {#if space_id}
43
43
  <p class="auth">
44
- {$_("login.enable_cookies")}
44
+ {i18n("login.enable_cookies")}
45
45
  </p>
46
46
  {/if}
47
47
  {#if incorrect_credentials}
48
- <p class="creds">{$_("login.incorrect_credentials")}</p>
48
+ <p class="creds">{i18n("login.incorrect_credentials")}</p>
49
49
  {/if}
50
- <Form>
50
+ <BaseForm>
51
51
  <Block>
52
52
  <Textbox
53
- label={$_("login.username")}
53
+ label={i18n("login.username")}
54
54
  lines={1}
55
55
  show_label={true}
56
56
  max_lines={1}
@@ -61,7 +61,7 @@
61
61
 
62
62
  <Block>
63
63
  <Textbox
64
- label={$_("login.password")}
64
+ label={i18n("login.password")}
65
65
  lines={1}
66
66
  show_label={true}
67
67
  max_lines={1}
@@ -70,12 +70,12 @@
70
70
  bind:value={password}
71
71
  />
72
72
  </Block>
73
- </Form>
73
+ </BaseForm>
74
74
 
75
75
  <BaseButton size="lg" variant="primary" on:click={submit}
76
- >{$_("login.login")}</BaseButton
76
+ >{i18n("login.login")}</BaseButton
77
77
  >
78
- </Column>
78
+ </BaseColumn>
79
79
  </div>
80
80
 
81
81
  <style>
@@ -16,6 +16,7 @@ declare const Login: $$__sveltets_2_IsomorphicComponent<{
16
16
  auth_message: string | null;
17
17
  app_mode: boolean;
18
18
  space_id: string | null;
19
+ i18n: (s: string) => string;
19
20
  }, {
20
21
  [evt: string]: CustomEvent<any>;
21
22
  }, {}, {}, string>;
@@ -2,7 +2,7 @@ import type { ComponentMeta, Dependency as IDependency, LayoutNode, Payload } fr
2
2
  import { Client, type client_return } from "@gradio/client";
3
3
  import { LoadingStatus } from "@gradio/statustracker";
4
4
  import type { ToastMessage } from "@gradio/statustracker";
5
- import type { StatusMessage } from "@gradio/client";
5
+ import type { StatusMessage, LogMessage } from "@gradio/client";
6
6
  /**
7
7
  * A dependency as used by the frontend
8
8
  * This class represents a discrete dependency that can be triggered by an event
@@ -58,6 +58,10 @@ interface DispatchEvent {
58
58
  target_id?: number;
59
59
  event_data: unknown;
60
60
  }
61
+ type UpdateStateCallback = (id: number, state: Record<string, unknown>, check_visibility?: boolean) => Promise<void>;
62
+ type GetStateCallback = (id: number) => Promise<Record<string, unknown> | null>;
63
+ type RerenderCallback = (components: ComponentMeta[], layout: LayoutNode) => void;
64
+ type LogCallback = (title: string, message: string, fn_index: number, type: ToastMessage["type"], duration?: number | null, visible?: boolean) => void;
61
65
  /**
62
66
  * Manages all dependencies for an app acting as a bridge between app state and Dependencies
63
67
  * Responsible for registering dependencies and dispatching events to them
@@ -77,13 +81,13 @@ export declare class DependencyManager {
77
81
  client: Client;
78
82
  queue: Set<number>;
79
83
  add_to_api_calls: (payload: Payload) => void;
80
- update_state_cb: (id: number, state: Record<string, unknown>, check_visibility?: boolean) => Promise<void>;
81
- get_state_cb: (id: number) => Promise<Record<string, unknown> | null>;
82
- rerender_cb: (components: ComponentMeta[], layout: LayoutNode) => void;
83
- log_cb: (title: string, message: string, fn_index: number, type: ToastMessage["type"], duration?: number | null, visible?: boolean) => void;
84
+ update_state_cb: UpdateStateCallback;
85
+ get_state_cb: GetStateCallback;
86
+ rerender_cb: RerenderCallback;
87
+ log_cb: LogCallback;
84
88
  loading_stati: LoadingStatus;
85
89
  constructor(dependencies: IDependency[], client: Client, update_state_cb: (id: number, state: Record<string, unknown>, check_visibility?: boolean) => Promise<void>, get_state_cb: (id: number) => Promise<Record<string, unknown> | null>, rerender_cb: (components: ComponentMeta[], layout: LayoutNode) => void, log_cb: (title: string, message: string, fn_index: number, type: ToastMessage["type"], duration?: number | null, visible?: boolean) => void, add_to_api_calls: (payload: Payload) => void);
86
- reload(dependencies: IDependency[], update_state: any, get_state: any, rerender: any, client: any): void;
90
+ reload(dependencies: IDependency[], update_state: UpdateStateCallback, get_state: GetStateCallback, rerender: RerenderCallback, client: Client): void;
87
91
  register_loading_stati(deps: Map<number, Dependency>): void;
88
92
  clear_loading_status(component_id: number): void;
89
93
  update_loading_stati_state(): Promise<void>;
@@ -125,6 +125,7 @@ export class DependencyManager {
125
125
  this.update_state_cb = update_state_cb;
126
126
  this.get_state_cb = get_state_cb;
127
127
  this.rerender_cb = rerender_cb;
128
+ this.client = client;
128
129
  this.reload(dependencies, update_state_cb, get_state_cb, rerender_cb, client);
129
130
  }
130
131
  reload(dependencies, update_state, get_state, rerender, client) {
@@ -344,7 +345,9 @@ export class DependencyManager {
344
345
  return;
345
346
  }
346
347
  const _message = result?.message?.replace(MESSAGE_QUOTE_RE, (_, b) => b);
347
- this.log_cb(result._title ?? "Error", _message, fn_index, "error", status.duration, status.visible);
348
+ this.log_cb(
349
+ //@ts-ignore
350
+ result?._title ?? "Error", _message || "", fn_index, "error", status.duration, status.visible);
348
351
  throw new Error("Dependency function failed");
349
352
  }
350
353
  else {
@@ -27,8 +27,8 @@ export declare class AppTree {
27
27
  ready: Promise<void>;
28
28
  ready_resolve: () => void;
29
29
  resolved: boolean;
30
- constructor(components: ComponentMeta[], layout: LayoutNode, dependencies: Dependency[], config: AppConfig, app: client_return, reactive_formatter: (str: string) => string);
31
- reload(components: ComponentMeta[], layout: LayoutNode, dependencies: Dependency[], config: AppConfig): void;
30
+ constructor(components: ComponentMeta[], layout: LayoutNode, dependencies: Dependency[], config: Omit<AppConfig, "api_url">, app: client_return, reactive_formatter: (str: string) => string);
31
+ reload(components: ComponentMeta[], layout: LayoutNode, dependencies: Dependency[], config: Omit<AppConfig, "api_url">): void;
32
32
  /**
33
33
  * Registers a component with its ID and data callbacks
34
34
  * @param id the ID of the component
@@ -40,7 +40,10 @@ export class AppTree {
40
40
  this.ready_resolve = resolve;
41
41
  });
42
42
  this.reactive_formatter = reactive_formatter;
43
- this.#config = config;
43
+ this.#config = {
44
+ ...config,
45
+ api_url: new URL(config.api_prefix, config.root).toString()
46
+ };
44
47
  this.#component_payload = components;
45
48
  this.#layout_payload = layout;
46
49
  this.#dependency_payload = dependencies;
@@ -67,7 +70,10 @@ export class AppTree {
67
70
  reload(components, layout, dependencies, config) {
68
71
  this.#layout_payload = layout;
69
72
  this.#component_payload = components;
70
- this.#config = config;
73
+ this.#config = {
74
+ ...config,
75
+ api_url: new URL(config.api_prefix, config.root).toString()
76
+ };
71
77
  this.#dependency_payload = dependencies;
72
78
  this.root = this.create_node({ id: layout.id, children: [] }, new Map(), true);
73
79
  for (const comp of components) {
@@ -115,11 +121,11 @@ export class AppTree {
115
121
  process() { }
116
122
  postprocess(tree) {
117
123
  this.root = this.traverse(tree, [
118
- (node) => handle_visibility(node, this.#config.root),
119
- (node) => untrack_children_of_invisible_parents(node, this.#config.root, this.components_to_register),
120
- (node) => handle_empty_forms(node, this.#config.root, this.components_to_register),
121
- (node) => translate_props(node, this.#config.root),
122
- (node) => apply_initial_tabs(node, this.#config.root, this.initial_tabs),
124
+ (node) => handle_visibility(node, this.#config.api_url),
125
+ (node) => untrack_children_of_invisible_parents(node, this.components_to_register),
126
+ (node) => handle_empty_forms(node, this.components_to_register),
127
+ (node) => translate_props(node),
128
+ (node) => apply_initial_tabs(node, this.initial_tabs),
123
129
  (node) => this.find_attached_events(node, this.#dependency_payload)
124
130
  ]);
125
131
  }
@@ -191,7 +197,7 @@ export class AppTree {
191
197
  if (reactive_formatter) {
192
198
  component.props.i18n = reactive_formatter;
193
199
  }
194
- const processed_props = gather_props(opts.id, component.props, [this.#input_ids, this.#output_ids], this.client, { ...this.#config });
200
+ const processed_props = gather_props(opts.id, component.props, [this.#input_ids, this.#output_ids], this.client, this.#config.api_url, { ...this.#config });
195
201
  const type = type_map[component.type] || component.type;
196
202
  const node = {
197
203
  id: opts.id,
@@ -201,7 +207,7 @@ export class AppTree {
201
207
  show_progress_on: null,
202
208
  component_class_id: component.component_class_id || component.type,
203
209
  component: processed_props.shared_props.visible !== false
204
- ? get_component(component.type, component.component_class_id, this.#config.root || "")
210
+ ? get_component(component.type, component.component_class_id, this.#config.api_url || "")
205
211
  : null,
206
212
  key: component.key,
207
213
  rendered_in: component.rendered_in,
@@ -242,7 +248,7 @@ export class AppTree {
242
248
  this.root = this.traverse(this.root, [
243
249
  //@ts-ignore
244
250
  (n) => set_visibility_for_updated_node(n, id, new_state.visible),
245
- (n) => handle_visibility(n, this.#config.root)
251
+ (n) => handle_visibility(n, this.#config.api_url)
246
252
  ]);
247
253
  already_updated_visibility = true;
248
254
  }
@@ -255,7 +261,7 @@ export class AppTree {
255
261
  // need to let the UI settle before traversing again
256
262
  // otherwise there could be
257
263
  await tick();
258
- this.root = this.traverse(this.root, (n) => handle_visibility(n, this.#config.root));
264
+ this.root = this.traverse(this.root, (n) => handle_visibility(n, this.#config.api_url));
259
265
  }
260
266
  /**
261
267
  * Gets the current state of a component by its ID
@@ -304,7 +310,7 @@ export function process_server_fn(id, server_fns, app) {
304
310
  * @param additional any additional props to include
305
311
  * @returns the gathered props as an object with `shared_props` and `props` keys
306
312
  */
307
- function gather_props(id, props, dependencies, client, additional = {}) {
313
+ function gather_props(id, props, dependencies, client, api_url, additional = {}) {
308
314
  const _shared_props = {};
309
315
  const _props = {};
310
316
  for (const key in props) {
@@ -336,22 +342,22 @@ function gather_props(id, props, dependencies, client, additional = {}) {
336
342
  _shared_props.client = client;
337
343
  _shared_props.id = id;
338
344
  _shared_props.interactive = determine_interactivity(id, _shared_props.interactive, _props.value, dependencies);
339
- _shared_props.load_component = (name, variant) => get_component(name, "", _shared_props.root || "", variant);
345
+ _shared_props.load_component = (name, variant) => get_component(name, "", api_url, variant);
340
346
  _shared_props.visible =
341
347
  _shared_props.visible === undefined ? true : _shared_props.visible;
342
348
  _shared_props.loading_status = {};
343
349
  return { shared_props: _shared_props, props: _props };
344
350
  }
345
- function handle_visibility(node, root) {
351
+ function handle_visibility(node, api_url) {
346
352
  // Check if the node is visible
347
353
  if (node.props.shared_props.visible && !node.component) {
348
354
  const result = {
349
355
  ...node,
350
- component: get_component(node.type, node.component_class_id, root),
356
+ component: get_component(node.type, node.component_class_id, api_url),
351
357
  children: []
352
358
  };
353
359
  if (node.children) {
354
- result.children = node.children.map((child) => handle_visibility(child, root));
360
+ result.children = node.children.map((child) => handle_visibility(child, api_url));
355
361
  }
356
362
  return result;
357
363
  }
@@ -372,14 +378,14 @@ function _untrack(node, components_to_register) {
372
378
  }
373
379
  return;
374
380
  }
375
- function untrack_children_of_invisible_parents(node, root, components_to_register) {
381
+ function untrack_children_of_invisible_parents(node, components_to_register) {
376
382
  // Check if the node is visible
377
383
  if (node.props.shared_props.visible !== true) {
378
384
  _untrack(node, components_to_register);
379
385
  }
380
386
  return node;
381
387
  }
382
- function handle_empty_forms(node, root, components_to_register) {
388
+ function handle_empty_forms(node, components_to_register) {
383
389
  // Check if the node is visible
384
390
  if (node.type === "form") {
385
391
  const all_children_invisible = node.children.every((child) => child.props.shared_props.visible === false);
@@ -391,7 +397,7 @@ function handle_empty_forms(node, root, components_to_register) {
391
397
  }
392
398
  return node;
393
399
  }
394
- function translate_props(node, root) {
400
+ function translate_props(node) {
395
401
  const supported_props = [
396
402
  "description",
397
403
  "info",
@@ -413,7 +419,7 @@ function translate_props(node, root) {
413
419
  }
414
420
  return node;
415
421
  }
416
- function apply_initial_tabs(node, root, initial_tabs) {
422
+ function apply_initial_tabs(node, initial_tabs) {
417
423
  if (node.type === "tabs" && node.id in initial_tabs) {
418
424
  const tabs = initial_tabs[node.id].sort((a, b) => a.order - b.order);
419
425
  node.props.props.initial_tabs = tabs;
@@ -107,5 +107,6 @@ export interface AppConfig {
107
107
  max_file_size?: number;
108
108
  autoscroll: boolean;
109
109
  api_prefix: string;
110
+ api_url: string;
110
111
  }
111
112
  export {};
package/package.json CHANGED
@@ -1,67 +1,67 @@
1
1
  {
2
2
  "name": "@gradio/core",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "devDependencies": {
6
- "@gradio/accordion": "^0.5.25",
7
- "@gradio/audio": "^0.20.0",
6
+ "@gradio/annotatedimage": "^0.10.1",
8
7
  "@gradio/atoms": "^0.19.0",
9
8
  "@gradio/box": "^0.2.26",
10
9
  "@gradio/browserstate": "^0.3.3",
11
10
  "@gradio/button": "^0.5.14",
12
- "@gradio/annotatedimage": "^0.10.1",
13
- "@gradio/chatbot": "^0.28.0",
14
11
  "@gradio/checkbox": "^0.5.0",
12
+ "@gradio/chatbot": "^0.28.0",
15
13
  "@gradio/client": "^2.0.0",
14
+ "@gradio/audio": "^0.20.0",
16
15
  "@gradio/checkboxgroup": "^0.8.0",
17
- "@gradio/column": "^0.3.0",
18
- "@gradio/code": "^0.16.0",
16
+ "@gradio/accordion": "^0.5.25",
19
17
  "@gradio/colorpicker": "^0.5.0",
18
+ "@gradio/code": "^0.16.0",
20
19
  "@gradio/dataframe": "^0.21.0",
20
+ "@gradio/column": "^0.3.0",
21
21
  "@gradio/dataset": "^0.5.0",
22
- "@gradio/downloadbutton": "^0.4.13",
23
22
  "@gradio/datetime": "^0.3.23",
23
+ "@gradio/downloadbutton": "^0.4.13",
24
24
  "@gradio/dropdown": "^0.10.6",
25
- "@gradio/file": "^0.13.1",
26
25
  "@gradio/fallback": "^0.4.30",
26
+ "@gradio/file": "^0.13.1",
27
+ "@gradio/form": "^0.2.27",
27
28
  "@gradio/fileexplorer": "^0.5.42",
28
- "@gradio/group": "^0.3.0",
29
29
  "@gradio/gallery": "^0.15.35",
30
- "@gradio/form": "^0.2.26",
30
+ "@gradio/group": "^0.3.0",
31
31
  "@gradio/highlightedtext": "^0.9.14",
32
32
  "@gradio/html": "^0.8.0",
33
- "@gradio/icons": "^0.15.0",
34
33
  "@gradio/image": "^0.24.0",
35
34
  "@gradio/imageeditor": "^0.18.2",
35
+ "@gradio/icons": "^0.15.0",
36
36
  "@gradio/imageslider": "^0.3.1",
37
37
  "@gradio/json": "^0.5.32",
38
- "@gradio/model3d": "^0.15.1",
39
38
  "@gradio/markdown": "^0.13.23",
40
39
  "@gradio/label": "^0.5.22",
40
+ "@gradio/model3d": "^0.15.1",
41
41
  "@gradio/multimodaltextbox": "^0.11.0",
42
42
  "@gradio/nativeplot": "^0.9.0",
43
- "@gradio/paramviewer": "^0.9.0",
44
43
  "@gradio/number": "^0.7.2",
44
+ "@gradio/paramviewer": "^0.9.0",
45
45
  "@gradio/plot": "^0.9.25",
46
- "@gradio/row": "^0.3.0",
47
46
  "@gradio/radio": "^0.8.0",
47
+ "@gradio/row": "^0.3.0",
48
48
  "@gradio/sidebar": "^0.1.24",
49
49
  "@gradio/simpledropdown": "^0.3.30",
50
- "@gradio/simpleimage": "^0.9.1",
51
50
  "@gradio/simpletextbox": "^0.3.31",
52
51
  "@gradio/slider": "^0.7.0",
52
+ "@gradio/simpleimage": "^0.9.1",
53
53
  "@gradio/state": "^0.2.0",
54
- "@gradio/statustracker": "^0.12.0",
55
54
  "@gradio/tabitem": "^0.6.2",
56
55
  "@gradio/tabs": "^0.5.2",
57
56
  "@gradio/textbox": "^0.12.0",
57
+ "@gradio/statustracker": "^0.12.0",
58
58
  "@gradio/theme": "^0.5.0",
59
59
  "@gradio/timer": "^0.4.6",
60
- "@gradio/uploadbutton": "^0.9.13",
61
60
  "@gradio/upload": "^0.17.2",
62
- "@gradio/vibeeditor": "^0.3.1",
63
- "@gradio/utils": "^0.10.3",
64
- "@gradio/video": "^0.17.0"
61
+ "@gradio/utils": "^0.10.4",
62
+ "@gradio/uploadbutton": "^0.9.13",
63
+ "@gradio/video": "^0.17.0",
64
+ "@gradio/vibeeditor": "^0.3.1"
65
65
  },
66
66
  "msw": {
67
67
  "workerDirectory": "public"
package/src/Blocks.svelte CHANGED
@@ -40,7 +40,6 @@
40
40
  import * as screen_recorder from "./screen_recorder";
41
41
 
42
42
  import { DependencyManager } from "./dependency";
43
-
44
43
  let {
45
44
  root,
46
45
  components,
@@ -138,11 +137,11 @@
138
137
  // trigger_share(title, description);
139
138
  // TODO: lets combine all of the into a log type with levels
140
139
  } else if (event === "error") {
141
- new_message("Error", data, -1, event, 10, true);
140
+ new_message("Error", data as string, -1, event, 10, true);
142
141
  } else if (event === "warning") {
143
- new_message("Warning", data, -1, event, 10, true);
142
+ new_message("Warning", data as string, -1, event, 10, true);
144
143
  } else if (event === "info") {
145
- new_message("Info", data, -1, event, 10, true);
144
+ new_message("Info", data as string, -1, event, 10, true);
146
145
  } else if (event == "clear_status") {
147
146
  app_tree.update_state(
148
147
  id,
@@ -163,7 +162,7 @@
163
162
  // so we need to pull out the correct id here.
164
163
  if (event === "select" && id in app_tree.initial_tabs) {
165
164
  // this is the id of the selected tab
166
- id = data.id;
165
+ id = (data as { id: number }).id;
167
166
  }
168
167
  dep_manager.dispatch({
169
168
  type: "event",
@@ -239,8 +238,8 @@
239
238
  if (!ApiDocs || !ApiRecorder) {
240
239
  const api_docs_module = await import("./api_docs/ApiDocs.svelte");
241
240
  const api_recorder_module = await import("./api_docs/ApiRecorder.svelte");
242
- if (!ApiDocs) ApiDocs = api_docs_module.default;
243
- if (!ApiRecorder) ApiRecorder = api_recorder_module.default;
241
+ if (!ApiDocs) ApiDocs = api_docs_module?.default;
242
+ if (!ApiRecorder) ApiRecorder = api_recorder_module?.default;
244
243
  }
245
244
  }
246
245
 
package/src/Login.svelte CHANGED
@@ -1,14 +1,14 @@
1
1
  <script lang="ts">
2
- import Form from "@gradio/form";
2
+ import { BaseForm } from "@gradio/form";
3
3
  import { BaseTextbox as Textbox } from "@gradio/textbox";
4
4
  import { BaseButton } from "@gradio/button";
5
- import Column from "@gradio/column";
5
+ import { BaseColumn } from "@gradio/column";
6
6
  import { Block } from "@gradio/atoms";
7
- import { _ } from "svelte-i18n";
8
7
  export let root: string;
9
8
  export let auth_message: string | null;
10
9
  export let app_mode: boolean;
11
10
  export let space_id: string | null;
11
+ export let i18n: (s: string) => string;
12
12
 
13
13
  let username = "";
14
14
  let password = "";
@@ -34,23 +34,23 @@
34
34
  </script>
35
35
 
36
36
  <div class="wrap" class:min-h-screen={app_mode}>
37
- <Column variant="panel" min_width={480}>
38
- <h2>{$_("login.login")}</h2>
37
+ <BaseColumn variant="panel" min_width={480}>
38
+ <h2>{i18n("login.login")}</h2>
39
39
  {#if auth_message}
40
40
  <p class="auth">{@html auth_message}</p>
41
41
  {/if}
42
42
  {#if space_id}
43
43
  <p class="auth">
44
- {$_("login.enable_cookies")}
44
+ {i18n("login.enable_cookies")}
45
45
  </p>
46
46
  {/if}
47
47
  {#if incorrect_credentials}
48
- <p class="creds">{$_("login.incorrect_credentials")}</p>
48
+ <p class="creds">{i18n("login.incorrect_credentials")}</p>
49
49
  {/if}
50
- <Form>
50
+ <BaseForm>
51
51
  <Block>
52
52
  <Textbox
53
- label={$_("login.username")}
53
+ label={i18n("login.username")}
54
54
  lines={1}
55
55
  show_label={true}
56
56
  max_lines={1}
@@ -61,7 +61,7 @@
61
61
 
62
62
  <Block>
63
63
  <Textbox
64
- label={$_("login.password")}
64
+ label={i18n("login.password")}
65
65
  lines={1}
66
66
  show_label={true}
67
67
  max_lines={1}
@@ -70,12 +70,12 @@
70
70
  bind:value={password}
71
71
  />
72
72
  </Block>
73
- </Form>
73
+ </BaseForm>
74
74
 
75
75
  <BaseButton size="lg" variant="primary" on:click={submit}
76
- >{$_("login.login")}</BaseButton
76
+ >{i18n("login.login")}</BaseButton
77
77
  >
78
- </Column>
78
+ </BaseColumn>
79
79
  </div>
80
80
 
81
81
  <style>
package/src/dependency.ts CHANGED
@@ -9,7 +9,11 @@ import { AsyncFunction } from "./init_utils";
9
9
  import { Client, type client_return } from "@gradio/client";
10
10
  import { LoadingStatus, type LoadingStatusArgs } from "@gradio/statustracker";
11
11
  import type { ToastMessage } from "@gradio/statustracker";
12
- import type { StatusMessage, ValidationError } from "@gradio/client";
12
+ import type {
13
+ StatusMessage,
14
+ ValidationError,
15
+ LogMessage
16
+ } from "@gradio/client";
13
17
  const MESSAGE_QUOTE_RE = /^'([^]+)'$/;
14
18
 
15
19
  const NOVALUE = Symbol("NOVALUE");
@@ -150,6 +154,25 @@ interface DispatchEvent {
150
154
  event_data: unknown;
151
155
  }
152
156
 
157
+ type UpdateStateCallback = (
158
+ id: number,
159
+ state: Record<string, unknown>,
160
+ check_visibility?: boolean
161
+ ) => Promise<void>;
162
+ type GetStateCallback = (id: number) => Promise<Record<string, unknown> | null>;
163
+ type RerenderCallback = (
164
+ components: ComponentMeta[],
165
+ layout: LayoutNode
166
+ ) => void;
167
+ type LogCallback = (
168
+ title: string,
169
+ message: string,
170
+ fn_index: number,
171
+ type: ToastMessage["type"],
172
+ duration?: number | null,
173
+ visible?: boolean
174
+ ) => void;
175
+
153
176
  /**
154
177
  * Manages all dependencies for an app acting as a bridge between app state and Dependencies
155
178
  * Responsible for registering dependencies and dispatching events to them
@@ -171,21 +194,11 @@ export class DependencyManager {
171
194
  queue: Set<number> = new Set();
172
195
  add_to_api_calls: (payload: Payload) => void;
173
196
 
174
- update_state_cb: (
175
- id: number,
176
- state: Record<string, unknown>,
177
- check_visibility?: boolean
178
- ) => Promise<void>;
179
- get_state_cb: (id: number) => Promise<Record<string, unknown> | null>;
180
- rerender_cb: (components: ComponentMeta[], layout: LayoutNode) => void;
181
- log_cb: (
182
- title: string,
183
- message: string,
184
- fn_index: number,
185
- type: ToastMessage["type"],
186
- duration?: number | null,
187
- visible?: boolean
188
- ) => void;
197
+ update_state_cb: UpdateStateCallback;
198
+ get_state_cb: GetStateCallback;
199
+ rerender_cb: RerenderCallback;
200
+ log_cb: LogCallback;
201
+
189
202
  loading_stati = new LoadingStatus();
190
203
 
191
204
  constructor(
@@ -213,6 +226,7 @@ export class DependencyManager {
213
226
  this.update_state_cb = update_state_cb;
214
227
  this.get_state_cb = get_state_cb;
215
228
  this.rerender_cb = rerender_cb;
229
+ this.client = client;
216
230
  this.reload(
217
231
  dependencies,
218
232
  update_state_cb,
@@ -224,10 +238,10 @@ export class DependencyManager {
224
238
 
225
239
  reload(
226
240
  dependencies: IDependency[],
227
- update_state,
228
- get_state,
229
- rerender,
230
- client
241
+ update_state: UpdateStateCallback,
242
+ get_state: GetStateCallback,
243
+ rerender: RerenderCallback,
244
+ client: Client
231
245
  ) {
232
246
  const { by_id, by_event } = this.create(dependencies);
233
247
  this.dependencies_by_event = by_event;
@@ -367,7 +381,7 @@ export class DependencyManager {
367
381
  data: data_payload,
368
382
  event_data: event_meta.event_data
369
383
  };
370
- submission!.send_chunk(payload);
384
+ submission!.send_chunk(payload as any);
371
385
  unset_args.forEach((fn) => fn());
372
386
  continue;
373
387
  }
@@ -508,8 +522,9 @@ export class DependencyManager {
508
522
  (_, b) => b
509
523
  );
510
524
  this.log_cb(
511
- result._title ?? "Error",
512
- _message,
525
+ //@ts-ignore
526
+ result?._title ?? "Error",
527
+ _message || "",
513
528
  fn_index,
514
529
  "error",
515
530
  status.duration,
@@ -77,7 +77,7 @@ export class AppTree {
77
77
  components: ComponentMeta[],
78
78
  layout: LayoutNode,
79
79
  dependencies: Dependency[],
80
- config: AppConfig,
80
+ config: Omit<AppConfig, "api_url">,
81
81
  app: client_return,
82
82
  reactive_formatter: (str: string) => string
83
83
  ) {
@@ -85,8 +85,10 @@ export class AppTree {
85
85
  this.ready_resolve = resolve;
86
86
  });
87
87
  this.reactive_formatter = reactive_formatter;
88
-
89
- this.#config = config;
88
+ this.#config = {
89
+ ...config,
90
+ api_url: new URL(config.api_prefix, config.root).toString()
91
+ };
90
92
  this.#component_payload = components;
91
93
  this.#layout_payload = layout;
92
94
  this.#dependency_payload = dependencies;
@@ -129,11 +131,14 @@ export class AppTree {
129
131
  components: ComponentMeta[],
130
132
  layout: LayoutNode,
131
133
  dependencies: Dependency[],
132
- config: AppConfig
134
+ config: Omit<AppConfig, "api_url">
133
135
  ) {
134
136
  this.#layout_payload = layout;
135
137
  this.#component_payload = components;
136
- this.#config = config;
138
+ this.#config = {
139
+ ...config,
140
+ api_url: new URL(config.api_prefix, config.root).toString()
141
+ };
137
142
  this.#dependency_payload = dependencies;
138
143
 
139
144
  this.root = this.create_node(
@@ -203,21 +208,15 @@ export class AppTree {
203
208
 
204
209
  postprocess(tree: ProcessedComponentMeta) {
205
210
  this.root = this.traverse(tree, [
206
- (node) => handle_visibility(node, this.#config.root),
211
+ (node) => handle_visibility(node, this.#config.api_url),
207
212
  (node) =>
208
213
  untrack_children_of_invisible_parents(
209
214
  node,
210
- this.#config.root,
211
215
  this.components_to_register
212
216
  ),
213
- (node) =>
214
- handle_empty_forms(
215
- node,
216
- this.#config.root,
217
- this.components_to_register
218
- ),
219
- (node) => translate_props(node, this.#config.root),
220
- (node) => apply_initial_tabs(node, this.#config.root, this.initial_tabs),
217
+ (node) => handle_empty_forms(node, this.components_to_register),
218
+ (node) => translate_props(node),
219
+ (node) => apply_initial_tabs(node, this.initial_tabs),
221
220
  (node) => this.find_attached_events(node, this.#dependency_payload)
222
221
  ]);
223
222
  }
@@ -317,6 +316,7 @@ export class AppTree {
317
316
  component.props,
318
317
  [this.#input_ids, this.#output_ids],
319
318
  this.client,
319
+ this.#config.api_url,
320
320
  { ...this.#config }
321
321
  );
322
322
 
@@ -335,7 +335,7 @@ export class AppTree {
335
335
  ? get_component(
336
336
  component.type,
337
337
  component.component_class_id,
338
- this.#config.root || ""
338
+ this.#config.api_url || ""
339
339
  )
340
340
  : null,
341
341
  key: component.key,
@@ -391,7 +391,7 @@ export class AppTree {
391
391
  this.root = this.traverse(this.root!, [
392
392
  //@ts-ignore
393
393
  (n) => set_visibility_for_updated_node(n, id, new_state.visible),
394
- (n) => handle_visibility(n, this.#config.root)
394
+ (n) => handle_visibility(n, this.#config.api_url)
395
395
  ]);
396
396
  already_updated_visibility = true;
397
397
  }
@@ -403,7 +403,7 @@ export class AppTree {
403
403
  // otherwise there could be
404
404
  await tick();
405
405
  this.root = this.traverse(this.root!, (n) =>
406
- handle_visibility(n, this.#config.root)
406
+ handle_visibility(n, this.#config.api_url)
407
407
  );
408
408
  }
409
409
 
@@ -464,6 +464,7 @@ function gather_props(
464
464
  props: ComponentMeta["props"],
465
465
  dependencies: [Set<number>, Set<number>],
466
466
  client: client_return,
467
+ api_url: string,
467
468
  additional: Record<string, unknown> = {}
468
469
  ): {
469
470
  shared_props: SharedProps;
@@ -508,13 +509,7 @@ function gather_props(
508
509
  _shared_props.load_component = (
509
510
  name: string,
510
511
  variant: "base" | "component" | "example"
511
- ) =>
512
- get_component(
513
- name,
514
- "",
515
- _shared_props.root || "",
516
- variant
517
- ) as LoadingComponent;
512
+ ) => get_component(name, "", api_url, variant) as LoadingComponent;
518
513
 
519
514
  _shared_props.visible =
520
515
  _shared_props.visible === undefined ? true : _shared_props.visible;
@@ -525,19 +520,19 @@ function gather_props(
525
520
 
526
521
  function handle_visibility(
527
522
  node: ProcessedComponentMeta,
528
- root: string
523
+ api_url: string
529
524
  ): ProcessedComponentMeta {
530
525
  // Check if the node is visible
531
526
  if (node.props.shared_props.visible && !node.component) {
532
527
  const result: ProcessedComponentMeta = {
533
528
  ...node,
534
- component: get_component(node.type, node.component_class_id, root),
529
+ component: get_component(node.type, node.component_class_id, api_url),
535
530
  children: []
536
531
  };
537
532
 
538
533
  if (node.children) {
539
534
  result.children = node.children.map((child) =>
540
- handle_visibility(child, root)
535
+ handle_visibility(child, api_url)
541
536
  );
542
537
  }
543
538
  return result;
@@ -570,7 +565,6 @@ function _untrack(
570
565
 
571
566
  function untrack_children_of_invisible_parents(
572
567
  node: ProcessedComponentMeta,
573
- root: string,
574
568
  components_to_register: Set<number>
575
569
  ): ProcessedComponentMeta {
576
570
  // Check if the node is visible
@@ -582,7 +576,6 @@ function untrack_children_of_invisible_parents(
582
576
 
583
577
  function handle_empty_forms(
584
578
  node: ProcessedComponentMeta,
585
- root: string,
586
579
  components_to_register: Set<number>
587
580
  ): ProcessedComponentMeta {
588
581
  // Check if the node is visible
@@ -601,10 +594,7 @@ function handle_empty_forms(
601
594
  return node;
602
595
  }
603
596
 
604
- function translate_props(
605
- node: ProcessedComponentMeta,
606
- root: string
607
- ): ProcessedComponentMeta {
597
+ function translate_props(node: ProcessedComponentMeta): ProcessedComponentMeta {
608
598
  const supported_props = [
609
599
  "description",
610
600
  "info",
@@ -631,7 +621,6 @@ function translate_props(
631
621
 
632
622
  function apply_initial_tabs(
633
623
  node: ProcessedComponentMeta,
634
- root: string,
635
624
  initial_tabs: Record<number, Tab[]>
636
625
  ): ProcessedComponentMeta {
637
626
  if (node.type === "tabs" && node.id in initial_tabs) {
package/src/types.ts CHANGED
@@ -126,4 +126,5 @@ export interface AppConfig {
126
126
  max_file_size?: number;
127
127
  autoscroll: boolean;
128
128
  api_prefix: string;
129
+ api_url: string;
129
130
  }