diff --git a/web/components/editor.tsx b/web/components/editor.tsx index cef1aa36..d52913b3 100644 --- a/web/components/editor.tsx +++ b/web/components/editor.tsx @@ -125,6 +125,13 @@ function isValidIframe(text: string) { return /^$/.test(text) } +function isValidUrl(text: string) { + // Conjured by Codex, not sure if it's actually good + return /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/.test( + text + ) +} + export function TextEditor(props: { editor: Editor | null upload: ReturnType @@ -191,8 +198,9 @@ function IframeModal(props: { setOpen: (open: boolean) => void }) { const { editor, open, setOpen } = props - const [embedCode, setEmbedCode] = useState('') - const valid = isValidIframe(embedCode) + const [input, setInput] = useState('') + const valid = isValidIframe(input) || isValidUrl(input) + const embedCode = isValidIframe(input) ? input : `' - value={embedCode} - onChange={(e) => setEmbedCode(e.target.value)} + value={input} + onChange={(e) => setInput(e.target.value)} /> {/* Preview the embed if it's valid */} @@ -222,7 +230,7 @@ function IframeModal(props: { onClick={() => { if (editor && valid) { editor.chain().insertContent(embedCode).run() - setEmbedCode('') + setInput('') setOpen(false) } }} @@ -232,7 +240,7 @@ function IframeModal(props: {