gradio-pr-bot commited on
Commit
d25e420
·
verified ·
1 Parent(s): e6528cd

Upload folder using huggingface_hub

Browse files
6.13.0/tabs/package.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "@gradio/tabs",
3
- "version": "0.5.9",
4
  "description": "Gradio UI packages",
5
  "type": "module",
6
  "author": "",
 
1
  {
2
  "name": "@gradio/tabs",
3
+ "version": "0.5.10",
4
  "description": "Gradio UI packages",
5
  "type": "module",
6
  "author": "",
6.13.0/tabs/shared/Tabs.svelte CHANGED
@@ -70,10 +70,11 @@
70
 
71
  onMount(() => {
72
  if (!tab_nav_el) return;
73
- const observer = new IntersectionObserver((entries) => {
74
  handle_menu_overflow();
75
  });
76
- observer.observe(tab_nav_el);
 
77
  });
78
 
79
  setContext(TABS, {
@@ -128,33 +129,42 @@
128
  }
129
  }
130
 
 
 
 
131
  async function handle_menu_overflow(): Promise<void> {
132
  if (!tab_nav_el) return;
133
 
134
  await tick();
135
- const tab_nav_size = tab_nav_el.getBoundingClientRect();
 
 
136
 
137
- let max_width = tab_nav_size.width;
138
- const tab_sizes = get_tab_sizes(tabs, tab_els);
139
- let last_visible_index = 0;
140
- const offset = tab_nav_size.left;
141
 
142
- for (let i = tabs.length - 1; i >= 0; i--) {
143
  const tab = tabs[i];
144
- if (!tab) continue;
145
- const tab_rect = tab_sizes[tab.id];
146
- if (!tab_rect) continue;
147
- if (tab_rect.right - offset < max_width) {
148
- last_visible_index = i;
 
 
 
 
 
149
  break;
150
  }
151
  }
152
 
153
- overflow_tabs = tabs.slice(last_visible_index + 1);
154
- visible_tabs = tabs.slice(0, last_visible_index + 1);
155
 
156
  overflow_has_selected_tab = handle_overflow_has_selected_tab($selected_tab);
157
- is_overflowing = overflow_tabs.length > 0;
 
158
  }
159
 
160
  $: overflow_has_selected_tab =
@@ -167,18 +177,6 @@
167
  return overflow_tabs.some((t) => t?.id === selected_tab);
168
  }
169
 
170
- function get_tab_sizes(
171
- tabs: (Tab | null)[],
172
- tab_els: Record<string | number, HTMLElement>
173
- ): Record<string | number, DOMRect> {
174
- const tab_sizes: Record<string | number, DOMRect> = {};
175
- tabs.forEach((tab) => {
176
- if (!tab) return;
177
- tab_sizes[tab.id] = tab_els[tab.id]?.getBoundingClientRect();
178
- });
179
- return tab_sizes;
180
- }
181
-
182
  $: tab_scale =
183
  tabs[$selected_tab_index >= 0 ? $selected_tab_index : 0]?.scale;
184
  </script>
@@ -277,9 +275,7 @@
277
  <style>
278
  .tabs {
279
  position: relative;
280
- display: flex;
281
  flex-direction: column;
282
- gap: var(--layout-gap);
283
  }
284
 
285
  .hide {
@@ -297,6 +293,7 @@
297
  position: relative;
298
  height: var(--size-8);
299
  padding-bottom: var(--size-2);
 
300
  }
301
 
302
  .tab-container {
 
70
 
71
  onMount(() => {
72
  if (!tab_nav_el) return;
73
+ const ro = new ResizeObserver(() => {
74
  handle_menu_overflow();
75
  });
76
+ ro.observe(tab_nav_el);
77
+ return () => ro.disconnect();
78
  });
79
 
80
  setContext(TABS, {
 
129
  }
130
  }
131
 
132
+ // approximate width of the "..." overflow button including margin
133
+ const OVERFLOW_BTN_RESERVE = 48;
134
+
135
  async function handle_menu_overflow(): Promise<void> {
136
  if (!tab_nav_el) return;
137
 
138
  await tick();
139
+ await new Promise((r) => requestAnimationFrame(r));
140
+
141
+ const available = tab_nav_el.clientWidth;
142
 
143
+ let cumulative = 0;
144
+ let split_index = tabs.length;
 
 
145
 
146
+ for (let i = 0; i < tabs.length; i++) {
147
  const tab = tabs[i];
148
+ if (!tab || tab.visible === false || tab.visible === "hidden") continue;
149
+ const el = tab_els[tab.id];
150
+ if (!el) continue;
151
+ cumulative += el.getBoundingClientRect().width;
152
+ const has_more = tabs
153
+ .slice(i + 1)
154
+ .some((t) => t && t.visible !== false && t.visible !== "hidden");
155
+ const limit = has_more ? available - OVERFLOW_BTN_RESERVE : available;
156
+ if (cumulative > limit) {
157
+ split_index = i;
158
  break;
159
  }
160
  }
161
 
162
+ visible_tabs = tabs.slice(0, split_index);
163
+ overflow_tabs = tabs.slice(split_index);
164
 
165
  overflow_has_selected_tab = handle_overflow_has_selected_tab($selected_tab);
166
+ is_overflowing =
167
+ overflow_tabs.filter((t) => t && t.visible !== false).length > 0;
168
  }
169
 
170
  $: overflow_has_selected_tab =
 
177
  return overflow_tabs.some((t) => t?.id === selected_tab);
178
  }
179
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  $: tab_scale =
181
  tabs[$selected_tab_index >= 0 ? $selected_tab_index : 0]?.scale;
182
  </script>
 
275
  <style>
276
  .tabs {
277
  position: relative;
 
278
  flex-direction: column;
 
279
  }
280
 
281
  .hide {
 
293
  position: relative;
294
  height: var(--size-8);
295
  padding-bottom: var(--size-2);
296
+ margin-bottom: var(--layout-gap);
297
  }
298
 
299
  .tab-container {