Update editorConfig.ts

This commit is contained in:
Patrick Erichsen 2025-04-07 10:40:55 -07:00
parent 204aa51a94
commit 3e1e0ea9bd

View file

@ -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;
}