@gradio/core 0.28.0 → 0.29.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/src/init.ts CHANGED
@@ -89,7 +89,6 @@ export function create_components(
89
89
  value_change_cb = cb;
90
90
  }
91
91
 
92
- // Store current layout and root for dynamic visibility recalculation
93
92
  let current_layout: LayoutNode;
94
93
  let current_root: string;
95
94
 
@@ -123,15 +122,12 @@ export function create_components(
123
122
  fill_height: boolean;
124
123
  };
125
124
  }): Promise<void> {
126
- // make sure the state is settled before proceeding
127
125
  flush();
128
126
  app = _app;
129
127
 
130
128
  if (instance_map) {
131
- // re-render in reload mode
132
129
  components.forEach((c) => {
133
130
  if (c.props.value == null && c.key) {
134
- // If the component has a key, we preserve its value by finding a matching instance with the same key
135
131
  const matching_instance = Object.values(instance_map).find(
136
132
  (instance) => instance.key === c.key
137
133
  );
@@ -150,14 +146,17 @@ export function create_components(
150
146
  _component_map = new Map();
151
147
  instance_map = {};
152
148
 
153
- // Store current layout and root for dynamic visibility recalculation
154
149
  current_layout = layout;
155
150
  current_root = root;
156
151
 
157
152
  _rootNode = {
158
153
  id: layout.id,
159
154
  type: "column",
160
- props: { interactive: false, scale: options.fill_height ? 1 : null },
155
+ props: {
156
+ interactive: false,
157
+ scale: options.fill_height ? 1 : null,
158
+ visible: true
159
+ },
161
160
  has_modes: false,
162
161
  instance: null as unknown as ComponentMeta["instance"],
163
162
  component: null as unknown as ComponentMeta["component"],
@@ -410,7 +409,10 @@ export function create_components(
410
409
  label: child.props.label.includes(i18n_marker) ? "" : child.props.label,
411
410
  id: child.props.id,
412
411
  visible:
413
- typeof child.props.visible === "boolean" ? child.props.visible : true,
412
+ typeof child.props.visible === "boolean" ||
413
+ child.props.visible === "hidden"
414
+ ? child.props.visible
415
+ : true,
414
416
  interactive: child.props.interactive,
415
417
  order: child.props.order
416
418
  }));
@@ -446,7 +448,6 @@ export function create_components(
446
448
  for (const component of components_to_load) {
447
449
  const constructor_key = component.component_class_id || component.type;
448
450
 
449
- // Only load if not already loaded
450
451
  if (!constructor_map.has(constructor_key)) {
451
452
  const { component: loadable_component, example_components } =
452
453
  get_component(
@@ -464,7 +465,6 @@ export function create_components(
464
465
  }
465
466
  }
466
467
 
467
- // Load the component if it doesn't exist yet
468
468
  if (!component.component) {
469
469
  component.component = (await loadable_component)?.default;
470
470
  }
@@ -487,10 +487,8 @@ export function create_components(
487
487
  const instance = instance_map?.[update.id];
488
488
  if (!instance) return false;
489
489
 
490
- // Check for visibility property changes
491
490
  if (update.prop === "visible") return true;
492
491
 
493
- // Check for selected tab changes in tabs components
494
492
  if (update.prop === "selected" && instance.type === "tabs") return true;
495
493
 
496
494
  return false;
@@ -505,7 +503,6 @@ export function create_components(
505
503
  ? [..._component_map.values()]
506
504
  : _components;
507
505
 
508
- // Capture current visibility state before applying updates
509
506
  if (had_visibility_changes && current_layout) {
510
507
  previous_visible_ids = determine_visible_components(
511
508
  current_layout,
@@ -541,10 +538,10 @@ export function create_components(
541
538
  }
542
539
  }
543
540
  }
541
+
544
542
  return layout;
545
543
  });
546
544
 
547
- // After applying updates, check if we need to load new components
548
545
  if (had_visibility_changes && current_layout && previous_visible_ids) {
549
546
  raf(async () => {
550
547
  const new_visible_ids = determine_visible_components(
@@ -553,17 +550,14 @@ export function create_components(
553
550
  );
554
551
  const newly_visible_ids = new Set<number>();
555
552
 
556
- // Find components that are now visible but weren't before
557
553
  for (const id of new_visible_ids) {
558
554
  if (!previous_visible_ids!.has(id)) {
559
555
  newly_visible_ids.add(id);
560
556
  }
561
557
  }
562
558
 
563
- // Load the newly visible components
564
559
  await load_newly_visible_components(newly_visible_ids, all_components);
565
560
 
566
- // Trigger a layout update to render the newly loaded components
567
561
  if (newly_visible_ids.size > 0) {
568
562
  layout_store.update((layout) => layout);
569
563
  }
@@ -906,13 +900,11 @@ function get_selected_tab_id(
906
900
  layout: LayoutNode,
907
901
  components: ComponentMeta[]
908
902
  ): string | number | undefined {
909
- // Check if selected prop is a string or number
910
903
  const selected = component.props.selected;
911
904
  if (typeof selected === "string" || typeof selected === "number") {
912
905
  return selected;
913
906
  }
914
907
 
915
- // If no tab is explicitly selected, find the first visible and interactive tab
916
908
  if (layout.children) {
917
909
  for (const child of layout.children) {
918
910
  const child_component = components.find((c) => c.id === child.id);
@@ -975,27 +967,42 @@ function determine_visible_components(
975
967
  parent_tabs_context?: { selected_tab_id?: string | number }
976
968
  ): Set<number> {
977
969
  const visible_components: Set<number> = new Set();
970
+
978
971
  const component = components.find((c) => c.id === layout.id);
979
972
 
980
973
  if (!component) {
981
974
  return visible_components;
982
975
  }
983
976
 
984
- // Check if the component itself is visible
985
977
  const component_visible =
986
- parent_visible &&
987
- (typeof component.props.visible === "boolean"
988
- ? component.props.visible
989
- : true);
978
+ component.props.visible !== false &&
979
+ component.props.visible !== "hidden" &&
980
+ parent_visible;
981
+
982
+ const should_load = component.props.visible === "hidden" || component_visible;
983
+
984
+ if (!should_load) {
985
+ return visible_components;
986
+ }
987
+
988
+ if (component.type === "tabs") {
989
+ const selected_tab_id = get_selected_tab_id(component, layout, components);
990
+ const tabs_context = { selected_tab_id };
990
991
 
991
- // Handle tab_item special case
992
- if (component.type === "tabitem") {
992
+ visible_components.add(layout.id);
993
+
994
+ const child_visible = process_children_visibility(
995
+ layout,
996
+ components,
997
+ tabs_context
998
+ );
999
+ child_visible.forEach((id) => visible_components.add(id));
1000
+ } else if (component.type === "tabitem") {
993
1001
  if (
994
1002
  is_tab_item_visible(component, component_visible, parent_tabs_context)
995
1003
  ) {
996
- visible_components.add(component.id);
1004
+ visible_components.add(layout.id);
997
1005
 
998
- // Process children if this tab item is visible
999
1006
  const child_visible = process_children_visibility(
1000
1007
  layout,
1001
1008
  components,
@@ -1003,36 +1010,9 @@ function determine_visible_components(
1003
1010
  );
1004
1011
  child_visible.forEach((id) => visible_components.add(id));
1005
1012
  }
1006
- // If tab item is not visible, none of its children should be loaded
1007
- return visible_components;
1008
- }
1009
-
1010
- // Handle tabs component
1011
- if (component.type === "tabs") {
1012
- if (component_visible) {
1013
- visible_components.add(component.id);
1014
-
1015
- // Determine which tab should be selected
1016
- const selected_tab_id = get_selected_tab_id(
1017
- component,
1018
- layout,
1019
- components
1020
- );
1021
-
1022
- // Process children with tabs context
1023
- const child_visible = process_children_visibility(layout, components, {
1024
- selected_tab_id
1025
- });
1026
- child_visible.forEach((id) => visible_components.add(id));
1027
- }
1028
- return visible_components;
1029
- }
1030
-
1031
- // For regular components
1032
- if (component_visible) {
1033
- visible_components.add(component.id);
1013
+ } else {
1014
+ visible_components.add(layout.id);
1034
1015
 
1035
- // Process children if this component is visible
1036
1016
  const child_visible = process_children_visibility(
1037
1017
  layout,
1038
1018
  components,
@@ -1040,7 +1020,6 @@ function determine_visible_components(
1040
1020
  );
1041
1021
  child_visible.forEach((id) => visible_components.add(id));
1042
1022
  }
1043
- // If component is not visible, don't process children
1044
1023
 
1045
1024
  return visible_components;
1046
1025
  }
@@ -1059,13 +1038,11 @@ export function preload_visible_components(
1059
1038
  ): Map<ComponentMeta["type"], LoadingComponent> {
1060
1039
  let constructor_map: Map<ComponentMeta["type"], LoadingComponent> = new Map();
1061
1040
 
1062
- // Determine which components should be visible
1063
1041
  const visible_component_ids = determine_visible_components(
1064
1042
  layout,
1065
1043
  components
1066
1044
  );
1067
1045
 
1068
- // Only preload visible components
1069
1046
  components.forEach((c) => {
1070
1047
  if (visible_component_ids.has(c.id)) {
1071
1048
  const { component, example_components } = get_component(
@@ -1121,12 +1098,21 @@ export function preload_all_components(
1121
1098
  }
1122
1099
 
1123
1100
  function is_visible(component: ComponentMeta): boolean {
1101
+ if (component.props.visible === "hidden") {
1102
+ return true;
1103
+ }
1124
1104
  if (
1125
1105
  typeof component.props.visible === "boolean" &&
1126
1106
  component.props.visible === false
1127
1107
  ) {
1128
1108
  return false;
1129
1109
  } else if (component.parent) {
1110
+ if (component.parent.type === "tabitem") {
1111
+ return is_tab_item_visible(
1112
+ component.parent,
1113
+ is_visible(component.parent)
1114
+ );
1115
+ }
1130
1116
  return is_visible(component.parent);
1131
1117
  }
1132
1118
  return true;
package/src/lang/ar.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "_name": "العربية",
3
3
  "3D_model": {
4
4
  "3d_model": "نموذج ثلاثي الأبعاد",
5
- "drop_to_upload": "اسقط ملف نموذج 3D (.obj، .glb، .stl، .gltf، .splat، أو .ply) هنا للتحميل"
5
+ "drop_to_upload": "اسقط ملف نموذج ثلاثي الأبعاد 3D (.obj، .glb، .stl، .gltf، .splat، أو .ply) هنا للتحميل"
6
6
  },
7
7
  "annotated_image": {
8
8
  "annotated_image": "صورة مشروحة"
@@ -23,10 +23,10 @@
23
23
  "drop_to_upload": "اسقط ملف صوت هنا للتحميل"
24
24
  },
25
25
  "blocks": {
26
- "connection_can_break": "على الهاتف المحمول، يمكن أن ينقطع الاتصال إذا تم تغيير التبويب أو دخل الجهاز في وضع السكون، مما يؤدي إلى فقدان موقعك في قائمة الانتظار.",
27
- "long_requests_queue": "هناك قائمة انتظار طويلة من الطلبات المعلقة. قم بتكرار هذا الفضاء للتخطي.",
28
- "lost_connection": "فقد الاتصال بسبب مغادرة الصفحة. إعادة الانضمام إلى قائمة الانتظار...",
29
- "waiting_for_inputs": "انتظار انتهاء تحميل الملف(ات)، يرجى إعادة المحاولة."
26
+ "connection_can_break": "على الهاتف المحمول، يمكن أن ينقطع الاتصال إذا تم تغيير التبويب لهذه الصفحةة أو دخل الجهاز في وضع السكون، مما يؤدي إلى فقدان موقعك في قائمة الانتظار.",
27
+ "long_requests_queue": "هناك قائمة انتظار طويلة من الطلبات المعلقة. قم بنسخ هذه المساحة للتخطي.",
28
+ "lost_connection": "تم فقدان الاتصال بسبب مغادرة الصفحة. جارٍ إعادة الانضمام إلى قائمة الانتظار...",
29
+ "waiting_for_inputs": "إنتظر انتهاء رفع الملف(ات)، يرجى إعادة المحاولة."
30
30
  },
31
31
  "checkbox": {
32
32
  "checkbox": "خانة اختيار",
@@ -40,9 +40,9 @@
40
40
  },
41
41
  "common": {
42
42
  "built_with": "بُني باستخدام",
43
- "built_with_gradio": "تم الإنشاء بإستخدام Gradio",
43
+ "built_with_gradio": "بني بإستخدام Gradio",
44
44
  "clear": "أمسح",
45
- "download": "تحميل",
45
+ "download": "تنزيل",
46
46
  "edit": "تعديل",
47
47
  "empty": "فارغ",
48
48
  "error": "خطأ",
@@ -58,7 +58,12 @@
58
58
  "no_devices": "لم يتم العثور على أجهزة",
59
59
  "language": "اللغة",
60
60
  "display_theme": "مظهر العرض",
61
- "pwa": "تطبيق ويب تقدمي"
61
+ "pwa": "تطبيق ويب تقدمي",
62
+ "record": "تسجيل",
63
+ "stop_recording": "إيقاف التسجيل",
64
+ "screen_studio": "شاشة الأستوديو",
65
+ "share_gradio_tab": "مشاركة تبويبة صفحة Gradio",
66
+ "run": "تشغيل"
62
67
  },
63
68
  "dataframe": {
64
69
  "incorrect_format": "تنسيق غير صحيح، يتم دعم ملفات CSV و TSV فقط",
@@ -73,8 +78,10 @@
73
78
  "sort_column": "فرز العمود",
74
79
  "sort_ascending": "فرز تصاعدي",
75
80
  "sort_descending": "فرز تنازلي",
76
- "drop_to_upload": "اسقط ملفات CSV أو TSV هنا لاستيراد البيانات إلى الإطار الجدولية",
77
- "clear_sort": "مسح الترتيب"
81
+ "drop_to_upload": "اسقط ملفات CSV أو TSV هنا لاستيراد البيانات إلى الإطر الجدولية",
82
+ "clear_sort": "مسح الترتيب",
83
+ "filter": "مرشح",
84
+ "clear_filter": "مسح المرشحات"
78
85
  },
79
86
  "dropdown": {
80
87
  "dropdown": "قائمة منسدلة"
@@ -82,18 +89,19 @@
82
89
  "errors": {
83
90
  "build_error": "هناك خطأ في البناء",
84
91
  "config_error": "هناك خطأ في التكوين",
85
- "contact_page_author": "يرجى الاتصال بمؤلف الصفحة",
92
+ "contact_page_author": "يرجى التواصل مع مبرمج الصفحة",
86
93
  "no_app_file": "لا يوجد ملف تطبيق",
87
- "runtime_error": "هناك خطأ في وقت التشغيل",
94
+ "runtime_error": "هناك خطأ أثناء التشغيل",
88
95
  "space_not_working": "المساحة لا تعمل لأن {0}",
89
96
  "space_paused": "المساحة متوقفة مؤقتًا",
90
- "use_via_api": "استخدم عبر API"
97
+ "use_via_api": "إستخدام عبر API",
98
+ "use_via_api_or_mcp": "إستخدام عبر واجهة برمجة التطبيقات API أو خادم MCP"
91
99
  },
92
100
  "file": {
93
101
  "uploading": "جاري الرفع..."
94
102
  },
95
103
  "highlighted_text": {
96
- "highlighted_text": "نص مميز"
104
+ "highlighted_text": "نص محدد"
97
105
  },
98
106
  "image": {
99
107
  "allow_webcam_access": "يرجى السماح بالوصول إلى كاميرا الويب للتسجيل.",
package/src/types.ts CHANGED
@@ -8,6 +8,7 @@ interface SharedProps {
8
8
  components?: string[];
9
9
  server_fns?: string[];
10
10
  interactive: boolean;
11
+ visible: boolean | "hidden";
11
12
  [key: string]: unknown;
12
13
  }
13
14
 
@@ -1,11 +0,0 @@
1
- import type { StoryObj } from "@storybook/svelte";
2
- import I18nMultiLanguageTestComponent from "./I18nMultiLanguageTestComponent.svelte";
3
- declare const meta: {
4
- component: typeof I18nMultiLanguageTestComponent;
5
- parameters: {
6
- layout: string;
7
- };
8
- };
9
- export default meta;
10
- type Story = StoryObj<typeof meta>;
11
- export declare const Default: Story;