Merge branch 'feat/parent-child-retrieval' of https://github.com/langgenius/dify into feat/parent-child-retrieval
commit
d1c3c26dc7
@ -0,0 +1,7 @@
|
|||||||
|
import type { FC, PropsWithChildren } from 'react'
|
||||||
|
|
||||||
|
export type FormattedTextProps = PropsWithChildren
|
||||||
|
|
||||||
|
export const FormattedText: FC<FormattedTextProps> = (props) => {
|
||||||
|
return <p className='leading-7'>{props.children}</p>
|
||||||
|
}
|
||||||
@ -0,0 +1,70 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import type { FC, ReactNode } from 'react'
|
||||||
|
import { autoUpdate, flip, inline, shift, useDismiss, useFloating, useHover, useInteractions, useRole } from '@floating-ui/react'
|
||||||
|
import type { SliceProps } from './type'
|
||||||
|
import classNames from '@/utils/classnames'
|
||||||
|
|
||||||
|
type NormalSliceProps = SliceProps<{
|
||||||
|
label: ReactNode
|
||||||
|
tooltip: ReactNode
|
||||||
|
}>
|
||||||
|
|
||||||
|
const baseStyle = 'py-[3px]'
|
||||||
|
|
||||||
|
export const NormalSlice: FC<NormalSliceProps> = (props) => {
|
||||||
|
const { label, className, text, tooltip, ...rest } = props
|
||||||
|
const [tooltipOpen, setTooltipOpen] = useState(false)
|
||||||
|
const { refs, floatingStyles, context } = useFloating({
|
||||||
|
open: tooltipOpen,
|
||||||
|
onOpenChange: setTooltipOpen,
|
||||||
|
whileElementsMounted: autoUpdate,
|
||||||
|
placement: 'top',
|
||||||
|
middleware: [
|
||||||
|
inline(),
|
||||||
|
flip(),
|
||||||
|
shift(),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
const hover = useHover(context, {
|
||||||
|
delay: { open: 500 },
|
||||||
|
move: true,
|
||||||
|
})
|
||||||
|
const dismiss = useDismiss(context)
|
||||||
|
const role = useRole(context, { role: 'tooltip' })
|
||||||
|
const { getReferenceProps, getFloatingProps } = useInteractions([hover, dismiss, role])
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<span {...rest} className={classNames(
|
||||||
|
'group align-bottom mr-1 select-none text-sm',
|
||||||
|
className,
|
||||||
|
)} ref={refs.setReference}
|
||||||
|
{...getReferenceProps()}
|
||||||
|
>
|
||||||
|
<span className={classNames(
|
||||||
|
baseStyle,
|
||||||
|
'px-1 bg-state-base-hover-alt text-text-tertiary group-hover:bg-state-accent-solid group-hover:text-white',
|
||||||
|
)}>
|
||||||
|
{label}
|
||||||
|
</span>
|
||||||
|
<span className={classNames(
|
||||||
|
baseStyle,
|
||||||
|
'px-1 text-text-secondary bg-state-base-hover group-hover:bg-state-accent-hover-alt group-hover:text-text-primary',
|
||||||
|
)}>
|
||||||
|
{text}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
className='py-[3px] bg-state-base-active group-hover:bg-state-accent-solid text-sm px-[1px]'
|
||||||
|
>
|
||||||
|
{/* use a zero-width space to make the hover area bigger */}
|
||||||
|
​
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
{tooltipOpen && <div ref={refs.setFloating} style={floatingStyles}
|
||||||
|
{...getFloatingProps()}
|
||||||
|
className='p-2 rounded-md bg-components-tooltip-bg shadow shadow-shadow-shadow-5 backdrop-blur-[5px] text-text-secondary leading-4 border-[0.5px] border-components-panel-border text-xs'
|
||||||
|
>
|
||||||
|
{tooltip}
|
||||||
|
</div>}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
import type { ComponentProps } from 'react'
|
||||||
|
|
||||||
|
export type SliceProps<T = {}> = T & {
|
||||||
|
text: string
|
||||||
|
} & ComponentProps<'span'>
|
||||||
@ -1,12 +1,16 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState } from 'react'
|
import { FormattedText } from '../components/datasets/formatted-text/flavours/formatted'
|
||||||
import { InputNumber } from '../components/base/input-number'
|
import { NormalSlice } from '../components/datasets/formatted-text/flavours/normal'
|
||||||
// import { Stepper } from '../components/datasets/create/stepper'
|
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
const [step, setStep] = useState(0)
|
|
||||||
return <div className='p-4'>
|
return <div className='p-4'>
|
||||||
<InputNumber onChange={setStep} unit={'tokens'} />
|
<FormattedText>
|
||||||
|
<NormalSlice label='C-1' text='lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' tooltip={'Child-chunk-2 · 268 Characters'} />
|
||||||
|
<NormalSlice label='C-1' text='lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' tooltip={'Child-chunk-2 · 268 Characters'} />
|
||||||
|
<NormalSlice label='C-1' text='lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' tooltip={'Child-chunk-2 · 268 Characters'} />
|
||||||
|
<NormalSlice label='C-1' text='lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' tooltip={'Child-chunk-2 · 268 Characters'} />
|
||||||
|
<NormalSlice label='C-1' text='lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' tooltip={'Child-chunk-2 · 268 Characters'} />
|
||||||
|
</FormattedText>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue