diff --git a/src/lib/components/id.svelte b/src/lib/components/id.svelte index 813cec9a2..f5d2414b7 100644 --- a/src/lib/components/id.svelte +++ b/src/lib/components/id.svelte @@ -1,11 +1,5 @@ - + +
import { Copy } from '.'; - import { isValueOfStringEnum } from '$lib/helpers/types'; - import { Flag } from '@appwrite.io/console'; import { sdk } from '$lib/stores/sdk'; - import { projectRegion } from '$routes/(console)/project-[region]-[project]/store'; + import { Flag } from '@appwrite.io/console'; + import { truncateText } from '$lib/components'; + import { isValueOfStringEnum } from '$lib/helpers/types'; import { getProjectEndpoint } from '$lib/helpers/project'; - - function truncateText(node: HTMLElement) { - const MAX_TRIES = 100; - let originalText = node.textContent; - - function checkOverflow() { - node.textContent = originalText; - - if (node.scrollWidth > node.clientWidth) { - let truncatedText = originalText; - let tries = 0; - while ( - node.scrollWidth > node.clientWidth && - truncatedText.length > 0 && - tries < MAX_TRIES - ) { - tries++; - if (truncatedText.includes('…')) { - const [left, right] = truncatedText.split('…'); - truncatedText = `${left.slice(0, -1)}…${right.slice(1)}`; - } else { - const left = truncatedText.slice(0, truncatedText.length / 2); - const right = truncatedText.slice(truncatedText.length / 2); - truncatedText = `${left.slice(0, -1)}…${right.slice(1)}`; - } - node.textContent = truncatedText; - } - } - } - - requestAnimationFrame(checkOverflow); - window.addEventListener('resize', checkOverflow); - - return { - update() { - originalText = node.textContent; - checkOverflow(); - }, - destroy() { - window.removeEventListener('resize', checkOverflow); - } - }; - } + import { projectRegion } from '$routes/(console)/project-[region]-[project]/store'; $: flagSrc = $projectRegion && isValueOfStringEnum(Flag, $projectRegion.flag)