move to biome (#297)

* switch to biome

* writer format

* migrate format

* packages format

* hudozka format

* writer fix

* biome config updated

* migrate fix

* packages fix

* hudozka fix

* claude updated
This commit is contained in:
tmshv authored and GitHub committed 2026-04-25 03:25:15 +03:00
1 parent 98dcaaa237
commit 467a218d00
112 files changed
+1472 -5914

No files matched your search

+20 -16
View File
@@ -1,7 +1,7 @@
import { useState, useEffect, useCallback } from "react"
import { pb } from "./pb"
import { Login } from "./components/Login"
import { useCallback, useEffect, useState } from "react"
import { Editor } from "./components/Editor"
import { Login } from "./components/Login"
import { pb } from "./pb"
import type { PbPage } from "./types"
import "./App.css"
@@ -22,9 +22,7 @@ export function App() {
setLoading(true)
setError("")
try {
const record = await pb.collection("pages").getFirstListItem<PbPage>(
`slug="${slug}"`,
)
const record = await pb.collection("pages").getFirstListItem<PbPage>(`slug="${slug}"`)
setPage(record)
} catch {
setError(`Page "${slug}" not found`)
@@ -87,8 +85,12 @@ export function App() {
if (!slug) {
return (
<div className="app-message">
<p>Add <code>?page=slug</code> to the URL to edit a page.</p>
<button onClick={handleLogout}>Logout</button>
<p>
Add <code>?page=slug</code> to the URL to edit a page.
</p>
<button type="button" onClick={handleLogout}>
Logout
</button>
</div>
)
}
@@ -101,7 +103,9 @@ export function App() {
return (
<div className="app-message">
<p className="app-error">{error}</p>
<button onClick={handleLogout}>Logout</button>
<button type="button" onClick={handleLogout}>
Logout
</button>
</div>
)
}
@@ -116,15 +120,15 @@ export function App() {
<span className="app-title">{page.title}</span>
<span className="app-slug">/{page.slug}</span>
<label className="app-published-toggle">
<input
type="checkbox"
checked={page.published}
onChange={handleTogglePublished}
/>
<input type="checkbox" checked={page.published} onChange={handleTogglePublished} />
Published
</label>
<button onClick={handleDuplicate}>Duplicate</button>
<button onClick={handleLogout}>Logout</button>
<button type="button" onClick={handleDuplicate}>
Duplicate
</button>
<button type="button" onClick={handleLogout}>
Logout
</button>
</header>
<main className="app-main">
<Editor page={page} />
@@ -1,6 +1,6 @@
import { useEffect, useCallback } from "react"
import type { Editor } from "@tiptap/react"
import { Fragment } from "@tiptap/pm/model"
import type { Editor } from "@tiptap/react"
import { useCallback, useEffect } from "react"
import "./BlockActions.css"
export type BlockActionsProps = {
@@ -68,10 +68,14 @@ export function BlockActions({ editor, getPos, showSplit }: BlockActionsProps) {
if (typeof pos !== "number") return
const node = editor.state.doc.nodeAt(pos)
if (!node) return
editor.chain().focus().deleteRange({
from: pos,
to: pos + node.nodeSize,
}).run()
editor
.chain()
.focus()
.deleteRange({
from: pos,
to: pos + node.nodeSize,
})
.run()
}
const handleSplit = (e: React.MouseEvent) => {
@@ -120,6 +124,7 @@ export function BlockActions({ editor, getPos, showSplit }: BlockActionsProps) {
return (
<div className="block-actions" contentEditable={false}>
<button
type="button"
className="block-action-btn block-action-delete"
title="Delete block"
onClick={handleDelete}
@@ -128,6 +133,7 @@ export function BlockActions({ editor, getPos, showSplit }: BlockActionsProps) {
</button>
{showSplit && (
<button
type="button"
className="block-action-btn block-action-split"
title="Split block"
onClick={handleSplit}
@@ -135,12 +141,7 @@ export function BlockActions({ editor, getPos, showSplit }: BlockActionsProps) {
&#x2702;
</button>
)}
<div
className="block-action-btn block-drag-handle"
data-drag-handle
draggable
title="Drag to reorder"
>
<div className="block-action-btn block-drag-handle" data-drag-handle draggable title="Drag to reorder">
&#x2807;
</div>
</div>
@@ -1,5 +1,5 @@
import { useState } from "react"
import type { Editor } from "@tiptap/react"
import { useState } from "react"
import { BlockMenu } from "./BlockMenu"
import "./BlockInsert.css"
@@ -30,20 +30,12 @@ export function BlockInsert({ editor, getPos }: BlockInsertProps) {
return (
<div className="block-insert" contentEditable={false}>
<button
className="block-insert-btn"
title="Add block"
onClick={handleToggle}
>
<button type="button" className="block-insert-btn" title="Add block" onClick={handleToggle}>
+
</button>
{menuOpen && (
<div className="block-insert-menu">
<BlockMenu
editor={editor}
position={insertPos}
onClose={handleClose}
/>
<BlockMenu editor={editor} position={insertPos} onClose={handleClose} />
</div>
)}
</div>
@@ -25,21 +25,29 @@ export type BlockMenuProps = {
export function BlockMenu({ editor, position, onClose, filter }: BlockMenuProps) {
const filtered = filter
? BLOCK_TYPES.filter((b) => b.label.toLowerCase().includes(filter.toLowerCase()))
? BLOCK_TYPES.filter(b => b.label.toLowerCase().includes(filter.toLowerCase()))
: BLOCK_TYPES
function handleInsert(block: BlockType) {
const id = generateBlockId()
if (block.type === "textBlock") {
editor.chain().focus().insertContentAt(position, {
type: "textBlock",
content: [{ type: "paragraph" }],
}).run()
editor
.chain()
.focus()
.insertContentAt(position, {
type: "textBlock",
content: [{ type: "paragraph" }],
})
.run()
} else {
editor.chain().focus().insertContentAt(position, {
type: block.type,
attrs: { ...block.attrs, id },
}).run()
editor
.chain()
.focus()
.insertContentAt(position, {
type: block.type,
attrs: { ...block.attrs, id },
})
.run()
}
onClose()
}
@@ -48,12 +56,8 @@ export function BlockMenu({ editor, position, onClose, filter }: BlockMenuProps)
return (
<div className="block-menu">
{filtered.map((block) => (
<button
key={block.type}
className="block-menu-item"
onClick={() => handleInsert(block)}
>
{filtered.map(block => (
<button type="button" key={block.type} className="block-menu-item" onClick={() => handleInsert(block)}>
{block.label}
</button>
))}
@@ -61,5 +65,5 @@ export function BlockMenu({ editor, position, onClose, filter }: BlockMenuProps)
)
}
export { BLOCK_TYPES }
export type { BlockType }
export { BLOCK_TYPES }
@@ -8,7 +8,7 @@ export function DraftBanner({ onDiscard }: DraftBannerProps) {
return (
<div className="draft-banner">
<span>You have unpublished changes</span>
<button onClick={onDiscard} className="draft-banner-discard">
<button type="button" onClick={onDiscard} className="draft-banner-discard">
Discard
</button>
</div>
+13 -27
View File
@@ -1,24 +1,17 @@
import { useEditor, EditorContent } from "@tiptap/react"
import StarterKit from "@tiptap/starter-kit"
import { Markdown } from "@tiptap/markdown"
import Link from "@tiptap/extension-link"
import { useState, useCallback, useRef, useEffect } from "react"
import { pb } from "../pb"
import { docToTiptap, tiptapToDoc } from "../lib/serialize"
import { Toolbar } from "./Toolbar"
import { DraftBanner } from "./DraftBanner"
import {
WriterDocument,
TextBlock,
ImageBlock,
DocumentBlock,
EmbedBlock,
CardGridBlock,
} from "../nodes"
import { Markdown } from "@tiptap/markdown"
import { EditorContent, useEditor } from "@tiptap/react"
import StarterKit from "@tiptap/starter-kit"
import { useCallback, useRef, useState } from "react"
import { SlashCommands } from "../extensions/SlashCommands"
import { docToTiptap, tiptapToDoc } from "../lib/serialize"
import { CardGridBlock, DocumentBlock, EmbedBlock, ImageBlock, TextBlock, WriterDocument } from "../nodes"
import { pb } from "../pb"
import { DraftBanner } from "./DraftBanner"
import { Toolbar } from "./Toolbar"
import "../nodes/nodes.css"
import "./Editor.css"
import type { PbPage, DocV1 } from "../types"
import type { DocV1, PbPage } from "../types"
function serializeDoc(doc: DocV1): string {
return JSON.stringify(doc)
@@ -37,15 +30,10 @@ export function Editor({ page }: EditorProps) {
const [hasDraft, setHasDraft] = useState(page.draft !== null)
const [publishedDoc, setPublishedDoc] = useState(page.doc)
const snapshotRef = useRef("")
const initialDoc = page.draft ?? page.doc
const tiptapDoc = docToTiptap(initialDoc)
// Set initial snapshot
useEffect(() => {
snapshotRef.current = serializeDoc(initialDoc)
}, []) // eslint-disable-line react-hooks/exhaustive-deps
const snapshotRef = useRef(serializeDoc(initialDoc))
const editor = useEditor({
extensions: [
@@ -157,14 +145,12 @@ export function Editor({ page }: EditorProps) {
markdownMode={markdownMode}
onToggleMarkdown={handleToggleMarkdown}
/>
{hasDraft && (
<DraftBanner onDiscard={handleDiscard} />
)}
{hasDraft && <DraftBanner onDiscard={handleDiscard} />}
{markdownMode ? (
<textarea
className="editor-markdown"
value={markdownText}
onChange={(e) => setMarkdownText(e.target.value)}
onChange={e => setMarkdownText(e.target.value)}
/>
) : (
<EditorContent editor={editor} className="editor-content" />
@@ -1,4 +1,4 @@
import { useState, useEffect, useRef } from "react"
import { useEffect, useRef, useState } from "react"
import { pb } from "../pb"
import type { PbFile } from "../types"
import "./FilePicker.css"
@@ -18,23 +18,25 @@ export function FilePicker({ onSelect, onClose }: FilePickerProps) {
const fileRef = useRef<HTMLInputElement>(null)
useEffect(() => {
loadFiles(page)
}, [page])
async function loadFiles(p: number) {
let cancelled = false
setLoading(true)
try {
const result = await pb.collection("files").getList<PbFile>(p, 20, {
sort: "-created",
pb.collection("files")
.getList<PbFile>(page, 20, { sort: "-created" })
.then(result => {
if (cancelled) return
setFiles(result.items)
setTotalPages(result.totalPages)
})
setFiles(result.items)
setTotalPages(result.totalPages)
} catch (err) {
console.error("Failed to load files:", err)
} finally {
setLoading(false)
.catch(err => {
if (!cancelled) console.error("Failed to load files:", err)
})
.finally(() => {
if (!cancelled) setLoading(false)
})
return () => {
cancelled = true
}
}
}, [page])
async function handleUpload() {
const file = fileRef.current?.files?.[0]
@@ -55,22 +57,30 @@ export function FilePicker({ onSelect, onClose }: FilePickerProps) {
}
return (
<div className="picker-overlay" onClick={onClose}>
<div className="picker" onClick={(e) => e.stopPropagation()}>
<div
className="picker-overlay"
onClick={onClose}
onKeyDown={e => {
if (e.key === "Escape") onClose()
}}
>
<div
className="picker"
onClick={e => e.stopPropagation()}
onKeyDown={e => {
e.stopPropagation()
}}
>
<div className="picker-header">
<button
className={tab === "browse" ? "active" : ""}
onClick={() => setTab("browse")}
>
<button type="button" className={tab === "browse" ? "active" : ""} onClick={() => setTab("browse")}>
Browse
</button>
<button
className={tab === "upload" ? "active" : ""}
onClick={() => setTab("upload")}
>
<button type="button" className={tab === "upload" ? "active" : ""} onClick={() => setTab("upload")}>
Upload
</button>
<button className="picker-close" onClick={onClose}>×</button>
<button type="button" className="picker-close" onClick={onClose}>
×
</button>
</div>
{tab === "browse" && (
@@ -79,8 +89,9 @@ export function FilePicker({ onSelect, onClose }: FilePickerProps) {
<div className="picker-loading">Loading...</div>
) : (
<div className="file-picker-list">
{files.map((f) => (
{files.map(f => (
<button
type="button"
key={f.id}
className="file-picker-item"
onClick={() => onSelect(f.id)}
@@ -92,17 +103,13 @@ export function FilePicker({ onSelect, onClose }: FilePickerProps) {
</div>
)}
<div className="picker-pagination">
<button
disabled={page <= 1}
onClick={() => setPage((p) => p - 1)}
>
<button type="button" disabled={page <= 1} onClick={() => setPage(p => p - 1)}>
Prev
</button>
<span>{page} / {totalPages}</span>
<button
disabled={page >= totalPages}
onClick={() => setPage((p) => p + 1)}
>
<span>
{page} / {totalPages}
</span>
<button type="button" disabled={page >= totalPages} onClick={() => setPage(p => p + 1)}>
Next
</button>
</div>
@@ -112,7 +119,7 @@ export function FilePicker({ onSelect, onClose }: FilePickerProps) {
{tab === "upload" && (
<div className="picker-upload">
<input type="file" ref={fileRef} />
<button onClick={handleUpload} disabled={uploading}>
<button type="button" onClick={handleUpload} disabled={uploading}>
{uploading ? "Uploading..." : "Upload"}
</button>
</div>
@@ -1,4 +1,4 @@
import { useState, useEffect, useRef } from "react"
import { useEffect, useRef, useState } from "react"
import { pb } from "../pb"
import type { PbImage } from "../types"
import "./ImagePicker.css"
@@ -18,23 +18,25 @@ export function ImagePicker({ onSelect, onClose }: ImagePickerProps) {
const fileRef = useRef<HTMLInputElement>(null)
useEffect(() => {
loadImages(page)
}, [page])
async function loadImages(p: number) {
let cancelled = false
setLoading(true)
try {
const result = await pb.collection("images").getList<PbImage>(p, 20, {
sort: "-created",
pb.collection("images")
.getList<PbImage>(page, 20, { sort: "-created" })
.then(result => {
if (cancelled) return
setImages(result.items)
setTotalPages(result.totalPages)
})
setImages(result.items)
setTotalPages(result.totalPages)
} catch (err) {
console.error("Failed to load images:", err)
} finally {
setLoading(false)
.catch(err => {
if (!cancelled) console.error("Failed to load images:", err)
})
.finally(() => {
if (!cancelled) setLoading(false)
})
return () => {
cancelled = true
}
}
}, [page])
async function handleUpload() {
const file = fileRef.current?.files?.[0]
@@ -64,22 +66,30 @@ export function ImagePicker({ onSelect, onClose }: ImagePickerProps) {
}
return (
<div className="picker-overlay" onClick={onClose}>
<div className="picker" onClick={(e) => e.stopPropagation()}>
<div
className="picker-overlay"
onClick={onClose}
onKeyDown={e => {
if (e.key === "Escape") onClose()
}}
>
<div
className="picker"
onClick={e => e.stopPropagation()}
onKeyDown={e => {
e.stopPropagation()
}}
>
<div className="picker-header">
<button
className={tab === "browse" ? "active" : ""}
onClick={() => setTab("browse")}
>
<button type="button" className={tab === "browse" ? "active" : ""} onClick={() => setTab("browse")}>
Browse
</button>
<button
className={tab === "upload" ? "active" : ""}
onClick={() => setTab("upload")}
>
<button type="button" className={tab === "upload" ? "active" : ""} onClick={() => setTab("upload")}>
Upload
</button>
<button className="picker-close" onClick={onClose}>×</button>
<button type="button" className="picker-close" onClick={onClose}>
×
</button>
</div>
{tab === "browse" && (
@@ -88,8 +98,9 @@ export function ImagePicker({ onSelect, onClose }: ImagePickerProps) {
<div className="picker-loading">Loading...</div>
) : (
<div className="picker-grid">
{images.map((img) => (
{images.map(img => (
<button
type="button"
key={img.id}
className="picker-thumb"
onClick={() => onSelect(img.id)}
@@ -100,17 +111,13 @@ export function ImagePicker({ onSelect, onClose }: ImagePickerProps) {
</div>
)}
<div className="picker-pagination">
<button
disabled={page <= 1}
onClick={() => setPage((p) => p - 1)}
>
<button type="button" disabled={page <= 1} onClick={() => setPage(p => p - 1)}>
Prev
</button>
<span>{page} / {totalPages}</span>
<button
disabled={page >= totalPages}
onClick={() => setPage((p) => p + 1)}
>
<span>
{page} / {totalPages}
</span>
<button type="button" disabled={page >= totalPages} onClick={() => setPage(p => p + 1)}>
Next
</button>
</div>
@@ -120,7 +127,7 @@ export function ImagePicker({ onSelect, onClose }: ImagePickerProps) {
{tab === "upload" && (
<div className="picker-upload">
<input type="file" accept="image/*" ref={fileRef} />
<button onClick={handleUpload} disabled={uploading}>
<button type="button" onClick={handleUpload} disabled={uploading}>
{uploading ? "Uploading..." : "Upload"}
</button>
</div>
+3 -3
View File
@@ -1,5 +1,5 @@
import { useState } from "react"
import type { FormEvent } from "react"
import { useState } from "react"
import { pb } from "../pb"
import "./Login.css"
@@ -36,14 +36,14 @@ export function Login({ onLogin }: LoginProps) {
type="email"
placeholder="Email"
value={email}
onChange={(e) => setEmail(e.target.value)}
onChange={e => setEmail(e.target.value)}
required
/>
<input
type="password"
placeholder="Password"
value={password}
onChange={(e) => setPassword(e.target.value)}
onChange={e => setPassword(e.target.value)}
required
/>
<button type="submit" disabled={loading}>
+15 -5
View File
@@ -33,6 +33,7 @@ export function Toolbar({
<div className="toolbar">
<div className="toolbar-group">
<button
type="button"
onClick={() => editor.chain().focus().toggleBold().run()}
className={editor.isActive("bold") ? "active" : ""}
title="Bold"
@@ -40,6 +41,7 @@ export function Toolbar({
B
</button>
<button
type="button"
onClick={() => editor.chain().focus().toggleItalic().run()}
className={editor.isActive("italic") ? "active" : ""}
title="Italic"
@@ -47,6 +49,7 @@ export function Toolbar({
I
</button>
<button
type="button"
onClick={() => editor.chain().focus().toggleStrike().run()}
className={editor.isActive("strike") ? "active" : ""}
title="Strikethrough"
@@ -54,6 +57,7 @@ export function Toolbar({
S
</button>
<button
type="button"
onClick={() => editor.chain().focus().toggleCode().run()}
className={editor.isActive("code") ? "active" : ""}
title="Inline code"
@@ -64,18 +68,21 @@ export function Toolbar({
<div className="toolbar-group">
<button
type="button"
onClick={() => editor.chain().focus().toggleHeading({ level: 1 }).run()}
className={editor.isActive("heading", { level: 1 }) ? "active" : ""}
>
H1
</button>
<button
type="button"
onClick={() => editor.chain().focus().toggleHeading({ level: 2 }).run()}
className={editor.isActive("heading", { level: 2 }) ? "active" : ""}
>
H2
</button>
<button
type="button"
onClick={() => editor.chain().focus().toggleHeading({ level: 3 }).run()}
className={editor.isActive("heading", { level: 3 }) ? "active" : ""}
>
@@ -85,6 +92,7 @@ export function Toolbar({
<div className="toolbar-group">
<button
type="button"
onClick={() => editor.chain().focus().toggleBulletList().run()}
className={editor.isActive("bulletList") ? "active" : ""}
title="Bullet list"
@@ -92,6 +100,7 @@ export function Toolbar({
List
</button>
<button
type="button"
onClick={() => editor.chain().focus().toggleOrderedList().run()}
className={editor.isActive("orderedList") ? "active" : ""}
title="Numbered list"
@@ -99,6 +108,7 @@ export function Toolbar({
1.
</button>
<button
type="button"
onClick={() => editor.chain().focus().toggleBlockquote().run()}
className={editor.isActive("blockquote") ? "active" : ""}
title="Blockquote"
@@ -106,6 +116,7 @@ export function Toolbar({
&ldquo;
</button>
<button
type="button"
onClick={() => editor.chain().focus().toggleCodeBlock().run()}
className={editor.isActive("codeBlock") ? "active" : ""}
title="Code block"
@@ -113,6 +124,7 @@ export function Toolbar({
Code
</button>
<button
type="button"
onClick={() => editor.chain().focus().setHorizontalRule().run()}
title="Horizontal rule"
>
@@ -122,6 +134,7 @@ export function Toolbar({
<div className="toolbar-group">
<button
type="button"
onClick={onToggleMarkdown}
className={markdownMode ? "active" : ""}
title="Toggle markdown view"
@@ -131,14 +144,11 @@ export function Toolbar({
</div>
<div className="toolbar-group toolbar-actions">
<button
onClick={onSave}
disabled={!canSave || saving}
className="toolbar-save-btn"
>
<button type="button" onClick={onSave} disabled={!canSave || saving} className="toolbar-save-btn">
{saving ? "Saving..." : "Save"}
</button>
<button
type="button"
onClick={onPublish}
disabled={!canPublish || publishing}
className="toolbar-publish-btn"
@@ -1,12 +1,12 @@
import { Extension } from "@tiptap/core"
import { PluginKey } from "@tiptap/pm/state"
import type { Node as PmNode, ResolvedPos } from "@tiptap/pm/model"
import { Fragment } from "@tiptap/pm/model"
import type { ResolvedPos, Node as PmNode } from "@tiptap/pm/model"
import { PluginKey } from "@tiptap/pm/state"
import type { Editor } from "@tiptap/react"
import type { SuggestionKeyDownProps, SuggestionOptions, SuggestionProps } from "@tiptap/suggestion"
import Suggestion from "@tiptap/suggestion"
import type { SuggestionOptions, SuggestionProps, SuggestionKeyDownProps } from "@tiptap/suggestion"
import { createRoot } from "react-dom/client"
import { generateBlockId } from "../lib/id"
import type { Editor } from "@tiptap/react"
import "./SlashCommands.css"
type SlashCommandItem = {
@@ -34,13 +34,22 @@ function findTextBlockDepth($pos: ResolvedPos): number | null {
return null
}
function SlashMenu({ items, command, selectedIndex }: { items: SlashCommandItem[]; command: (item: SlashCommandItem) => void; selectedIndex: number }) {
function SlashMenu({
items,
command,
selectedIndex,
}: {
items: SlashCommandItem[]
command: (item: SlashCommandItem) => void
selectedIndex: number
}) {
if (items.length === 0) return null
return (
<div className="slash-menu">
{items.map((item, index) => (
<button
type="button"
key={item.type}
className={`slash-menu-item${index === selectedIndex ? " slash-menu-item--selected" : ""}`}
onClick={() => command(item)}
@@ -62,9 +71,7 @@ export const SlashCommands = Extension.create({
pluginKey: slashCommandsPluginKey,
startOfLine: true,
items: ({ query }: { query: string }) => {
return ITEMS.filter((item) =>
item.label.toLowerCase().includes(query.toLowerCase())
)
return ITEMS.filter(item => item.label.toLowerCase().includes(query.toLowerCase()))
},
render: () => {
let container: HTMLDivElement | null = null
@@ -74,13 +81,9 @@ export const SlashCommands = Extension.create({
let currentCommand: ((item: SlashCommandItem) => void) | null = null
function renderMenu() {
if (!root) return
if (!root || !currentCommand) return
root.render(
<SlashMenu
items={currentItems}
command={currentCommand!}
selectedIndex={selectedIndex}
/>
<SlashMenu items={currentItems} command={currentCommand} selectedIndex={selectedIndex} />,
)
}
@@ -153,7 +156,15 @@ export const SlashCommands = Extension.create({
},
}
},
command: ({ editor, range, props }: { editor: Editor; range: { from: number; to: number }; props: SlashCommandItem }) => {
command: ({
editor,
range,
props,
}: {
editor: Editor
range: { from: number; to: number }
props: SlashCommandItem
}) => {
// Delete the slash command text
editor.chain().focus().deleteRange(range).run()
@@ -193,7 +204,7 @@ export const SlashCommands = Extension.create({
if (curChild.content.size === 0 && i > 0) {
splitAfter = i - 1
} else if (curChild.content.size === 0 && i === 0) {
splitAfter = -1 // cursor in empty first child
splitAfter = -1 // cursor in empty first child
} else {
splitAfter = i
}
@@ -213,16 +224,14 @@ export const SlashCommands = Extension.create({
children.push(textBlockNode.child(i))
}
// Skip if all children are empty paragraphs
const hasContent = children.some((c) => c.content.size > 0)
const hasContent = children.some(c => c.content.size > 0)
if (hasContent) {
fragments.push(textBlockType.create(null, children))
}
}
// Insert the custom block
fragments.push(schema.nodes[props.type].create(
{ ...props.attrs, id },
))
fragments.push(schema.nodes[props.type].create({ ...props.attrs, id }))
// Build second textBlock (children after splitAfter) — skip empty
const remaining = []
@@ -231,7 +240,7 @@ export const SlashCommands = Extension.create({
remaining.push(textBlockNode.child(i))
}
// Filter out empty paragraphs at the edges
const nonEmpty = remaining.filter((c) => c.content.size > 0)
const nonEmpty = remaining.filter(c => c.content.size > 0)
if (nonEmpty.length > 0) {
fragments.push(textBlockType.create(null, remaining))
}
+2 -5
View File
@@ -1,16 +1,13 @@
import Link from "@tiptap/extension-link"
import { MarkdownManager } from "@tiptap/markdown"
import StarterKit from "@tiptap/starter-kit"
import Link from "@tiptap/extension-link"
let manager: MarkdownManager | null = null
export function getMarkdownManager(): MarkdownManager {
if (!manager) {
manager = new MarkdownManager({
extensions: [
StarterKit,
Link,
],
extensions: [StarterKit, Link],
})
}
return manager
+67 -67
View File
@@ -2,11 +2,11 @@ import type { JSONContent } from "@tiptap/core"
import type {
DocV1,
DocV1Block,
DocV1BlockText,
DocV1BlockImage,
DocV1BlockCardGrid,
DocV1BlockDocument,
DocV1BlockEmbed,
DocV1BlockCardGrid,
DocV1BlockImage,
DocV1BlockText,
} from "../types"
import { generateBlockId } from "./id"
import { getMarkdownManager } from "./markdown"
@@ -70,21 +70,21 @@ export function docToTiptap(doc: DocV1): JSONContent {
for (const block of doc.blocks) {
switch (block.type) {
case "text":
content.push(textBlockToTiptap(block))
break
case "image":
content.push(imageBlockToTiptap(block))
break
case "document":
content.push(documentBlockToTiptap(block))
break
case "embed":
content.push(embedBlockToTiptap(block))
break
case "card-grid":
content.push(cardGridBlockToTiptap(block))
break
case "text":
content.push(textBlockToTiptap(block))
break
case "image":
content.push(imageBlockToTiptap(block))
break
case "document":
content.push(documentBlockToTiptap(block))
break
case "embed":
content.push(embedBlockToTiptap(block))
break
case "card-grid":
content.push(cardGridBlockToTiptap(block))
break
}
}
@@ -107,60 +107,60 @@ export function tiptapToDoc(content: JSONContent[]): DocV1 {
for (const node of content) {
switch (node.type) {
case "textBlock": {
const text = textNodesToMarkdown(node.content ?? [])
if (text.trim()) {
blocks.push({
type: "text",
id: generateBlockId(),
text,
})
case "textBlock": {
const text = textNodesToMarkdown(node.content ?? [])
if (text.trim()) {
blocks.push({
type: "text",
id: generateBlockId(),
text,
})
}
break
}
break
}
case "imageBlock": {
const attrs = node.attrs ?? {}
blocks.push({
type: "image",
id: attrs.id ?? generateBlockId(),
image: attrs.imageId ?? "",
wide: attrs.wide ?? false,
caption: attrs.caption ?? "",
})
break
}
case "imageBlock": {
const attrs = node.attrs ?? {}
blocks.push({
type: "image",
id: attrs.id ?? generateBlockId(),
image: attrs.imageId ?? "",
wide: attrs.wide ?? false,
caption: attrs.caption ?? "",
})
break
}
case "documentBlock": {
const attrs = node.attrs ?? {}
blocks.push({
type: "document",
id: attrs.id ?? generateBlockId(),
file: attrs.fileId ?? "",
title: attrs.title ?? "",
})
break
}
case "documentBlock": {
const attrs = node.attrs ?? {}
blocks.push({
type: "document",
id: attrs.id ?? generateBlockId(),
file: attrs.fileId ?? "",
title: attrs.title ?? "",
})
break
}
case "embedBlock": {
const attrs = node.attrs ?? {}
blocks.push({
type: "embed",
id: attrs.id ?? generateBlockId(),
src: attrs.src ?? "",
})
break
}
case "embedBlock": {
const attrs = node.attrs ?? {}
blocks.push({
type: "embed",
id: attrs.id ?? generateBlockId(),
src: attrs.src ?? "",
})
break
}
case "cardGridBlock": {
const attrs = node.attrs ?? {}
blocks.push({
type: "card-grid",
id: attrs.id ?? generateBlockId(),
items: JSON.parse(attrs.items ?? "[]"),
})
break
}
case "cardGridBlock": {
const attrs = node.attrs ?? {}
blocks.push({
type: "card-grid",
id: attrs.id ?? generateBlockId(),
items: JSON.parse(attrs.items ?? "[]"),
})
break
}
}
}
+4 -1
View File
@@ -3,7 +3,10 @@ import { createRoot } from "react-dom/client"
import { App } from "./App"
import "./index.css"
createRoot(document.getElementById("root")!).render(
const rootElement = document.getElementById("root")
if (!rootElement) throw new Error("Root element #root not found")
createRoot(rootElement).render(
<StrictMode>
<App />
</StrictMode>,
+12 -14
View File
@@ -1,11 +1,11 @@
import { Node, mergeAttributes } from "@tiptap/core"
import { ReactNodeViewRenderer, NodeViewWrapper } from "@tiptap/react"
import { mergeAttributes, Node } from "@tiptap/core"
import type { NodeViewProps } from "@tiptap/react"
import { useState, useEffect } from "react"
import { pb } from "../pb"
import type { PbPage } from "../types"
import { NodeViewWrapper, ReactNodeViewRenderer } from "@tiptap/react"
import { useEffect, useMemo, useState } from "react"
import { BlockActions } from "../components/BlockActions"
import { BlockInsert } from "../components/BlockInsert"
import { pb } from "../pb"
import type { PbPage } from "../types"
type ResolvedItem = {
page: string
@@ -13,7 +13,7 @@ type ResolvedItem = {
}
function CardGridBlockView({ node, editor, getPos }: NodeViewProps) {
const items = JSON.parse(node.attrs.items || "[]")
const items = useMemo<Array<{ page: string }>>(() => JSON.parse(node.attrs.items || "[]"), [node.attrs.items])
const [resolved, setResolved] = useState<ResolvedItem[]>([])
const [loading, setLoading] = useState(false)
@@ -25,33 +25,31 @@ function CardGridBlockView({ node, editor, getPos }: NodeViewProps) {
setLoading(true)
Promise.all(
items.map(async (item: { page: string }) => {
items.map(async item => {
try {
const page = await pb.collection("pages").getOne<PbPage>(item.page)
return { page: item.page, title: page.title }
} catch {
return { page: item.page, title: null }
}
})
).then((results) => {
}),
).then(results => {
setResolved(results)
setLoading(false)
})
}, [node.attrs.items])
}, [items])
return (
<>
<NodeViewWrapper className="node-view-block node-readonly-block">
<BlockActions editor={editor} getPos={getPos} />
<div className="node-view-content">
<div className="node-block-label">
Card Grid ({items.length})
</div>
<div className="node-block-label">Card Grid ({items.length})</div>
{loading ? (
<div className="node-block-info">Loading...</div>
) : (
<ul className="node-cardgrid-list">
{resolved.map((item) => (
{resolved.map(item => (
<li key={item.page} className="node-cardgrid-item">
{item.title ?? item.page}
</li>
+23 -26
View File
@@ -1,12 +1,12 @@
import { Node, mergeAttributes } from "@tiptap/core"
import { ReactNodeViewRenderer, NodeViewWrapper } from "@tiptap/react"
import { mergeAttributes, Node } from "@tiptap/core"
import type { NodeViewProps } from "@tiptap/react"
import { useState, useEffect } from "react"
import { pb } from "../pb"
import { FilePicker } from "../components/FilePicker"
import type { PbFile } from "../types"
import { NodeViewWrapper, ReactNodeViewRenderer } from "@tiptap/react"
import { useEffect, useState } from "react"
import { BlockActions } from "../components/BlockActions"
import { BlockInsert } from "../components/BlockInsert"
import { FilePicker } from "../components/FilePicker"
import { pb } from "../pb"
import type { PbFile } from "../types"
function DocumentBlockView({ node, updateAttributes, editor, getPos }: NodeViewProps) {
const { fileId, title } = node.attrs
@@ -15,11 +15,14 @@ function DocumentBlockView({ node, updateAttributes, editor, getPos }: NodeViewP
useEffect(() => {
if (!fileId) return
pb.collection("files").getOne<PbFile>(fileId).then((f) => {
setFilename(f.filename)
}).catch(() => {
setFilename(null)
})
pb.collection("files")
.getOne<PbFile>(fileId)
.then(f => {
setFilename(f.filename)
})
.catch(() => {
setFilename(null)
})
}, [fileId])
function handleSelect(newFileId: string) {
@@ -34,43 +37,37 @@ function DocumentBlockView({ node, updateAttributes, editor, getPos }: NodeViewP
<div className="node-view-content">
<div className="node-block-label">File</div>
{fileId ? (
<div
<button
type="button"
className="node-document-file"
onClick={() => setShowPicker(true)}
style={{ cursor: "pointer" }}
>
📎 {filename ?? fileId}
</div>
</button>
) : (
<div
<button
type="button"
className="node-document-placeholder"
onClick={() => setShowPicker(true)}
style={{ cursor: "pointer" }}
>
Click to select file
</div>
</button>
)}
<div className="node-document-controls">
<input
type="text"
placeholder="Title"
value={title || ""}
onChange={(e) => updateAttributes({ title: e.target.value })}
onChange={e => updateAttributes({ title: e.target.value })}
className="node-document-title"
/>
<button
className="node-image-pick-btn"
onClick={() => setShowPicker(true)}
>
<button type="button" className="node-image-pick-btn" onClick={() => setShowPicker(true)}>
Pick
</button>
</div>
{showPicker && (
<FilePicker
onSelect={handleSelect}
onClose={() => setShowPicker(false)}
/>
)}
{showPicker && <FilePicker onSelect={handleSelect} onClose={() => setShowPicker(false)} />}
</div>
</NodeViewWrapper>
<BlockInsert editor={editor} getPos={getPos} />
+2 -2
View File
@@ -1,6 +1,6 @@
import { Node, mergeAttributes } from "@tiptap/core"
import { ReactNodeViewRenderer, NodeViewWrapper } from "@tiptap/react"
import { mergeAttributes, Node } from "@tiptap/core"
import type { NodeViewProps } from "@tiptap/react"
import { NodeViewWrapper, ReactNodeViewRenderer } from "@tiptap/react"
import { BlockActions } from "../components/BlockActions"
import { BlockInsert } from "../components/BlockInsert"
+29 -32
View File
@@ -1,12 +1,12 @@
import { Node, mergeAttributes } from "@tiptap/core"
import { ReactNodeViewRenderer, NodeViewWrapper } from "@tiptap/react"
import { mergeAttributes, Node } from "@tiptap/core"
import type { NodeViewProps } from "@tiptap/react"
import { pb } from "../pb"
import type { PbImage } from "../types"
import { useState, useEffect } from "react"
import { ImagePicker } from "../components/ImagePicker"
import { NodeViewWrapper, ReactNodeViewRenderer } from "@tiptap/react"
import { useEffect, useState } from "react"
import { BlockActions } from "../components/BlockActions"
import { BlockInsert } from "../components/BlockInsert"
import { ImagePicker } from "../components/ImagePicker"
import { pb } from "../pb"
import type { PbImage } from "../types"
function ImageBlockView({ node, updateAttributes, editor, getPos }: NodeViewProps) {
const { imageId, wide, caption } = node.attrs
@@ -15,12 +15,15 @@ function ImageBlockView({ node, updateAttributes, editor, getPos }: NodeViewProp
useEffect(() => {
if (!imageId) return
pb.collection("images").getOne<PbImage>(imageId).then((img) => {
const url = pb.files.getURL(img, img.file, { thumb: "300x200" })
setThumbnail(url)
}).catch(() => {
setThumbnail(null)
})
pb.collection("images")
.getOne<PbImage>(imageId)
.then(img => {
const url = pb.files.getURL(img, img.file, { thumb: "300x200" })
setThumbnail(url)
})
.catch(() => {
setThumbnail(null)
})
}, [imageId])
function handleSelect(newImageId: string) {
@@ -35,28 +38,30 @@ function ImageBlockView({ node, updateAttributes, editor, getPos }: NodeViewProp
<div className="node-view-content">
<div className="node-block-label">Image</div>
{thumbnail ? (
<img
src={thumbnail}
alt={caption || "image"}
className="node-image-thumb"
<button
type="button"
className="node-image-thumb-button"
onClick={() => setShowPicker(true)}
style={{ cursor: "pointer" }}
/>
style={{ cursor: "pointer", padding: 0, border: 0, background: "none" }}
>
<img src={thumbnail} alt={caption || "image"} className="node-image-thumb" />
</button>
) : (
<div
<button
type="button"
className="node-image-placeholder"
onClick={() => setShowPicker(true)}
style={{ cursor: "pointer" }}
>
{imageId ? "Loading..." : "Click to select image"}
</div>
</button>
)}
<div className="node-image-controls">
<label>
<input
type="checkbox"
checked={wide}
onChange={(e) => updateAttributes({ wide: e.target.checked })}
onChange={e => updateAttributes({ wide: e.target.checked })}
/>
Wide
</label>
@@ -64,22 +69,14 @@ function ImageBlockView({ node, updateAttributes, editor, getPos }: NodeViewProp
type="text"
placeholder="Caption"
value={caption || ""}
onChange={(e) => updateAttributes({ caption: e.target.value })}
onChange={e => updateAttributes({ caption: e.target.value })}
className="node-image-caption"
/>
<button
className="node-image-pick-btn"
onClick={() => setShowPicker(true)}
>
<button type="button" className="node-image-pick-btn" onClick={() => setShowPicker(true)}>
Pick
</button>
</div>
{showPicker && (
<ImagePicker
onSelect={handleSelect}
onClose={() => setShowPicker(false)}
/>
)}
{showPicker && <ImagePicker onSelect={handleSelect} onClose={() => setShowPicker(false)} />}
</div>
</NodeViewWrapper>
<BlockInsert editor={editor} getPos={getPos} />
+2 -2
View File
@@ -1,6 +1,6 @@
import { Node, mergeAttributes } from "@tiptap/core"
import { ReactNodeViewRenderer, NodeViewWrapper, NodeViewContent } from "@tiptap/react"
import { mergeAttributes, Node } from "@tiptap/core"
import type { NodeViewProps } from "@tiptap/react"
import { NodeViewContent, NodeViewWrapper, ReactNodeViewRenderer } from "@tiptap/react"
import { BlockActions } from "../components/BlockActions"
import { BlockInsert } from "../components/BlockInsert"
+4 -4
View File
@@ -1,6 +1,6 @@
export { WriterDocument } from "./WriterDocument"
export { TextBlock } from "./TextBlock"
export { ImageBlock } from "./ImageBlock"
export { CardGridBlock } from "./CardGridBlock"
export { DocumentBlock } from "./DocumentBlock"
export { EmbedBlock } from "./EmbedBlock"
export { CardGridBlock } from "./CardGridBlock"
export { ImageBlock } from "./ImageBlock"
export { TextBlock } from "./TextBlock"
export { WriterDocument } from "./WriterDocument"
+1 -6
View File
@@ -77,12 +77,7 @@ export type DocV1BlockCardGrid = {
items: DocV1BlockCardGridItem[]
}
export type DocV1Block =
| DocV1BlockText
| DocV1BlockImage
| DocV1BlockDocument
| DocV1BlockEmbed
| DocV1BlockCardGrid
export type DocV1Block = DocV1BlockText | DocV1BlockImage | DocV1BlockDocument | DocV1BlockEmbed | DocV1BlockCardGrid
export type DocV1 = {
version: 1