瀏覽代碼

Optimize the event handling and rendering logic of the component picker (#19232)

tags/1.4.0
allenZhang 5 月之前
父節點
當前提交
5a6f20d575
沒有連結到貢獻者的電子郵件帳戶。
共有 1 個檔案被更改,包括 8 行新增7 行删除
  1. 8
    7
      web/app/components/base/prompt-editor/plugins/component-picker-block/index.tsx

+ 8
- 7
web/app/components/base/prompt-editor/plugins/component-picker-block/index.tsx 查看文件

@@ -120,10 +120,8 @@ const ComponentPicker = ({
}, [editor, checkForTriggerMatch, triggerString])

const handleClose = useCallback(() => {
ReactDOM.flushSync(() => {
const escapeEvent = new KeyboardEvent('keydown', { key: 'Escape' })
editor.dispatchCommand(KEY_ESCAPE_COMMAND, escapeEvent)
})
const escapeEvent = new KeyboardEvent('keydown', { key: 'Escape' })
editor.dispatchCommand(KEY_ESCAPE_COMMAND, escapeEvent)
}, [editor])

const renderMenu = useCallback<MenuRenderFn<PickerBlockMenuOption>>((
@@ -132,7 +130,11 @@ const ComponentPicker = ({
) => {
if (!(anchorElementRef.current && (allFlattenOptions.length || workflowVariableBlock?.show)))
return null
refs.setReference(anchorElementRef.current)

setTimeout(() => {
if (anchorElementRef.current)
refs.setReference(anchorElementRef.current)
}, 0)

return (
<>
@@ -149,7 +151,6 @@ const ComponentPicker = ({
visibility: isPositioned ? 'visible' : 'hidden',
}}
ref={refs.setFloating}
data-testid="component-picker-container"
>
{
workflowVariableBlock?.show && (
@@ -173,7 +174,7 @@ const ComponentPicker = ({
<div className='my-1 h-px w-full -translate-x-1 bg-divider-subtle'></div>
)
}
<div data-testid="options-list">
<div>
{
options.map((option, index) => (
<Fragment key={option.key}>

Loading…
取消
儲存