|
1 | 1 | import { escapeHtml } from './utils.js'; |
2 | 2 |
|
3 | | -export function getDefaultSpaceTitle(space) { |
4 | | - const count = space.tabs && space.tabs.length; |
5 | | - if (!count) return ''; |
6 | | - const firstTitle = space.tabs[0].title; |
7 | | - if (count === 1) { |
8 | | - return `[${escapeHtml(firstTitle)}]`; |
9 | | - } |
10 | | - return firstTitle.length > 30 |
11 | | - ? `[${escapeHtml(firstTitle.slice(0, 21))}…] +${count - 1} more` |
12 | | - : `[${escapeHtml(firstTitle)}] +${count - 1} more`; |
13 | | -} |
14 | | - |
15 | | -export function getTabDetailsString(space) { |
16 | | - const count = space.tabs && space.tabs.length; |
17 | | - const open = space.windowId; |
18 | | - |
19 | | - if (open) { |
20 | | - return ''; |
21 | | - } |
22 | | - return `(${count} tab${count !== 1 ? 's' : ''})`; |
23 | | -} |
| 3 | +/** @typedef {import('./common.js').Space} Space */ |
24 | 4 |
|
25 | 5 | // eslint-disable-next-line no-var |
26 | 6 | export const spacesRenderer = { |
@@ -248,3 +228,40 @@ export const spacesRenderer = { |
248 | 228 | } |
249 | 229 | }, |
250 | 230 | }; |
| 231 | + |
| 232 | +// Module-level helper functions. |
| 233 | + |
| 234 | +/** |
| 235 | + * Generates a default title for a space when it hasn't been named. |
| 236 | + * Based on the title of the first tab and the total number of tabs. |
| 237 | + * @param {Space} space - The space object |
| 238 | + * @returns {string} The generated title string |
| 239 | + */ |
| 240 | +export function getDefaultSpaceTitle(space) { |
| 241 | + const count = space.tabs && space.tabs.length; |
| 242 | + if (!count) return ''; |
| 243 | + const firstTitle = space.tabs[0].title; |
| 244 | + if (count === 1) { |
| 245 | + return `[${escapeHtml(firstTitle)}]`; |
| 246 | + } |
| 247 | + return firstTitle.length > 30 |
| 248 | + ? `[${escapeHtml(firstTitle.slice(0, 21))}…] +${count - 1} more` |
| 249 | + : `[${escapeHtml(firstTitle)}] +${count - 1} more`; |
| 250 | +} |
| 251 | + |
| 252 | +/** |
| 253 | + * Generates a string with the number of tabs in a space. |
| 254 | + * Returns an empty string if the space is currently open. |
| 255 | + * @param {Space} space - The space object |
| 256 | + * @returns {string} The generated string with the number of tabs |
| 257 | + */ |
| 258 | +export function getTabDetailsString(space) { |
| 259 | + const count = space.tabs && space.tabs.length; |
| 260 | + const open = space.windowId; |
| 261 | + |
| 262 | + if (open) { |
| 263 | + return ''; |
| 264 | + } |
| 265 | + return `(${count} tab${count !== 1 ? 's' : ''})`; |
| 266 | +} |
| 267 | + |
0 commit comments