mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-08-01 12:20:35 +08:00
custom selection tools (#710, #14, #322, #312, #193, #209, #134, #77, #13, #4, #719, #714, #399, #366, #357, #332, #216, #167, #395, #261, #673, #541, #523)
This commit is contained in:
@@ -113,27 +113,41 @@ function FloatingToolbar(props) {
|
||||
</div>
|
||||
)
|
||||
} else {
|
||||
if (config.activeSelectionTools.length === 0) return <div />
|
||||
if (
|
||||
config.activeSelectionTools.length === 0 &&
|
||||
config.customSelectionTools.reduce((count, tool) => count + (tool.active ? 1 : 0), 0) === 0
|
||||
)
|
||||
return <div />
|
||||
|
||||
const tools = []
|
||||
const pushTool = (iconKey, name, genPrompt) => {
|
||||
tools.push(
|
||||
cloneElement(toolsConfig[iconKey].icon, {
|
||||
size: 24,
|
||||
className: 'chatgptbox-selection-toolbar-button',
|
||||
title: name,
|
||||
onClick: async () => {
|
||||
const p = getClientPosition(props.container)
|
||||
props.container.style.position = 'fixed'
|
||||
setPosition(p)
|
||||
setPrompt(await genPrompt(selection))
|
||||
setTriggered(true)
|
||||
},
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
for (const key in toolsConfig) {
|
||||
if (config.activeSelectionTools.includes(key)) {
|
||||
const toolConfig = toolsConfig[key]
|
||||
tools.push(
|
||||
cloneElement(toolConfig.icon, {
|
||||
size: 24,
|
||||
className: 'chatgptbox-selection-toolbar-button',
|
||||
title: t(toolConfig.label),
|
||||
onClick: async () => {
|
||||
const p = getClientPosition(props.container)
|
||||
props.container.style.position = 'fixed'
|
||||
setPosition(p)
|
||||
setPrompt(await toolConfig.genPrompt(selection))
|
||||
setTriggered(true)
|
||||
},
|
||||
}),
|
||||
)
|
||||
pushTool(key, t(toolConfig.label), toolConfig.genPrompt)
|
||||
}
|
||||
}
|
||||
for (const tool of config.customSelectionTools) {
|
||||
if (tool.active) {
|
||||
pushTool(tool.iconKey, tool.name, async (selection) => {
|
||||
return tool.prompt.replace('{{selection}}', selection)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user