LCOV - code coverage report
Current view: top level - src/platform/updates/components - WhatsNewPopup.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 41.5 % 41 17
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : <template>
       2         2104 :   <div v-if="shouldShow" class="whats-new-popup-container left-4">
       3              :     <div
       4              :       class="whats-new-popup relative flex w-100 max-w-100 flex-col rounded-lg border bg-popover shadow-md"
       5              :       @click.stop
       6              :     >
       7              :       <Button
       8              :         class="absolute top-2 right-2 z-10 p-2 opacity-50"
       9              :         :aria-label="$t('g.close')"
      10              :         size="icon"
      11              :         variant="muted-textonly"
      12              :         @click="closePopup"
      13              :       >
      14              :         <i class="icon-[lucide--x]" />
      15              :       </Button>
      16              : 
      17              :       <div class="flex flex-1 flex-col gap-4">
      18              :         <SanitizedHtml
      19              :           class="content-text max-h-96 overflow-y-auto"
      20              :           :html="formattedContent"
      21              :         />
      22              :       </div>
      23              : 
      24              :       <div class="flex items-center justify-between gap-4 px-4 pb-4">
      25              :         <a
      26              :           class="flex items-center gap-2 py-1 text-sm text-muted-foreground no-underline hover:text-foreground"
      27              :           :href="changelogUrl"
      28              :           target="_blank"
      29              :           rel="noopener noreferrer"
      30              :           @click="closePopup"
      31              :         >
      32              :           <i class="icon-[lucide--external-link]" />
      33              :           {{ $t('whatsNewPopup.learnMore') }}
      34              :         </a>
      35              :         <div class="flex items-center gap-4">
      36              :           <Button
      37              :             class="h-8"
      38              :             size="sm"
      39              :             variant="muted-textonly"
      40              :             @click="closePopup"
      41              :           >
      42              :             {{ $t('whatsNewPopup.later') }}
      43              :           </Button>
      44              :         </div>
      45              :       </div>
      46              :     </div>
      47              :   </div>
      48              : </template>
      49              : 
      50              : <script setup lang="ts">
      51              : import { default as DOMPurify } from 'dompurify'
      52              : import { computed, onMounted, ref } from 'vue'
      53              : import { useI18n } from 'vue-i18n'
      54              : 
      55              : import SanitizedHtml from '@comfyorg/design-system/common/SanitizedHtml'
      56              : import Button from '@comfyorg/design-system/button/Button'
      57              : import { useExternalLink } from '@/composables/useExternalLink'
      58              : import { formatVersionAnchor } from '@/utils/formatUtil'
      59              : import { renderMarkdownToHtml } from '@/utils/markdownRendererUtil'
      60              : 
      61              : import type { ReleaseNote } from '@/platform/updates/common/releaseService'
      62              : import { useReleaseStore } from '@/platform/updates/common/releaseStore'
      63              : 
      64         2093 : const { buildDocsUrl } = useExternalLink()
      65         2093 : const releaseStore = useReleaseStore()
      66         2093 : const { t } = useI18n()
      67              : 
      68              : // Define emits
      69         2093 : const emit = defineEmits<{
      70              :   'whats-new-dismissed': []
      71              : }>()
      72              : 
      73              : // Local state for dismissed status
      74         2093 : const isDismissed = ref(false)
      75              : 
      76              : // Get latest release from store
      77         2093 : const latestRelease = computed<ReleaseNote | null>(() => {
      78            0 :   return releaseStore.recentRelease
      79              : })
      80              : 
      81              : // Show popup when on latest version and not dismissed
      82         2093 : const shouldShow = computed(
      83              :   () => releaseStore.shouldShowPopup && !isDismissed.value
      84              : )
      85              : 
      86              : // Generate changelog URL with version anchor (language-aware)
      87         2093 : const changelogUrl = computed(() => {
      88            0 :   const changelogBaseUrl = buildDocsUrl('/changelog', { includeLocale: true })
      89            0 :   if (latestRelease.value?.version) {
      90              :     const versionAnchor = formatVersionAnchor(latestRelease.value.version)
      91            0 :     return `${changelogBaseUrl}#${versionAnchor}`
      92              :   }
      93            0 :   return changelogBaseUrl
      94              : })
      95              : 
      96         2093 : const formattedContent = computed(() => {
      97            0 :   if (!latestRelease.value?.content) {
      98            0 :     return DOMPurify.sanitize(`<p>${t('whatsNewPopup.noReleaseNotes')}</p>`)
      99              :   }
     100              : 
     101            0 :   try {
     102            0 :     const markdown = latestRelease.value.content
     103              : 
     104              :     // Check if content is meaningful (not just whitespace)
     105            0 :     const trimmedContent = markdown.trim()
     106            0 :     if (!trimmedContent || trimmedContent.replace(/\s+/g, '') === '') {
     107            0 :       return DOMPurify.sanitize(`<p>${t('whatsNewPopup.noReleaseNotes')}</p>`)
     108              :     }
     109              : 
     110              :     // Extract image and remaining content separately
     111            0 :     const imageMatch = markdown.match(/!\[.*?\]\(.*?\)/)
     112              :     const image = imageMatch ? imageMatch[0] : ''
     113              : 
     114              :     // Remove image from content but keep original title
     115              :     const contentWithoutImage = markdown.replace(/!\[.*?\]\(.*?\)/, '').trim()
     116              : 
     117              :     // Reorder: image first, then original content
     118            0 :     const reorderedContent = [image, contentWithoutImage]
     119              :       .filter(Boolean)
     120              :       .join('\n\n')
     121              : 
     122              :     // renderMarkdownToHtml already sanitizes with DOMPurify, so this is safe
     123            0 :     return renderMarkdownToHtml(reorderedContent)
     124              :   } catch (error) {
     125            0 :     console.error('Error parsing markdown:', error)
     126              :     // Fallback to plain text with line breaks - sanitize the HTML we create
     127            0 :     const fallbackContent = latestRelease.value.content.replace(/\n/g, '<br>')
     128            0 :     return fallbackContent.trim()
     129              :       ? DOMPurify.sanitize(fallbackContent)
     130              :       : DOMPurify.sanitize(`<p>${t('whatsNewPopup.noReleaseNotes')}</p>`)
     131              :   }
     132              : })
     133              : 
     134         2093 : const show = () => {
     135            0 :   isDismissed.value = false
     136              : }
     137              : 
     138         2093 : const hide = () => {
     139            0 :   isDismissed.value = true
     140            0 :   emit('whats-new-dismissed')
     141              : }
     142              : 
     143         2093 : const closePopup = async () => {
     144              :   // Mark "what's new" seen when popup is closed
     145            0 :   if (latestRelease.value) {
     146            0 :     await releaseStore.handleWhatsNewSeen(latestRelease.value.version)
     147              :   }
     148            0 :   hide()
     149              : }
     150              : 
     151              : // Initialize on mount
     152         2093 : onMounted(async () => {
     153              :   // Fetch releases if not already loaded
     154         2093 :   if (!releaseStore.releases.length) {
     155         2093 :     await releaseStore.fetchReleases()
     156              :   }
     157              : })
     158              : 
     159              : // Expose methods for parent component and tests
     160         2093 : defineExpose({
     161              :   show,
     162              :   hide,
     163              :   closePopup
     164              : })
     165              : </script>
     166              : 
     167              : <style scoped>
     168              : /* Popup container - positioning handled by parent */
     169              : .whats-new-popup-container {
     170              :   --whats-new-popup-bottom: 1rem;
     171              : 
     172              :   position: absolute;
     173              :   bottom: var(--whats-new-popup-bottom);
     174              :   pointer-events: auto;
     175              : }
     176              : 
     177              : .content-text {
     178              :   color: var(--foreground);
     179              :   font-size: 14px;
     180              :   line-height: 1.5;
     181              :   word-wrap: break-word;
     182              :   padding: 0 1rem;
     183              : }
     184              : 
     185              : .content-text :deep(h1) {
     186              :   color: var(--muted-foreground);
     187              :   font-size: 14px;
     188              :   font-weight: 400;
     189              :   margin-top: 1rem;
     190              :   margin-bottom: 8px;
     191              :   text-transform: uppercase;
     192              :   letter-spacing: 0.05em;
     193              : }
     194              : 
     195              : /* What's new title - targets h2 or strong text after h1 */
     196              : .content-text :deep(h2),
     197              : /* stylelint-disable-next-line selector-max-type -- generated markdown offers no class hooks */
     198              : .content-text :deep(h1 + p strong) {
     199              :   color: var(--foreground);
     200              :   font-size: 14px;
     201              :   font-weight: 600;
     202              :   margin: 0 0 8px;
     203              :   line-height: 1.429;
     204              : }
     205              : 
     206              : /* Regular paragraphs - short description */
     207              : .content-text :deep(p) {
     208              :   color: var(--muted-foreground);
     209              :   margin: 1rem 0;
     210              : }
     211              : 
     212              : /* List */
     213              : .content-text :deep(ul),
     214              : .content-text :deep(ol) {
     215              :   margin-bottom: 0;
     216              :   padding-left: 0;
     217              :   list-style: none;
     218              : }
     219              : 
     220              : .content-text :deep(ul:first-child),
     221              : .content-text :deep(ol:first-child) {
     222              :   margin-top: 0;
     223              : }
     224              : 
     225              : .content-text :deep(ul:last-child),
     226              : .content-text :deep(ol:last-child) {
     227              :   margin-bottom: 0;
     228              : }
     229              : 
     230              : .content-text :deep(li) {
     231              :   margin-bottom: 6px;
     232              :   position: relative;
     233              :   padding-left: 18px;
     234              :   color: var(--muted-foreground);
     235              :   font-size: 14px;
     236              :   font-weight: 400;
     237              :   line-height: 1.2102;
     238              : }
     239              : 
     240              : .content-text :deep(li:last-child) {
     241              :   margin-bottom: 0;
     242              : }
     243              : 
     244              : .content-text :deep(li::before) {
     245              :   content: '';
     246              :   position: absolute;
     247              :   left: 4px;
     248              :   top: 7px;
     249              :   width: 6px;
     250              :   height: 6px;
     251              :   border: 2px solid var(--muted-foreground);
     252              :   border-radius: 50%;
     253              :   background: transparent;
     254              : }
     255              : 
     256              : .content-text :deep(li strong) {
     257              :   color: var(--muted-foreground);
     258              :   font-size: 14px;
     259              :   font-weight: 400;
     260              :   line-height: 1.2102;
     261              :   margin-right: 4px;
     262              : }
     263              : 
     264              : .content-text :deep(li p) {
     265              :   margin: 2px 0 0;
     266              :   display: inline;
     267              : }
     268              : 
     269              : /* Code styling */
     270              : .content-text :deep(code) {
     271              :   background-color: var(--input);
     272              :   border: 1px solid var(--border);
     273              :   border-radius: 4px;
     274              :   padding: 2px 6px;
     275              :   color: var(--foreground);
     276              :   white-space: nowrap;
     277              : }
     278              : 
     279              : .content-text :deep(img) {
     280              :   width: 100%;
     281              :   height: 200px;
     282              :   margin: 0 0 16px;
     283              :   object-fit: cover;
     284              :   display: block;
     285              :   border-radius: 8px;
     286              : }
     287              : 
     288              : .content-text :deep(img:first-child) {
     289              :   margin: -1rem -1rem 16px;
     290              :   width: calc(100% + 2rem);
     291              :   border-top-left-radius: 8px;
     292              :   border-top-right-radius: 8px;
     293              :   border-bottom-left-radius: 0;
     294              :   border-bottom-right-radius: 0;
     295              : }
     296              : 
     297              : /* Add border to content when image is present */
     298              : .content-text:has(img:first-child) {
     299              :   border-left: 1px solid var(--border);
     300              :   border-right: 1px solid var(--border);
     301              :   border-top: 1px solid var(--border);
     302              :   border-bottom-left-radius: 8px;
     303              :   border-bottom-right-radius: 8px;
     304              :   margin: -1px;
     305              :   margin-bottom: 0;
     306              : }
     307              : 
     308              : .content-text :deep(img + h1) {
     309              :   margin-top: 0;
     310              : }
     311              : 
     312              : /* Secondary headings */
     313              : .content-text :deep(h3) {
     314              :   color: var(--foreground);
     315              :   font-size: 16px;
     316              :   font-weight: 600;
     317              :   margin: 16px 0 8px;
     318              :   line-height: 1.4;
     319              : }
     320              : </style>
        

Generated by: LCOV version 2.0-1