This commit is contained in:
2025-12-01 17:21:38 +08:00
parent 32fee2b8ab
commit fab8c13cb3
7511 changed files with 996300 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
import { RiCheckLine, RiCloseLine } from '@remixicon/react'
import { Mcp } from '@/app/components/base/icons/src/vender/other'
import AppIcon from '@/app/components/base/app-icon'
import cn from '@/utils/classnames'
import { shouldUseMcpIcon } from '@/utils/mcp'
const iconSizeMap = {
xs: 'w-4 h-4 text-base',
tiny: 'w-6 h-6 text-base',
small: 'w-8 h-8',
medium: 'w-9 h-9',
large: 'w-10 h-10',
}
const Icon = ({
className,
src,
installed = false,
installFailed = false,
size = 'large',
}: {
className?: string
src: string | {
content: string
background: string
}
installed?: boolean
installFailed?: boolean
size?: 'xs' | 'tiny' | 'small' | 'medium' | 'large'
}) => {
const iconClassName = 'flex justify-center items-center gap-2 absolute bottom-[-4px] right-[-4px] w-[18px] h-[18px] rounded-full border-2 border-components-panel-bg'
if (typeof src === 'object') {
return (
<div className={cn('relative', className)}>
<AppIcon
size={size}
iconType={'emoji'}
icon={src.content}
background={src.background}
className='rounded-md'
innerIcon={shouldUseMcpIcon(src) ? <Mcp className='h-8 w-8 text-text-primary-on-surface' /> : undefined}
/>
</div>
)
}
return (
<div
className={cn('relative shrink-0 rounded-md bg-contain bg-center bg-no-repeat', iconSizeMap[size], className)}
style={{
backgroundImage: `url(${src})`,
}}
>
{
installed
&& <div className={cn(iconClassName, 'bg-state-success-solid')}>
<RiCheckLine className='h-3 w-3 text-text-primary-on-surface' />
</div>
}
{
installFailed
&& <div className={cn(iconClassName, 'bg-state-destructive-solid')}>
<RiCloseLine className='h-3 w-3 text-text-primary-on-surface' />
</div>
}
</div>
)
}
export default Icon

View File

@@ -0,0 +1,12 @@
import { LeftCorner } from '../../../base/icons/src/vender/plugin'
const CornerMark = ({ text }: { text: string }) => {
return (
<div className='absolute right-0 top-0 flex pl-[13px] '>
<LeftCorner className="text-background-section" />
<div className="system-2xs-medium-uppercase h-5 rounded-tr-xl bg-background-section pr-2 leading-5 text-text-tertiary">{text}</div>
</div>
)
}
export default CornerMark

View File

@@ -0,0 +1,31 @@
import type { FC } from 'react'
import React, { useMemo } from 'react'
import cn from '@/utils/classnames'
type Props = {
className?: string
text: string
descriptionLineRows: number
}
const Description: FC<Props> = ({
className,
text,
descriptionLineRows,
}) => {
const lineClassName = useMemo(() => {
if (descriptionLineRows === 1)
return 'h-4 truncate'
else if (descriptionLineRows === 2)
return 'h-8 line-clamp-2'
else
return 'h-12 line-clamp-3'
}, [descriptionLineRows])
return (
<div className={cn('system-xs-regular text-text-tertiary', lineClassName, className)}>
{text}
</div>
)
}
export default Description

View File

@@ -0,0 +1,19 @@
import { RiInstallLine } from '@remixicon/react'
import { formatNumber } from '@/utils/format'
type Props = {
downloadCount: number
}
const DownloadCount = ({
downloadCount,
}: Props) => {
return (
<div className="flex items-center space-x-1 text-text-tertiary">
<RiInstallLine className="h-3 w-3 shrink-0" />
<div className="system-xs-regular">{formatNumber(downloadCount)}</div>
</div>
)
}
export default DownloadCount

View File

@@ -0,0 +1,30 @@
import cn from '@/utils/classnames'
type Props = {
className?: string
orgName?: string
packageName: string
packageNameClassName?: string
}
const OrgInfo = ({
className,
orgName,
packageName,
packageNameClassName,
}: Props) => {
return (
<div className={cn('flex h-4 items-center space-x-0.5', className)}>
{orgName && (
<>
<span className='system-xs-regular shrink-0 text-text-tertiary'>{orgName}</span>
<span className='system-xs-regular shrink-0 text-text-quaternary'>/</span>
</>
)}
<span className={cn('system-xs-regular w-0 shrink-0 grow truncate text-text-tertiary', packageNameClassName)}>
{packageName}
</span>
</div>
)
}
export default OrgInfo

View File

@@ -0,0 +1,51 @@
import { Group } from '../../../base/icons/src/vender/other'
import Title from './title'
import { SkeletonContainer, SkeletonPoint, SkeletonRectangle, SkeletonRow } from '@/app/components/base/skeleton'
import cn from '@/utils/classnames'
type Props = {
wrapClassName: string
loadingFileName?: string
}
export const LoadingPlaceholder = ({ className }: { className?: string }) => (
<div className={cn('h-2 rounded-sm bg-text-quaternary opacity-20', className)} />
)
const Placeholder = ({
wrapClassName,
loadingFileName,
}: Props) => {
return (
<div className={wrapClassName}>
<SkeletonRow>
<div
className='flex h-10 w-10 items-center justify-center gap-2 rounded-[10px] border-[0.5px]
border-components-panel-border bg-background-default p-1 backdrop-blur-sm'>
<div className='flex h-5 w-5 items-center justify-center'>
<Group className='text-text-tertiary' />
</div>
</div>
<div className="grow">
<SkeletonContainer>
<div className="flex h-5 items-center">
{loadingFileName ? (
<Title title={loadingFileName} />
) : (
<SkeletonRectangle className="w-[260px]" />
)}
</div>
<SkeletonRow className="h-4">
<SkeletonRectangle className="w-[41px]" />
<SkeletonPoint />
<SkeletonRectangle className="w-[180px]" />
</SkeletonRow>
</SkeletonContainer>
</div>
</SkeletonRow>
<SkeletonRectangle className="mt-3 w-[420px]" />
</div>
)
}
export default Placeholder

View File

@@ -0,0 +1,13 @@
const Title = ({
title,
}: {
title: string
}) => {
return (
<div className='system-md-semibold truncate text-text-secondary'>
{title}
</div>
)
}
export default Title

View File

@@ -0,0 +1,36 @@
import DownloadCount from './base/download-count'
type Props = {
downloadCount?: number
tags: string[]
}
const CardMoreInfo = ({
downloadCount,
tags,
}: Props) => {
return (
<div className="flex h-5 items-center">
{downloadCount !== undefined && <DownloadCount downloadCount={downloadCount} />}
{downloadCount !== undefined && tags && tags.length > 0 && <div className="system-xs-regular mx-2 text-text-quaternary">·</div>}
{tags && tags.length > 0 && (
<>
<div className="flex h-4 flex-wrap space-x-2 overflow-hidden">
{tags.map(tag => (
<div
key={tag}
className="system-xs-regular flex max-w-[120px] space-x-1 overflow-hidden"
title={`# ${tag}`}
>
<span className="text-text-quaternary">#</span>
<span className="truncate text-text-tertiary">{tag}</span>
</div>
))}
</div>
</>
)}
</div>
)
}
export default CardMoreInfo

View File

@@ -0,0 +1,107 @@
'use client'
import { useMixedTranslation } from '@/app/components/plugins/marketplace/hooks'
import { useGetLanguage } from '@/context/i18n'
import { renderI18nObject } from '@/i18n-config'
import { getLanguage } from '@/i18n-config/language'
import cn from '@/utils/classnames'
import { RiAlertFill } from '@remixicon/react'
import React from 'react'
import Partner from '../base/badges/partner'
import Verified from '../base/badges/verified'
import Icon from '../card/base/card-icon'
import { useCategories } from '../hooks'
import type { Plugin } from '../types'
import CornerMark from './base/corner-mark'
import Description from './base/description'
import OrgInfo from './base/org-info'
import Placeholder from './base/placeholder'
import Title from './base/title'
export type Props = {
className?: string
payload: Plugin
titleLeft?: React.ReactNode
installed?: boolean
installFailed?: boolean
hideCornerMark?: boolean
descriptionLineRows?: number
footer?: React.ReactNode
isLoading?: boolean
loadingFileName?: string
locale?: string
limitedInstall?: boolean
}
const Card = ({
className,
payload,
titleLeft,
installed,
installFailed,
hideCornerMark,
descriptionLineRows = 2,
footer,
isLoading = false,
loadingFileName,
locale: localeFromProps,
limitedInstall = false,
}: Props) => {
const defaultLocale = useGetLanguage()
const locale = localeFromProps ? getLanguage(localeFromProps) : defaultLocale
const { t } = useMixedTranslation(localeFromProps)
const { categoriesMap } = useCategories(t, true)
const { category, type, name, org, label, brief, icon, verified, badges = [] } = payload
const getLocalizedText = (obj: Record<string, string> | undefined) =>
obj ? renderI18nObject(obj, locale) : ''
const isPartner = badges.includes('partner')
const wrapClassName = cn('hover-bg-components-panel-on-panel-item-bg relative overflow-hidden rounded-xl border-[0.5px] border-components-panel-border bg-components-panel-on-panel-item-bg shadow-xs', className)
if (isLoading) {
return (
<Placeholder
wrapClassName={wrapClassName}
loadingFileName={loadingFileName!}
/>
)
}
return (
<div className={wrapClassName}>
<div className={cn('p-4 pb-3', limitedInstall && 'pb-1')}>
{!hideCornerMark && <CornerMark text={categoriesMap[type === 'bundle' ? type : category]?.label} />}
{/* Header */}
<div className="flex">
<Icon src={icon} installed={installed} installFailed={installFailed} />
<div className="ml-3 w-0 grow">
<div className="flex h-5 items-center">
<Title title={getLocalizedText(label)} />
{isPartner && <Partner className='ml-0.5 h-4 w-4' text={t('plugin.marketplace.partnerTip')} />}
{verified && <Verified className='ml-0.5 h-4 w-4' text={t('plugin.marketplace.verifiedTip')} />}
{titleLeft} {/* This can be version badge */}
</div>
<OrgInfo
className="mt-0.5"
orgName={org}
packageName={name}
/>
</div>
</div>
<Description
className="mt-3"
text={getLocalizedText(brief)}
descriptionLineRows={descriptionLineRows}
/>
{footer && <div>{footer}</div>}
</div>
{limitedInstall
&& <div className='relative flex h-8 items-center gap-x-2 px-3 after:absolute after:bottom-0 after:left-0 after:right-0 after:top-0 after:bg-toast-warning-bg after:opacity-40'>
<RiAlertFill className='h-3 w-3 shrink-0 text-text-warning-secondary' />
<p className='system-xs-regular z-10 grow text-text-secondary'>
{t('plugin.installModal.installWarning')}
</p>
</div>}
</div>
)
}
export default React.memo(Card)