mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 18:08:07 +08:00
fix: Enhance components with display names and ref forwarding; fix preview and edit slice style issue
This commit is contained in:
@ -49,4 +49,6 @@ const AutoHeightTextarea = forwardRef<HTMLTextAreaElement, AutoHeightTextareaPro
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
AutoHeightTextarea.displayName = 'AutoHeightTextarea'
|
||||||
|
|
||||||
export default AutoHeightTextarea
|
export default AutoHeightTextarea
|
||||||
|
|||||||
@ -11,7 +11,7 @@ type SwitchProps = {
|
|||||||
className?: string
|
className?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const Switch = ({ onChange, size = 'md', defaultValue = false, disabled = false, className }: SwitchProps) => {
|
const Switch = React.forwardRef<HTMLButtonElement>(({ onChange, size = 'md', defaultValue = false, disabled = false, className }: SwitchProps, ref) => {
|
||||||
const [enabled, setEnabled] = useState(defaultValue)
|
const [enabled, setEnabled] = useState(defaultValue)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setEnabled(defaultValue)
|
setEnabled(defaultValue)
|
||||||
@ -38,6 +38,7 @@ const Switch = ({ onChange, size = 'md', defaultValue = false, disabled = false,
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<OriginalSwitch
|
<OriginalSwitch
|
||||||
|
ref={ref}
|
||||||
checked={enabled}
|
checked={enabled}
|
||||||
onChange={(checked: boolean) => {
|
onChange={(checked: boolean) => {
|
||||||
if (disabled)
|
if (disabled)
|
||||||
@ -63,5 +64,8 @@ const Switch = ({ onChange, size = 'md', defaultValue = false, disabled = false,
|
|||||||
/>
|
/>
|
||||||
</OriginalSwitch>
|
</OriginalSwitch>
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
|
|
||||||
|
Switch.displayName = 'Switch'
|
||||||
|
|
||||||
export default React.memo(Switch)
|
export default React.memo(Switch)
|
||||||
|
|||||||
@ -29,9 +29,9 @@ export const ChunkContainer: FC<ChunkContainerProps> = (props) => {
|
|||||||
const { label, characterCount, children } = props
|
const { label, characterCount, children } = props
|
||||||
return <div className='space-y-2'>
|
return <div className='space-y-2'>
|
||||||
<ChunkLabel label={label} characterCount={characterCount} />
|
<ChunkLabel label={label} characterCount={characterCount} />
|
||||||
<p className='text-text-secondary text-sm tracking-[-0.0005em]'>
|
<div className='text-text-secondary text-sm tracking-[-0.0005em]'>
|
||||||
{children}
|
{children}
|
||||||
</p>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1086,6 +1086,7 @@ const StepTwo = ({
|
|||||||
label={`C-${indexForLabel}`}
|
label={`C-${indexForLabel}`}
|
||||||
text={child}
|
text={child}
|
||||||
tooltip={`Child-chunk-${indexForLabel} · ${child.length} Characters`}
|
tooltip={`Child-chunk-${indexForLabel} · ${child.length} Characters`}
|
||||||
|
labelInnerClassName='text-[10px] font-semibold align-bottom leading-7'
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
|
|||||||
@ -137,7 +137,7 @@ const ChildSegmentList: FC<IChildSegmentCardProps> = ({
|
|||||||
{((isFullDocMode && !isLoading) || !collapsed)
|
{((isFullDocMode && !isLoading) || !collapsed)
|
||||||
? <div className={classNames('flex items-center gap-x-0.5', isFullDocMode ? 'grow mb-6' : '')}>
|
? <div className={classNames('flex items-center gap-x-0.5', isFullDocMode ? 'grow mb-6' : '')}>
|
||||||
{isParagraphMode && (
|
{isParagraphMode && (
|
||||||
<div className='self-stretch my-0.5'>
|
<div className='self-stretch'>
|
||||||
<Divider type='vertical' className='w-[2px] mx-[7px] bg-text-accent-secondary' />
|
<Divider type='vertical' className='w-[2px] mx-[7px] bg-text-accent-secondary' />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -151,8 +151,9 @@ const ChildSegmentList: FC<IChildSegmentCardProps> = ({
|
|||||||
text={childChunk.content}
|
text={childChunk.content}
|
||||||
onDelete={() => onDelete?.(childChunk.segment_id, childChunk.id)}
|
onDelete={() => onDelete?.(childChunk.segment_id, childChunk.id)}
|
||||||
className='line-clamp-3'
|
className='line-clamp-3'
|
||||||
labelClassName='font-semibold'
|
labelInnerClassName='text-[10px] font-semibold align-bottom leading-6'
|
||||||
contentClassName={'!leading-6'}
|
contentClassName='!leading-6'
|
||||||
|
showDivider={false}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
onClickSlice?.(childChunk)
|
onClickSlice?.(childChunk)
|
||||||
|
|||||||
@ -133,7 +133,11 @@ const SegmentDetail: FC<ISegmentDetailProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={classNames('flex grow overflow-hidden', fullScreen ? 'w-full flex-row justify-center px-6 pt-6 gap-x-8 mx-auto' : 'flex-col gap-y-1 py-3 px-4')}>
|
<div className={classNames(
|
||||||
|
'flex grow overflow-hidden',
|
||||||
|
fullScreen ? 'w-full flex-row justify-center px-6 pt-6 gap-x-8 mx-auto' : 'flex-col gap-y-1 py-3 px-4',
|
||||||
|
!isEditMode && 'pb-0',
|
||||||
|
)}>
|
||||||
<div className={classNames('break-all overflow-y-auto whitespace-pre-line', fullScreen ? 'w-1/2' : 'grow')}>
|
<div className={classNames('break-all overflow-y-auto whitespace-pre-line', fullScreen ? 'w-1/2' : 'grow')}>
|
||||||
<ChunkContent
|
<ChunkContent
|
||||||
docForm={docForm}
|
docForm={docForm}
|
||||||
|
|||||||
@ -10,12 +10,22 @@ import ActionButton, { ActionButtonState } from '@/app/components/base/action-bu
|
|||||||
type EditSliceProps = SliceProps<{
|
type EditSliceProps = SliceProps<{
|
||||||
label: ReactNode
|
label: ReactNode
|
||||||
onDelete: () => void
|
onDelete: () => void
|
||||||
labelClassName?: string
|
labelInnerClassName?: string
|
||||||
contentClassName?: string
|
contentClassName?: string
|
||||||
|
showDivider?: boolean
|
||||||
}>
|
}>
|
||||||
|
|
||||||
export const EditSlice: FC<EditSliceProps> = (props) => {
|
export const EditSlice: FC<EditSliceProps> = (props) => {
|
||||||
const { label, className, text, onDelete, labelClassName, contentClassName, ...rest } = props
|
const {
|
||||||
|
label,
|
||||||
|
className,
|
||||||
|
text,
|
||||||
|
onDelete,
|
||||||
|
labelInnerClassName,
|
||||||
|
contentClassName,
|
||||||
|
showDivider = true,
|
||||||
|
...rest
|
||||||
|
} = props
|
||||||
const [delBtnShow, setDelBtnShow] = useState(false)
|
const [delBtnShow, setDelBtnShow] = useState(false)
|
||||||
const [isDelBtnHover, setDelBtnHover] = useState(false)
|
const [isDelBtnHover, setDelBtnHover] = useState(false)
|
||||||
|
|
||||||
@ -37,7 +47,7 @@ export const EditSlice: FC<EditSliceProps> = (props) => {
|
|||||||
const isDestructive = delBtnShow && isDelBtnHover
|
const isDestructive = delBtnShow && isDelBtnHover
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<span className='inline-block'>
|
||||||
<SliceContainer {...rest}
|
<SliceContainer {...rest}
|
||||||
className={className}
|
className={className}
|
||||||
ref={refs.setReference}
|
ref={refs.setReference}
|
||||||
@ -46,8 +56,8 @@ export const EditSlice: FC<EditSliceProps> = (props) => {
|
|||||||
<SliceLabel
|
<SliceLabel
|
||||||
className={classNames(
|
className={classNames(
|
||||||
isDestructive && '!bg-state-destructive-solid !text-text-primary-on-surface',
|
isDestructive && '!bg-state-destructive-solid !text-text-primary-on-surface',
|
||||||
labelClassName,
|
|
||||||
)}
|
)}
|
||||||
|
labelInnerClassName={labelInnerClassName}
|
||||||
>
|
>
|
||||||
{label}
|
{label}
|
||||||
</SliceLabel>
|
</SliceLabel>
|
||||||
@ -59,11 +69,11 @@ export const EditSlice: FC<EditSliceProps> = (props) => {
|
|||||||
>
|
>
|
||||||
{text}
|
{text}
|
||||||
</SliceContent>
|
</SliceContent>
|
||||||
<SliceDivider
|
{showDivider && <SliceDivider
|
||||||
className={classNames(
|
className={classNames(
|
||||||
isDestructive && '!bg-state-destructive-hover-alt',
|
isDestructive && '!bg-state-destructive-hover-alt',
|
||||||
)}
|
)}
|
||||||
/>
|
/>}
|
||||||
{delBtnShow && <FloatingFocusManager
|
{delBtnShow && <FloatingFocusManager
|
||||||
context={context}
|
context={context}
|
||||||
>
|
>
|
||||||
@ -88,6 +98,6 @@ export const EditSlice: FC<EditSliceProps> = (props) => {
|
|||||||
</div>
|
</div>
|
||||||
</FloatingFocusManager>}
|
</FloatingFocusManager>}
|
||||||
</SliceContainer>
|
</SliceContainer>
|
||||||
</div>
|
</span>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,10 +7,11 @@ import { SliceContainer, SliceContent, SliceDivider, SliceLabel } from './shared
|
|||||||
type PreviewSliceProps = SliceProps<{
|
type PreviewSliceProps = SliceProps<{
|
||||||
label: ReactNode
|
label: ReactNode
|
||||||
tooltip: ReactNode
|
tooltip: ReactNode
|
||||||
|
labelInnerClassName?: string
|
||||||
}>
|
}>
|
||||||
|
|
||||||
export const PreviewSlice: FC<PreviewSliceProps> = (props) => {
|
export const PreviewSlice: FC<PreviewSliceProps> = (props) => {
|
||||||
const { label, className, text, tooltip, ...rest } = props
|
const { label, className, text, tooltip, labelInnerClassName, ...rest } = props
|
||||||
const [tooltipOpen, setTooltipOpen] = useState(false)
|
const [tooltipOpen, setTooltipOpen] = useState(false)
|
||||||
const { refs, floatingStyles, context } = useFloating({
|
const { refs, floatingStyles, context } = useFloating({
|
||||||
open: tooltipOpen,
|
open: tooltipOpen,
|
||||||
@ -37,7 +38,7 @@ export const PreviewSlice: FC<PreviewSliceProps> = (props) => {
|
|||||||
ref={refs.setReference}
|
ref={refs.setReference}
|
||||||
{...getReferenceProps()}
|
{...getReferenceProps()}
|
||||||
>
|
>
|
||||||
<SliceLabel>{label}</SliceLabel>
|
<SliceLabel labelInnerClassName={labelInnerClassName}>{label}</SliceLabel>
|
||||||
<SliceContent>{text}</SliceContent>
|
<SliceContent>{text}</SliceContent>
|
||||||
<SliceDivider />
|
<SliceDivider />
|
||||||
</SliceContainer>
|
</SliceContainer>
|
||||||
|
|||||||
@ -14,16 +14,18 @@ export const SliceContainer: FC<SliceContainerProps> = forwardRef((props, ref) =
|
|||||||
})
|
})
|
||||||
SliceContainer.displayName = 'SliceContainer'
|
SliceContainer.displayName = 'SliceContainer'
|
||||||
|
|
||||||
export type SliceLabelProps = ComponentProps<'span'>
|
export type SliceLabelProps = ComponentProps<'span'> & { labelInnerClassName?: string }
|
||||||
|
|
||||||
export const SliceLabel: FC<SliceLabelProps> = forwardRef((props, ref) => {
|
export const SliceLabel: FC<SliceLabelProps> = forwardRef((props, ref) => {
|
||||||
const { className, children, ...rest } = props
|
const { className, children, labelInnerClassName, ...rest } = props
|
||||||
return <span {...rest} ref={ref} className={classNames(
|
return <span {...rest} ref={ref} className={classNames(
|
||||||
baseStyle,
|
baseStyle,
|
||||||
'px-1 bg-state-base-hover-alt group-hover:bg-state-accent-solid group-hover:text-text-primary-on-surface uppercase text-text-tertiary',
|
'px-1 bg-state-base-hover-alt group-hover:bg-state-accent-solid group-hover:text-text-primary-on-surface uppercase text-text-tertiary',
|
||||||
className,
|
className,
|
||||||
)}>
|
)}>
|
||||||
{children}
|
<span className={classNames('text-nowrap', labelInnerClassName)}>
|
||||||
|
{children}
|
||||||
|
</span>
|
||||||
</span>
|
</span>
|
||||||
})
|
})
|
||||||
SliceLabel.displayName = 'SliceLabel'
|
SliceLabel.displayName = 'SliceLabel'
|
||||||
@ -47,7 +49,8 @@ export type SliceDividerProps = ComponentProps<'span'>
|
|||||||
export const SliceDivider: FC<SliceDividerProps> = forwardRef((props, ref) => {
|
export const SliceDivider: FC<SliceDividerProps> = forwardRef((props, ref) => {
|
||||||
const { className, ...rest } = props
|
const { className, ...rest } = props
|
||||||
return <span {...rest} ref={ref} className={classNames(
|
return <span {...rest} ref={ref} className={classNames(
|
||||||
'py-[3px] bg-state-base-active group-hover:bg-state-accent-solid text-sm px-[1px]',
|
baseStyle,
|
||||||
|
'bg-state-base-active group-hover:bg-state-accent-solid text-sm px-[1px]',
|
||||||
className,
|
className,
|
||||||
)}>
|
)}>
|
||||||
{/* use a zero-width space to make the hover area bigger */}
|
{/* use a zero-width space to make the hover area bigger */}
|
||||||
|
|||||||
Reference in New Issue
Block a user