'use client' import { useEffect, useState } from 'react' import { createReactBlockSpec, createReactInlineContentSpec } from '@blocknote/react' import { useTranslation } from 'react-i18next' import { Info, Lightbulb, AlertTriangle, ChevronRight, Globe, ExternalLink, Pencil, ListTree, FileCode, } from 'lucide-react' import dynamic from 'next/dynamic' import type { NoteBlock } from '@/lib/notes-api' import { safeNoteUrl } from '../model/urls' const TaskView = dynamic(() => import('./NoteTaskView'), { ssr: false }) export const callout = createReactBlockSpec( { type: 'callout', propSchema: { tone: { default: 'tip' } }, content: 'inline' }, { render: function Callout({ block, editor, contentRef }) { const { t } = useTranslation() const icons = { tip: Lightbulb, info: Info, warning: AlertTriangle } const tone = block.props.tone as keyof typeof icons const Icon = icons[tone] || Info return (
) }, } ) export const toggleHeading = createReactBlockSpec( { type: 'toggleHeading', propSchema: { level: { default: 2 }, collapsed: { default: false } }, content: 'inline', }, { render: ({ block, contentRef }) => (
), renderFrame: function Toggle({ block, editor, slotRef }) { const { t } = useTranslation() return (
) }, } ) export const noteColumn = createReactBlockSpec( { type: 'noteColumn', content: 'none', propSchema: {}, layoutOnly: true, placeable: 'namedOnly' }, { renderFrame: ({ slotRef }) =>
} ) export const noteColumns = createReactBlockSpec( { type: 'noteColumns', content: 'none', propSchema: {}, layoutOnly: true, children: { allow: ['noteColumn'], min: 2, dissolve: true }, }, { renderFrame: ({ slotRef }) =>
} ) export const tableOfContents = createReactBlockSpec( { type: 'tableOfContents', content: 'none', propSchema: {} }, { render: function Contents({ editor }) { const { t } = useTranslation() const [headings, setHeadings] = useState([]) useEffect(() => { const refresh = () => { const result: NoteBlock[] = [] const walk = (blocks: NoteBlock[]) => blocks.forEach(b => { if (b.type === 'heading' || b.type === 'toggleHeading') result.push(b) walk(b.children || []) }) walk(editor.document as NoteBlock[]) setHeadings(result) } refresh() return editor.onChange(refresh) }, [editor]) return ( ) }, } ) export const webCard = createReactBlockSpec( { type: 'webCard', content: 'none', propSchema: { url: { default: '' }, title: { default: '' }, description: { default: '' }, mode: { default: 'bookmark' }, }, }, { render: function WebCard({ block, editor }) { const { t } = useTranslation() const [edit, setEdit] = useState(!block.props.url) const [url, setUrl] = useState(block.props.url) const [title, setTitle] = useState(block.props.title) const [description, setDescription] = useState(block.props.description) const [error, setError] = useState('') const safe = safeNoteUrl(block.props.url) const host = safe && /^https?:/.test(safe) ? new URL(safe).hostname : '' return (
{edit ? (
{ e.preventDefault() const normalized = url.trim() if (!safeNoteUrl(normalized) || !/^https?:/i.test(normalized)) { setError(t('Enter an HTTP or HTTPS URL')) return } editor.updateBlock(block, { props: { url: normalized, title: title.trim(), description: description.trim() }, }) setEdit(false) setError('') }} > {error &&

{error}

}
{block.props.url && ( )}
) : ( <> {block.props.mode === 'embed' && safe && ( <>