Merge branch 'zhsama/panel-var-popup' into feat/pull-a-variable

This commit is contained in:
zhsama
2026-01-19 23:15:01 +08:00
5 changed files with 295 additions and 69 deletions

View File

@ -155,14 +155,13 @@ export type TriggerFn = (
text: string,
editor: LexicalEditor,
) => MenuTextMatch | null
export const PUNCTUATION = '\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%\'"~=<>_:;'
export function useBasicTypeaheadTriggerMatch(
trigger: string,
{ minLength = 1, maxLength = 75 }: { minLength?: number, maxLength?: number },
): TriggerFn {
return useCallback(
(text: string) => {
const validChars = `[${PUNCTUATION}\\s]`
const validChars = '[^\\n]'
const TypeaheadTriggerRegex = new RegExp(
'(.*)('
+ `[${trigger}]`

View File

@ -32,6 +32,8 @@ import { PickerBlockMenuOption } from './menu'
import { PromptMenuItem } from './prompt-option'
import { VariableMenuItem } from './variable-option'
const escapeRegExp = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
export const usePromptOptions = (
contextBlock?: ContextBlockType,
queryBlock?: QueryBlockType,
@ -154,7 +156,7 @@ export const useVariableOptions = (
if (!queryString)
return baseOptions
const regex = new RegExp(queryString, 'i')
const regex = new RegExp(escapeRegExp(queryString), 'i')
return baseOptions.filter(option => regex.test(option.key))
}, [editor, queryString, variableBlock])
@ -232,7 +234,7 @@ export const useExternalToolOptions = (
if (!queryString)
return baseToolOptions
const regex = new RegExp(queryString, 'i')
const regex = new RegExp(escapeRegExp(queryString), 'i')
return baseToolOptions.filter(option => regex.test(option.key))
}, [editor, queryString, externalToolBlockType])

View File

@ -91,9 +91,10 @@ const ComponentPicker = ({
],
})
const [editor] = useLexicalComposerContext()
const useExternalSearch = triggerString === '/' || triggerString === '@'
const checkForTriggerMatch = useBasicTypeaheadTriggerMatch(triggerString, {
minLength: 0,
maxLength: 0,
maxLength: useExternalSearch ? 75 : 0,
})
const [queryString, setQueryString] = useState<string | null>(null)
@ -116,6 +117,7 @@ const ComponentPicker = ({
currentBlock,
errorMessageBlock,
lastRunBlock,
useExternalSearch ? (queryString ?? undefined) : undefined,
)
const onSelectOption = useCallback(
@ -247,6 +249,9 @@ const ComponentPicker = ({
onBlur={handleClose}
maxHeightClass="max-h-[34vh]"
autoFocus={false}
hideSearch={useExternalSearch}
externalSearchText={useExternalSearch ? (queryString ?? '') : undefined}
enableKeyboardNavigation={useExternalSearch}
/>
)
: (
@ -270,6 +275,9 @@ const ComponentPicker = ({
onAssembleVariables={showAssembleVariables ? handleSelectAssembleVariables : undefined}
autoFocus={false}
isInCodeGeneratorInstructionEditor={currentBlock?.generatorType === GeneratorType.code}
hideSearch={useExternalSearch}
externalSearchText={useExternalSearch ? (queryString ?? '') : undefined}
enableKeyboardNavigation={useExternalSearch}
/>
</div>
)
@ -311,7 +319,7 @@ const ComponentPicker = ({
}
</>
)
}, [isAgentTrigger, agentNodes, allFlattenOptions.length, workflowVariableBlock?.show, floatingStyles, isPositioned, refs, handleSelectAgent, handleClose, workflowVariableOptions, isSupportFileVar, currentBlock?.generatorType, handleSelectWorkflowVariable, queryString, workflowVariableBlock?.showManageInputField, workflowVariableBlock?.onManageInputField, showAssembleVariables, handleSelectAssembleVariables])
}, [isAgentTrigger, agentNodes, allFlattenOptions.length, workflowVariableBlock?.show, floatingStyles, isPositioned, refs, handleSelectAgent, handleClose, workflowVariableOptions, isSupportFileVar, currentBlock?.generatorType, handleSelectWorkflowVariable, queryString, workflowVariableBlock?.showManageInputField, workflowVariableBlock?.onManageInputField, showAssembleVariables, handleSelectAssembleVariables, useExternalSearch])
return (
<LexicalTypeaheadMenuPlugin