diff --git a/classes/class-rest.php b/classes/class-rest.php index 2fa77ad..4f9354f 100644 --- a/classes/class-rest.php +++ b/classes/class-rest.php @@ -202,6 +202,7 @@ class Mind_Rest extends WP_REST_Controller { [ 'Rules:', $context ? '- The context for the user request placed under "Context".' : '', + $context ? '- Context usually contains the current blocks JSON, use it to improve by the user request. Try to keep essential information, links and images.' : '', '- Respond to the user request placed under "Request".', '- See the "Response Format Rules" section for block output rules.', '- Avoid offensive or sensitive content.', diff --git a/src/editor/extensions/block-toolbar/index.js b/src/editor/extensions/block-toolbar/index.js index 8150bf3..2aacafc 100644 --- a/src/editor/extensions/block-toolbar/index.js +++ b/src/editor/extensions/block-toolbar/index.js @@ -27,6 +27,7 @@ import { ReactComponent as AIImproveIcon } from '../../../icons/ai-improve.svg'; import { ReactComponent as AIFixSpellingIcon } from '../../../icons/ai-fix-spelling.svg'; import { ReactComponent as AIShorterIcon } from '../../../icons/ai-shorter.svg'; import { ReactComponent as AILongerIcon } from '../../../icons/ai-longer.svg'; +import { ReactComponent as AIMessage } from '../../../icons/ai-message.svg'; import { ReactComponent as AISummarizeIcon } from '../../../icons/ai-summarize.svg'; import { ReactComponent as AIToneIcon } from '../../../icons/ai-tone.svg'; import { ReactComponent as AIParaphraseIcon } from '../../../icons/ai-paraphrase.svg'; @@ -34,8 +35,6 @@ import { ReactComponent as AITranslateIcon } from '../../../icons/ai-translate.s import { ReactComponent as MindLogoIcon } from '../../../icons/mind-logo.svg'; import wrapEmoji from '../../../utils/wrap-emoji'; -const ALLOWED_BLOCKS = ['core/paragraph', 'core/heading']; - const TONE = [ [__('professional', 'mind'), __('🧐 Professional', 'mind')], [__('friendly', 'mind'), __('😀 Friendly', 'mind')], @@ -63,16 +62,6 @@ const LANGUAGE = [ [__('vietnamese', 'mind'), __('🇻🇳 Vietnamese', 'mind')], ]; -/** - * Check if Mind allowed in block toolbar. - * - * @param {Object} data - block data. - * @return {boolean} allowed. - */ -function isToolbarAllowed(data) { - return ALLOWED_BLOCKS.includes(data.name); -} - function Toolbar() { const { open, setInput, setContext, setInsertionPlace, requestAI } = useDispatch('mind/popup'); @@ -82,7 +71,10 @@ function Toolbar() { setInput(prompt); setContext('selected-blocks'); setInsertionPlace('selected-blocks'); - requestAI(); + + if (prompt) { + requestAI(); + } } return ( @@ -97,6 +89,15 @@ function Toolbar() { return ( <> + } + iconPosition="left" + onClick={() => { + openModal(); + }} + > + {__('Ask AI', 'mind')} + } iconPosition="left" @@ -290,12 +291,6 @@ function Toolbar() { */ const withToolbarControl = createHigherOrderComponent((OriginalComponent) => { function MindToolbarToggle(props) { - const allow = isToolbarAllowed(props); - - if (!allow) { - return ; - } - return ( <> diff --git a/src/editor/extensions/editor-styles/index.js b/src/editor/extensions/editor-styles/index.js index 0e91500..a5f1cfe 100644 --- a/src/editor/extensions/editor-styles/index.js +++ b/src/editor/extensions/editor-styles/index.js @@ -11,15 +11,6 @@ import { useDispatch, useSelect } from '@wordpress/data'; */ import EditorStyles from '../../components/editor-styles'; -const HIGHLIGHT_BLOCKS = [ - 'core/paragraph', - 'core/list', - 'core/code', - 'core/preformatted', - 'core/quote', - 'core/blockquote', -]; - /** * Add new blocks highlight to see what exactly added by the AI. * @@ -30,7 +21,7 @@ const HIGHLIGHT_BLOCKS = [ const withMindAIEditorStyles = createHigherOrderComponent( (OriginalComponent) => { function MindHighlightInsertedBlocks(props) { - const { name, clientId } = props; + const { clientId } = props; const [animateOpacity, setAnimateOpacity] = useState(false); @@ -45,7 +36,6 @@ const withMindAIEditorStyles = createHigherOrderComponent( }); const allowHighlight = - HIGHLIGHT_BLOCKS.includes(name) && highlightBlocks && highlightBlocks.length && highlightBlocks.includes(clientId); diff --git a/src/editor/extensions/post-toolbar/index.js b/src/editor/extensions/post-toolbar/index.js index 3eab3f8..1ab657a 100644 --- a/src/editor/extensions/post-toolbar/index.js +++ b/src/editor/extensions/post-toolbar/index.js @@ -5,7 +5,7 @@ import './style.scss'; */ import { __ } from '@wordpress/i18n'; import { createRoot } from '@wordpress/element'; -import { subscribe, useDispatch } from '@wordpress/data'; +import { subscribe, useSelect, useDispatch } from '@wordpress/data'; import domReady from '@wordpress/dom-ready'; // eslint-disable-next-line import/no-extraneous-dependencies import { throttle } from 'lodash'; @@ -18,7 +18,14 @@ import { ReactComponent as MindLogoIcon } from '../../../icons/mind-logo.svg'; const TOOLBAR_TOGGLE_CONTAINER_CLASS = 'mind-post-toolbar-toggle'; function Toggle() { - const { toggle } = useDispatch('mind/popup'); + const { open, setContext, setInsertionPlace } = useDispatch('mind/popup'); + + const { getSelectedBlockClientIds } = useSelect((select) => { + return { + getSelectedBlockClientIds: + select('core/block-editor').getSelectedBlockClientIds, + }; + }); return (