Update editorConfig.ts
This commit is contained in:
parent
204aa51a94
commit
3e1e0ea9bd
1 changed files with 25 additions and 3 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { Editor } from "@tiptap/core";
|
||||
import { Editor, JSONContent } from "@tiptap/core";
|
||||
import Document from "@tiptap/extension-document";
|
||||
import History from "@tiptap/extension-history";
|
||||
import Image from "@tiptap/extension-image";
|
||||
|
|
@ -48,6 +48,28 @@ export function getPlaceholderText(
|
|||
: "Ask a follow-up";
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the editor content is valid for submission.
|
||||
* A valid submission can contain either text content or prompt/code blocks
|
||||
*
|
||||
* @param json The editor JSON content
|
||||
* @returns true if the content is valid for submission, false otherwise
|
||||
*/
|
||||
export function hasValidEditorContent(json: JSONContent): boolean {
|
||||
// Check for prompt or code blocks
|
||||
const hasPromptOrCodeBlock = json.content?.some(
|
||||
(c) =>
|
||||
c.type === ContinueExtensions.PromptBlock.name ||
|
||||
c.type === ContinueExtensions.CodeBlock.name,
|
||||
);
|
||||
|
||||
// Check for text content
|
||||
const hasTextContent = json.content?.some((c) => c.content);
|
||||
|
||||
// Content is valid if it has either text or special blocks
|
||||
return hasTextContent || hasPromptOrCodeBlock || false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called only once, so we need to use refs to pass in the latest values
|
||||
*/
|
||||
|
|
@ -367,8 +389,8 @@ export function createEditorConfig(options: {
|
|||
|
||||
const json = editor.getJSON();
|
||||
|
||||
// Don't do anything if input box is empty
|
||||
if (!json.content?.some((c) => c.content)) {
|
||||
// Don't do anything if input box doesn't have valid content
|
||||
if (!hasValidEditorContent(json)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue