From ea7d82da3bc013c543a55d454c54da9a8b2523bf Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Sun, 24 Nov 2024 09:58:50 +0700 Subject: [PATCH] fix: limit tooltip size in inbox (#7228) Signed-off-by: Alexander Onnikov --- packages/ui/src/components/TooltipInstance.svelte | 11 +++++++++++ .../src/components/BasePreview.svelte | 11 ++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/ui/src/components/TooltipInstance.svelte b/packages/ui/src/components/TooltipInstance.svelte index 8d6b800d97..0461ae535e 100644 --- a/packages/ui/src/components/TooltipInstance.svelte +++ b/packages/ui/src/components/TooltipInstance.svelte @@ -45,6 +45,7 @@ right: string width: string height: string + maxWidth: string transform: string visibility: string classList: string @@ -57,6 +58,7 @@ right: '', width: '', height: '', + maxWidth: '', transform: '', visibility: 'hidden', classList: '' @@ -71,6 +73,7 @@ right: '', width: '', height: '', + maxWidth: '', transform: '', visibility: 'hidden', classList: '' @@ -86,6 +89,7 @@ width: '', height: '', transform: '', + maxWidth: '', visibility: 'visible', classList: '' } @@ -140,6 +144,9 @@ else dir = 'top' } else dir = $tooltip.direction + const left = rectAnchor.x + rectAnchor.width / 2 + const maxWidth = Math.min(left, docWidth - left) + if (dir === 'right') { options.top = rectAnchor.y + rectAnchor.height / 2 + 'px' options.left = `calc(${rectAnchor.right}px + .75rem)` @@ -151,10 +158,12 @@ } else if (dir === 'bottom') { options.top = `calc(${rectAnchor.bottom}px + .5rem)` options.left = rectAnchor.x + rectAnchor.width / 2 + 'px' + options.maxWidth = `calc(${maxWidth * 2}px - 1.5rem)` options.transform = 'translateX(-50%)' } else if (dir === 'top') { options.bottom = `calc(${docHeight - rectAnchor.y}px + .75rem)` options.left = rectAnchor.x + rectAnchor.width / 2 + 'px' + options.maxWidth = `calc(${maxWidth * 2}px - 1.5rem)` options.transform = 'translateX(-50%)' } } @@ -183,6 +192,7 @@ right: '', width: '', height: '', + maxWidth: '', visibility: 'visible', transform: '', classList: '' @@ -356,6 +366,7 @@ style:right={options.right} style:width={options.width} style:height={options.height} + style:max-width={options.maxWidth} style:transform={options.transform} style:z-index={($modals.findIndex((t) => t.type === 'tooltip') ?? 1) + 10000} > diff --git a/plugins/activity-resources/src/components/BasePreview.svelte b/plugins/activity-resources/src/components/BasePreview.svelte index fa0f9cf52f..e67a8b4520 100644 --- a/plugins/activity-resources/src/components/BasePreview.svelte +++ b/plugins/activity-resources/src/components/BasePreview.svelte @@ -39,6 +39,7 @@ const client = getClient() const limit = 300 + const tooltipLimit = 512 let isActionsOpened = false let person: WithLookup | undefined = undefined @@ -83,6 +84,14 @@ } else { tooltipLabel = core.string.System } + + function getTooltipText (markup: string): string { + const text = markupToText(markup) + if (text.length > tooltipLimit) { + return text.substring(0, tooltipLimit) + '...' + } + return text + } @@ -138,7 +147,7 @@ {#if intlLabel}