/* * Copyright 2025 coze-dev Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { useLayoutEffect, type PropsWithChildren } from 'react'; import { useLocalStorageState } from 'ahooks'; import { useEditor, useInjector } from '@coze-editor/editor/react'; import { type EditorAPI } from '@coze-editor/editor/preset-prompt'; import { insertInputSlot } from '@coze-common/editor-plugins/actions'; import { I18n } from '@coze-arch/i18n'; import { IconCozInputSlot } from '@coze-arch/coze-design/icons'; import { Button, Tooltip } from '@coze-arch/coze-design'; import { type ButtonProps } from '@coze-arch/coze-design'; import { keymap } from '@codemirror/view'; import { useReadonly } from '../../shared/hooks/use-editor-readonly'; import InsertBlankSlotGuideEn from '../../assets/insert-blank-slot-guide-en.png'; import InsertBlankSlotGuideCn from '../../assets/insert-blank-slot-guide-cn.png'; import BlankSlotShortCutIcon from '../../assets/blank-slot-shortcut-icon.png'; type NlPromptActionProps = Pick & { disabled?: boolean; }; export const InsertInputSlotButton: React.FC = props => { const { className, disabled } = props; const editor = useEditor(); const readonly = useReadonly(); const injector = useInjector(); const [showActionGuide, setShowActionGuide] = useLocalStorageState( insertInputSlotTooltipGuideKey, { defaultValue: true, }, ); useLayoutEffect( () => injector.inject([ keymap.of([ { key: 'Cmd-k', run() { if (!editor || readonly || disabled) { return false; } insertInputSlot(editor); return false; }, }, ]), ]), [injector, editor, readonly, disabled], ); return (
); }; const insertInputSlotTooltipGuideKey = 'insert_input_slot_tooltip_guide'; const GuideTooltip: React.FC< PropsWithChildren<{ showActionGuide: boolean; }> > = ({ showActionGuide, children }) => { if (showActionGuide) { return (
{I18n.t('edit_block_guild_title')}
{I18n.t('edit_block_guild_describe')}
} className="!w-[301px] !max-w-[301px]" > {children}
); } return ( ⌘ K } className="coz-fg-primary text-sm" > {children} ); };