mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-04-27 17:36:25 +02:00
Refactor RowboatX configuration and enhance editor features
- Updated `next.config.ts` to scope Turbopack to the app's directory. - Modified `package.json` and `package-lock.json` to include new dependencies for Tiptap and markdown processing. - Removed deprecated chat API and added new agent and config routes for file management. - Introduced `JsonEditor` and `MarkdownViewer` components for improved content editing and display. - Enhanced `TiptapMarkdownEditor` with additional toolbar options and markdown parsing capabilities. - Updated layout and page components to integrate new editors and improve user experience.
This commit is contained in:
parent
da20e280f4
commit
c637cb49ac
26 changed files with 2552 additions and 540 deletions
|
|
@ -53,7 +53,13 @@ export const CheckpointTrigger = ({
|
|||
tooltip ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button size={size} type="button" variant={variant} {...props}>
|
||||
<Button
|
||||
className={cn(className)}
|
||||
size={size}
|
||||
type="button"
|
||||
variant={variant}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
|
|
@ -62,7 +68,13 @@ export const CheckpointTrigger = ({
|
|||
</TooltipContent>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<Button size={size} type="button" variant={variant} {...props}>
|
||||
<Button
|
||||
className={cn(className)}
|
||||
size={size}
|
||||
type="button"
|
||||
variant={variant}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</Button>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable @next/next/no-img-element */
|
||||
import { cn } from "@/lib/utils";
|
||||
import type { Experimental_GeneratedImage } from "ai";
|
||||
|
||||
|
|
@ -8,7 +9,6 @@ export type ImageProps = Experimental_GeneratedImage & {
|
|||
|
||||
export const Image = ({
|
||||
base64,
|
||||
uint8Array,
|
||||
mediaType,
|
||||
...props
|
||||
}: ImageProps) => (
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
"use client";
|
||||
|
||||
/* eslint-disable @next/next/no-img-element */
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
ButtonGroup,
|
||||
|
|
@ -20,7 +21,7 @@ import {
|
|||
XIcon,
|
||||
} from "lucide-react";
|
||||
import type { ComponentProps, HTMLAttributes, ReactElement } from "react";
|
||||
import { createContext, memo, useContext, useEffect, useState } from "react";
|
||||
import { createContext, memo, useContext, useEffect, useMemo, useState } from "react";
|
||||
import { Streamdown } from "streamdown";
|
||||
|
||||
export type MessageProps = HTMLAttributes<HTMLDivElement> & {
|
||||
|
|
@ -188,7 +189,10 @@ export const MessageBranchContent = ({
|
|||
...props
|
||||
}: MessageBranchContentProps) => {
|
||||
const { currentBranch, setBranches, branches } = useMessageBranch();
|
||||
const childrenArray = Array.isArray(children) ? children : [children];
|
||||
const childrenArray = useMemo(
|
||||
() => (Array.isArray(children) ? children : [children]),
|
||||
[children]
|
||||
);
|
||||
|
||||
// Use useEffect to update branches when they change
|
||||
useEffect(() => {
|
||||
|
|
@ -211,13 +215,10 @@ export const MessageBranchContent = ({
|
|||
));
|
||||
};
|
||||
|
||||
export type MessageBranchSelectorProps = HTMLAttributes<HTMLDivElement> & {
|
||||
from: UIMessage["role"];
|
||||
};
|
||||
export type MessageBranchSelectorProps = HTMLAttributes<HTMLDivElement>;
|
||||
|
||||
export const MessageBranchSelector = ({
|
||||
className,
|
||||
from,
|
||||
...props
|
||||
}: MessageBranchSelectorProps) => {
|
||||
const { totalBranches } = useMessageBranch();
|
||||
|
|
@ -229,7 +230,10 @@ export const MessageBranchSelector = ({
|
|||
|
||||
return (
|
||||
<ButtonGroup
|
||||
className="[&>*:not(:first-child)]:rounded-l-md [&>*:not(:last-child)]:rounded-r-md"
|
||||
className={cn(
|
||||
"[&>*:not(:first-child)]:rounded-l-md [&>*:not(:last-child)]:rounded-r-md",
|
||||
className
|
||||
)}
|
||||
orientation="horizontal"
|
||||
{...props}
|
||||
/>
|
||||
|
|
@ -276,6 +280,7 @@ export const MessageBranchNext = ({
|
|||
size="icon-sm"
|
||||
type="button"
|
||||
variant="ghost"
|
||||
className={className}
|
||||
{...props}
|
||||
>
|
||||
{children ?? <ChevronRightIcon size={14} />}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
/* eslint-disable @next/next/no-img-element */
|
||||
import {
|
||||
Command,
|
||||
CommandDialog,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
"use client";
|
||||
|
||||
/* eslint-disable @next/next/no-img-element */
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Command,
|
||||
|
|
@ -666,7 +667,6 @@ export const PromptInput = ({
|
|||
}
|
||||
}
|
||||
},
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- cleanup only on unmount; filesRef always current
|
||||
[usingProvider]
|
||||
);
|
||||
|
||||
|
|
@ -726,7 +726,7 @@ export const PromptInput = ({
|
|||
|
||||
// Convert blob URLs to data URLs asynchronously
|
||||
Promise.all(
|
||||
files.map(async ({ id, ...item }) => {
|
||||
files.map(async ({ ...item }) => {
|
||||
if (item.url && item.url.startsWith("blob:")) {
|
||||
const dataUrl = await convertBlobUrlToDataUrl(item.url);
|
||||
// If conversion failed, keep the original blob URL
|
||||
|
|
@ -1060,13 +1060,13 @@ interface SpeechRecognition extends EventTarget {
|
|||
lang: string;
|
||||
start(): void;
|
||||
stop(): void;
|
||||
onstart: ((this: SpeechRecognition, ev: Event) => any) | null;
|
||||
onend: ((this: SpeechRecognition, ev: Event) => any) | null;
|
||||
onstart: ((this: SpeechRecognition, ev: Event) => void) | null;
|
||||
onend: ((this: SpeechRecognition, ev: Event) => void) | null;
|
||||
onresult:
|
||||
| ((this: SpeechRecognition, ev: SpeechRecognitionEvent) => any)
|
||||
| ((this: SpeechRecognition, ev: SpeechRecognitionEvent) => void)
|
||||
| null;
|
||||
onerror:
|
||||
| ((this: SpeechRecognition, ev: SpeechRecognitionErrorEvent) => any)
|
||||
| ((this: SpeechRecognition, ev: SpeechRecognitionErrorEvent) => void)
|
||||
| null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
"use client";
|
||||
|
||||
/* eslint-disable @next/next/no-img-element */
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Collapsible,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import { ChevronRight, Clock3, FileText, Folder, Play, Plug, Rocket, Users } fro
|
|||
|
||||
import { NavUser } from "@/components/nav-user"
|
||||
import { TeamSwitcher } from "@/components/team-switcher"
|
||||
import { NavMain } from "@/components/nav-main"
|
||||
import { NavProjects } from "@/components/nav-projects"
|
||||
import {
|
||||
Sidebar,
|
||||
|
|
|
|||
197
apps/rowboatx/components/json-editor.css
Normal file
197
apps/rowboatx/components/json-editor.css
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
.json-editor-wrapper {
|
||||
height: 100%;
|
||||
min-height: 240px;
|
||||
max-height: 70vh;
|
||||
overflow: auto;
|
||||
border-radius: 0.375rem;
|
||||
border: 1px solid hsl(var(--border));
|
||||
background: hsl(var(--background));
|
||||
position: relative;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
/* Dark mode wrapper */
|
||||
.dark .json-editor-wrapper {
|
||||
background: hsl(var(--background));
|
||||
border-color: hsl(var(--border));
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.json-editor-wrapper {
|
||||
background: hsl(var(--background));
|
||||
border-color: hsl(var(--border));
|
||||
}
|
||||
}
|
||||
|
||||
.json-editor-line-numbers {
|
||||
position: sticky;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 3.5rem;
|
||||
flex-shrink: 0;
|
||||
border-right: 1px solid hsl(var(--border) / 0.3);
|
||||
background: hsl(var(--muted) / 0.03);
|
||||
padding: 1rem 0.75rem 1rem 0.5rem;
|
||||
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.75;
|
||||
user-select: none;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.json-editor-line-number {
|
||||
color: hsl(var(--muted-foreground) / 0.6);
|
||||
text-align: right;
|
||||
font-variant-numeric: tabular-nums;
|
||||
height: 1.75rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
/* Dark mode line numbers */
|
||||
.dark .json-editor-line-numbers {
|
||||
background: hsl(var(--muted) / 0.15);
|
||||
border-right-color: hsl(var(--border) / 0.5);
|
||||
}
|
||||
|
||||
.dark .json-editor-line-number {
|
||||
color: hsl(var(--muted-foreground) / 0.7);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.json-editor-line-numbers {
|
||||
background: hsl(var(--muted) / 0.15);
|
||||
border-right-color: hsl(var(--border) / 0.5);
|
||||
}
|
||||
|
||||
.json-editor-line-number {
|
||||
color: hsl(var(--muted-foreground) / 0.7);
|
||||
}
|
||||
}
|
||||
|
||||
.json-editor-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
height: 100%;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.json-editor-content:focus-visible {
|
||||
outline: 2px solid hsl(var(--ring) / 0.6);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
/* Code block styling */
|
||||
.json-editor-content pre {
|
||||
margin: 0;
|
||||
padding: 1rem 1rem 1rem 0.5rem;
|
||||
background: transparent !important;
|
||||
color: hsl(var(--foreground));
|
||||
overflow-x: auto;
|
||||
white-space: pre;
|
||||
word-wrap: normal;
|
||||
tab-size: 2;
|
||||
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.75;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.json-editor-content pre code {
|
||||
background: transparent !important;
|
||||
padding: 0;
|
||||
font-family: inherit;
|
||||
font-size: inherit;
|
||||
color: inherit;
|
||||
display: block;
|
||||
white-space: pre;
|
||||
word-wrap: normal;
|
||||
min-height: 1.75rem;
|
||||
}
|
||||
|
||||
/* Syntax highlighting for JSON - Light theme */
|
||||
.json-editor-content .hljs-attr {
|
||||
color: #0969da;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.json-editor-content .hljs-string {
|
||||
color: #0a3069;
|
||||
}
|
||||
|
||||
.json-editor-content .hljs-number,
|
||||
.json-editor-content .hljs-literal {
|
||||
color: #0550ae;
|
||||
}
|
||||
|
||||
.json-editor-content .hljs-punctuation {
|
||||
color: hsl(var(--foreground) / 0.7);
|
||||
}
|
||||
|
||||
.json-editor-content .hljs-keyword {
|
||||
color: #cf222e;
|
||||
}
|
||||
|
||||
.json-editor-content .hljs-comment {
|
||||
color: #6e7781;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* Dark mode support - Class-based */
|
||||
.dark .json-editor-content .hljs-attr {
|
||||
color: #79c0ff;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.dark .json-editor-content .hljs-string {
|
||||
color: #a5d6ff;
|
||||
}
|
||||
|
||||
.dark .json-editor-content .hljs-number,
|
||||
.dark .json-editor-content .hljs-literal {
|
||||
color: #79c0ff;
|
||||
}
|
||||
|
||||
.dark .json-editor-content .hljs-punctuation {
|
||||
color: #c9d1d9;
|
||||
}
|
||||
|
||||
.dark .json-editor-content .hljs-keyword {
|
||||
color: #ff7b72;
|
||||
}
|
||||
|
||||
.dark .json-editor-content .hljs-comment {
|
||||
color: #8b949e;
|
||||
}
|
||||
|
||||
/* Dark mode support - Media query */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.json-editor-content .hljs-attr {
|
||||
color: #79c0ff;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.json-editor-content .hljs-string {
|
||||
color: #a5d6ff;
|
||||
}
|
||||
|
||||
.json-editor-content .hljs-number,
|
||||
.json-editor-content .hljs-literal {
|
||||
color: #79c0ff;
|
||||
}
|
||||
|
||||
.json-editor-content .hljs-punctuation {
|
||||
color: #c9d1d9;
|
||||
}
|
||||
|
||||
.json-editor-content .hljs-keyword {
|
||||
color: #ff7b72;
|
||||
}
|
||||
|
||||
.json-editor-content .hljs-comment {
|
||||
color: #8b949e;
|
||||
}
|
||||
}
|
||||
|
||||
92
apps/rowboatx/components/json-editor.tsx
Normal file
92
apps/rowboatx/components/json-editor.tsx
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
"use client";
|
||||
|
||||
import { useEditor, EditorContent } from "@tiptap/react";
|
||||
import { useEffect, useState } from "react";
|
||||
import StarterKit from "@tiptap/starter-kit";
|
||||
import CodeBlockLowlight from "@tiptap/extension-code-block-lowlight";
|
||||
import { common, createLowlight } from "lowlight";
|
||||
import "./json-editor.css";
|
||||
|
||||
const lowlight = createLowlight(common);
|
||||
|
||||
interface JsonEditorProps {
|
||||
content: string;
|
||||
onChange: (content: string) => void;
|
||||
readOnly?: boolean;
|
||||
}
|
||||
|
||||
export function JsonEditor({ content, onChange, readOnly = false }: JsonEditorProps) {
|
||||
const [lineCount, setLineCount] = useState(1);
|
||||
|
||||
const editor = useEditor({
|
||||
extensions: [
|
||||
StarterKit.configure({
|
||||
codeBlock: false, // Disable default code block
|
||||
}),
|
||||
CodeBlockLowlight.configure({
|
||||
lowlight,
|
||||
defaultLanguage: "json",
|
||||
}),
|
||||
],
|
||||
immediatelyRender: false,
|
||||
editable: !readOnly,
|
||||
editorProps: {
|
||||
attributes: {
|
||||
class: "json-editor-content",
|
||||
},
|
||||
},
|
||||
onUpdate: ({ editor }) => {
|
||||
// Extract text content from the code block
|
||||
const text = editor.getText();
|
||||
onChange(text);
|
||||
// Update line count
|
||||
setLineCount(text.split("\n").length || 1);
|
||||
},
|
||||
});
|
||||
|
||||
// Set initial content and update when content prop changes
|
||||
useEffect(() => {
|
||||
if (!editor) return;
|
||||
|
||||
const currentText = editor.getText().trim();
|
||||
if (currentText !== content.trim()) {
|
||||
// Set content using ProseMirror JSON structure
|
||||
editor.commands.setContent({
|
||||
type: "doc",
|
||||
content: [
|
||||
{
|
||||
type: "codeBlock",
|
||||
attrs: {
|
||||
language: "json",
|
||||
},
|
||||
content: content ? [
|
||||
{
|
||||
type: "text",
|
||||
text: content,
|
||||
},
|
||||
] : [],
|
||||
},
|
||||
],
|
||||
});
|
||||
setLineCount(content.split("\n").length || 1);
|
||||
}
|
||||
}, [editor, content]);
|
||||
|
||||
if (!editor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="json-editor-wrapper">
|
||||
<div className="json-editor-line-numbers">
|
||||
{Array.from({ length: lineCount }, (_, i) => (
|
||||
<div key={i} className="json-editor-line-number">
|
||||
{i + 1}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<EditorContent editor={editor} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
141
apps/rowboatx/components/markdown-viewer.css
Normal file
141
apps/rowboatx/components/markdown-viewer.css
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
.markdown-viewer-wrapper {
|
||||
height: 100%;
|
||||
min-height: 240px;
|
||||
max-height: 70vh;
|
||||
overflow: auto;
|
||||
border-radius: 0.375rem;
|
||||
border: 1px solid hsl(var(--border));
|
||||
background: hsl(var(--background));
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.markdown-content {
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.75;
|
||||
color: hsl(var(--foreground));
|
||||
}
|
||||
|
||||
.markdown-content p {
|
||||
margin: 0.75rem 0;
|
||||
}
|
||||
|
||||
.markdown-content p:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.markdown-content p:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.markdown-content h1,
|
||||
.markdown-content h2,
|
||||
.markdown-content h3,
|
||||
.markdown-content h4,
|
||||
.markdown-content h5,
|
||||
.markdown-content h6 {
|
||||
font-weight: 600;
|
||||
margin-top: 1.5rem;
|
||||
margin-bottom: 0.75rem;
|
||||
line-height: 1.25;
|
||||
}
|
||||
|
||||
.markdown-content h1 {
|
||||
font-size: 1.875rem;
|
||||
}
|
||||
|
||||
.markdown-content h2 {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.markdown-content h3 {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.markdown-content ul,
|
||||
.markdown-content ol {
|
||||
margin: 0.75rem 0;
|
||||
padding-left: 1.5rem;
|
||||
}
|
||||
|
||||
.markdown-content li {
|
||||
margin: 0.25rem 0;
|
||||
}
|
||||
|
||||
.markdown-content code {
|
||||
background: hsl(var(--muted));
|
||||
padding: 0.125rem 0.375rem;
|
||||
border-radius: 0.25rem;
|
||||
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
|
||||
font-size: 0.875em;
|
||||
}
|
||||
|
||||
.markdown-content pre {
|
||||
background: hsl(var(--muted));
|
||||
padding: 1rem;
|
||||
border-radius: 0.375rem;
|
||||
overflow-x: auto;
|
||||
margin: 0.75rem 0;
|
||||
}
|
||||
|
||||
.markdown-content pre code {
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.markdown-content blockquote {
|
||||
border-left: 4px solid hsl(var(--border));
|
||||
padding-left: 1rem;
|
||||
margin: 0.75rem 0;
|
||||
color: hsl(var(--muted-foreground));
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.markdown-content a {
|
||||
color: hsl(var(--primary));
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.markdown-content a:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.markdown-content strong {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.markdown-content em {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.markdown-content hr {
|
||||
border: none;
|
||||
border-top: 1px solid hsl(var(--border));
|
||||
margin: 1.5rem 0;
|
||||
}
|
||||
|
||||
.markdown-content table {
|
||||
border-collapse: collapse;
|
||||
margin: 0.75rem 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.markdown-content table th,
|
||||
.markdown-content table td {
|
||||
border: 1px solid hsl(var(--border));
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.markdown-content table th {
|
||||
background: hsl(var(--muted));
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.markdown-content img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
border-radius: 0.375rem;
|
||||
margin: 0.75rem 0;
|
||||
}
|
||||
|
||||
|
||||
21
apps/rowboatx/components/markdown-viewer.tsx
Normal file
21
apps/rowboatx/components/markdown-viewer.tsx
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
"use client";
|
||||
|
||||
import ReactMarkdown from "react-markdown";
|
||||
import remarkGfm from "remark-gfm";
|
||||
import "./markdown-viewer.css";
|
||||
|
||||
interface MarkdownViewerProps {
|
||||
content: string;
|
||||
}
|
||||
|
||||
export function MarkdownViewer({ content }: MarkdownViewerProps) {
|
||||
return (
|
||||
<div className="markdown-viewer-wrapper markdown-content">
|
||||
<ReactMarkdown remarkPlugins={[remarkGfm]}>
|
||||
{content}
|
||||
</ReactMarkdown>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
290
apps/rowboatx/components/tiptap-markdown-editor.css
Normal file
290
apps/rowboatx/components/tiptap-markdown-editor.css
Normal file
|
|
@ -0,0 +1,290 @@
|
|||
.tiptap-markdown-editor {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
padding: 1rem;
|
||||
min-height: 0;
|
||||
width: 100%;
|
||||
border-radius: 16px;
|
||||
border: 1px solid hsl(var(--border));
|
||||
background:
|
||||
radial-gradient(circle at 14% 20%, hsl(var(--primary) / 0.08), transparent 32%),
|
||||
radial-gradient(circle at 86% 10%, hsl(var(--primary) / 0.06), transparent 30%),
|
||||
hsl(var(--background));
|
||||
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
|
||||
min-height: 460px;
|
||||
}
|
||||
|
||||
.tiptap-markdown-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
border-radius: 12px;
|
||||
border: 1px solid hsl(var(--border));
|
||||
background: linear-gradient(120deg, hsl(var(--background)), hsl(var(--muted) / 0.4));
|
||||
backdrop-filter: blur(10px);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.tiptap-toolbar-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.tiptap-toolbar-separator {
|
||||
width: 1px;
|
||||
height: 28px;
|
||||
background: hsl(var(--border));
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
.tiptap-toolbar-button {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
height: 32px;
|
||||
width: 32px;
|
||||
border-radius: 10px;
|
||||
border: 1px solid transparent;
|
||||
background: hsl(var(--muted) / 0.4);
|
||||
color: hsl(var(--foreground));
|
||||
transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
|
||||
}
|
||||
|
||||
.tiptap-toolbar-button:hover:not(:disabled) {
|
||||
border-color: hsl(var(--primary) / 0.65);
|
||||
color: hsl(var(--primary));
|
||||
box-shadow: 0 4px 16px hsl(var(--primary) / 0.2);
|
||||
}
|
||||
|
||||
.tiptap-toolbar-button.is-active {
|
||||
background: hsl(var(--primary) / 0.12);
|
||||
border-color: hsl(var(--primary));
|
||||
color: hsl(var(--primary));
|
||||
}
|
||||
|
||||
.tiptap-toolbar-button:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.tiptap-toolbar-pill {
|
||||
margin-left: auto;
|
||||
padding: 0.35rem 0.65rem;
|
||||
border-radius: 0.65rem;
|
||||
border: 1px solid hsl(var(--border));
|
||||
background: hsl(var(--muted) / 0.4);
|
||||
color: hsl(var(--muted-foreground));
|
||||
font-size: 0.75rem;
|
||||
letter-spacing: 0.01em;
|
||||
}
|
||||
|
||||
.tiptap-editor-pane {
|
||||
border: 1px solid hsl(var(--border));
|
||||
border-radius: 14px;
|
||||
background: linear-gradient(180deg, hsl(var(--background)), hsl(var(--muted) / 0.2));
|
||||
padding: 0.75rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 360px;
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
max-height: 72vh;
|
||||
overflow: auto;
|
||||
position: relative;
|
||||
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
|
||||
}
|
||||
|
||||
.tiptap-editor-surface {
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.tiptap-pane-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.tiptap-pane-title {
|
||||
font-weight: 600;
|
||||
font-size: 0.95rem;
|
||||
letter-spacing: -0.01em;
|
||||
color: hsl(var(--foreground));
|
||||
}
|
||||
|
||||
.tiptap-pane-hint {
|
||||
font-size: 0.8rem;
|
||||
color: hsl(var(--muted-foreground));
|
||||
}
|
||||
|
||||
.tiptap-pill {
|
||||
padding: 0.25rem 0.6rem;
|
||||
border-radius: 999px;
|
||||
background: hsl(var(--primary) / 0.15);
|
||||
color: hsl(var(--primary));
|
||||
border: 1px solid hsl(var(--primary) / 0.4);
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content {
|
||||
flex: 1 1 auto;
|
||||
min-height: 300px;
|
||||
max-height: 100%;
|
||||
width: 100%;
|
||||
padding: 0.35rem 0.35rem 0.75rem;
|
||||
font-size: 0.96rem;
|
||||
line-height: 1.8;
|
||||
color: hsl(var(--foreground));
|
||||
outline: none;
|
||||
background: transparent;
|
||||
max-width: 100%;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
word-break: break-word;
|
||||
overflow-wrap: anywhere;
|
||||
caret-color: hsl(var(--foreground));
|
||||
min-height: 0;
|
||||
overscroll-behavior: contain;
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: hsl(var(--border)) transparent;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.tiptap-editor-surface .tiptap-markdown-editor-content,
|
||||
.tiptap-editor-surface .ProseMirror {
|
||||
height: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content::selection,
|
||||
.tiptap-markdown-editor-content *::selection {
|
||||
background: rgba(99, 102, 241, 0.55);
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content::-webkit-scrollbar-thumb {
|
||||
background: hsl(var(--border));
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content::-webkit-scrollbar-thumb:hover {
|
||||
background: hsl(var(--border) / 0.9);
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content p {
|
||||
margin: 0.35rem 0;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content h1,
|
||||
.tiptap-markdown-editor-content h2,
|
||||
.tiptap-markdown-editor-content h3 {
|
||||
font-weight: 700;
|
||||
line-height: 1.25;
|
||||
margin-top: 1.4rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content h1 {
|
||||
font-size: 1.8rem;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content h2 {
|
||||
font-size: 1.4rem;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content h3 {
|
||||
font-size: 1.15rem;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content strong {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content em {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content ul,
|
||||
.tiptap-markdown-editor-content ol {
|
||||
padding-left: 1.3rem;
|
||||
margin: 0.6rem 0;
|
||||
display: grid;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content li {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content code {
|
||||
background: hsl(var(--muted));
|
||||
padding: 0.15rem 0.35rem;
|
||||
border-radius: 0.35rem;
|
||||
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
|
||||
font-size: 0.9em;
|
||||
color: hsl(var(--foreground));
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content pre {
|
||||
background: #0f172a;
|
||||
color: #e2e8f0;
|
||||
padding: 1rem;
|
||||
border-radius: 12px;
|
||||
overflow-x: auto;
|
||||
margin: 1.1rem 0;
|
||||
border: 1px solid hsl(var(--border));
|
||||
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content pre code {
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
padding: 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content blockquote {
|
||||
border-left: 4px solid hsl(var(--primary));
|
||||
padding-left: 1rem;
|
||||
margin: 1rem 0;
|
||||
color: hsl(var(--muted-foreground));
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content hr {
|
||||
border: none;
|
||||
border-top: 2px solid hsl(var(--border));
|
||||
margin: 1.5rem 0;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content a {
|
||||
color: hsl(var(--primary));
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content a:hover {
|
||||
color: hsl(var(--primary) / 0.9);
|
||||
}
|
||||
|
||||
.tiptap-markdown-editor-content p.is-editor-empty:first-child::before {
|
||||
content: attr(data-placeholder);
|
||||
float: left;
|
||||
color: hsl(var(--muted-foreground));
|
||||
pointer-events: none;
|
||||
height: 0;
|
||||
}
|
||||
262
apps/rowboatx/components/tiptap-markdown-editor.tsx
Normal file
262
apps/rowboatx/components/tiptap-markdown-editor.tsx
Normal file
|
|
@ -0,0 +1,262 @@
|
|||
"use client";
|
||||
|
||||
import { EditorContent, useEditor } from "@tiptap/react";
|
||||
import StarterKit from "@tiptap/starter-kit";
|
||||
import Placeholder from "@tiptap/extension-placeholder";
|
||||
import Link from "@tiptap/extension-link";
|
||||
import { useEffect } from "react";
|
||||
import TurndownService from "turndown";
|
||||
import { marked } from "marked";
|
||||
import {
|
||||
Bold,
|
||||
Code2,
|
||||
Heading1,
|
||||
Heading2,
|
||||
Heading3,
|
||||
Italic,
|
||||
Link2,
|
||||
List,
|
||||
ListOrdered,
|
||||
Minus,
|
||||
Quote,
|
||||
Redo2,
|
||||
Strikethrough,
|
||||
Undo2,
|
||||
} from "lucide-react";
|
||||
import type { LucideIcon } from "lucide-react";
|
||||
import "./tiptap-markdown-editor.css";
|
||||
|
||||
interface TiptapMarkdownEditorProps {
|
||||
content: string;
|
||||
onChange: (content: string) => void;
|
||||
readOnly?: boolean;
|
||||
placeholder?: string;
|
||||
}
|
||||
|
||||
// Configure marked to parse markdown
|
||||
marked.setOptions({
|
||||
gfm: true,
|
||||
breaks: true,
|
||||
});
|
||||
|
||||
// Configure turndown to convert HTML back to markdown
|
||||
const turndownService = new TurndownService({
|
||||
headingStyle: "atx",
|
||||
codeBlockStyle: "fenced",
|
||||
});
|
||||
|
||||
type ToolbarButtonProps = {
|
||||
icon: LucideIcon;
|
||||
label: string;
|
||||
active?: boolean;
|
||||
disabled?: boolean;
|
||||
onClick: () => void;
|
||||
};
|
||||
|
||||
function ToolbarButton({ icon: Icon, label, active, disabled, onClick }: ToolbarButtonProps) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className={`tiptap-toolbar-button ${active ? "is-active" : ""}`}
|
||||
aria-label={label}
|
||||
title={label}
|
||||
disabled={disabled}
|
||||
onClick={onClick}
|
||||
>
|
||||
<Icon size={15} strokeWidth={2.25} />
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
export function TiptapMarkdownEditor({
|
||||
content,
|
||||
onChange,
|
||||
readOnly = false,
|
||||
placeholder = "Start typing...",
|
||||
}: TiptapMarkdownEditorProps) {
|
||||
const editor = useEditor({
|
||||
immediatelyRender: false,
|
||||
content: content ? (marked.parse(content) as string) : "",
|
||||
extensions: [
|
||||
StarterKit.configure({
|
||||
heading: {
|
||||
levels: [1, 2, 3],
|
||||
},
|
||||
codeBlock: {
|
||||
HTMLAttributes: {
|
||||
class: "code-block",
|
||||
},
|
||||
},
|
||||
}),
|
||||
Placeholder.configure({
|
||||
placeholder,
|
||||
emptyEditorClass: "is-editor-empty",
|
||||
}),
|
||||
Link.configure({
|
||||
openOnClick: false,
|
||||
linkOnPaste: true,
|
||||
autolink: true,
|
||||
}),
|
||||
],
|
||||
editorProps: {
|
||||
attributes: {
|
||||
class: "tiptap-markdown-editor-content",
|
||||
},
|
||||
},
|
||||
editable: !readOnly,
|
||||
onUpdate: ({ editor }) => {
|
||||
const html = editor.getHTML();
|
||||
const markdown = turndownService.turndown(html);
|
||||
onChange(markdown);
|
||||
},
|
||||
});
|
||||
|
||||
// Keep editor content in sync when a new artifact is selected
|
||||
useEffect(() => {
|
||||
if (!editor) return;
|
||||
|
||||
const currentMarkdown = turndownService.turndown(editor.getHTML());
|
||||
if ((currentMarkdown || "").trim() === (content || "").trim()) return;
|
||||
|
||||
editor.commands.setContent(content ? (marked.parse(content) as string) : "");
|
||||
}, [editor, content]);
|
||||
|
||||
if (!editor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const handleLink = () => {
|
||||
const previousUrl = editor.getAttributes("link").href as string | undefined;
|
||||
const url = window.prompt("Paste or type a link", previousUrl ?? "");
|
||||
|
||||
if (url === null) return;
|
||||
if (url === "") {
|
||||
editor.chain().focus().unsetLink().run();
|
||||
return;
|
||||
}
|
||||
|
||||
editor.chain().focus().extendMarkRange("link").setLink({ href: url }).run();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="tiptap-markdown-editor">
|
||||
{!readOnly && (
|
||||
<div className="tiptap-markdown-toolbar">
|
||||
<div className="tiptap-toolbar-group">
|
||||
<ToolbarButton
|
||||
icon={Undo2}
|
||||
label="Undo"
|
||||
onClick={() => editor.chain().focus().undo().run()}
|
||||
disabled={!editor.can().undo()}
|
||||
/>
|
||||
<ToolbarButton
|
||||
icon={Redo2}
|
||||
label="Redo"
|
||||
onClick={() => editor.chain().focus().redo().run()}
|
||||
disabled={!editor.can().redo()}
|
||||
/>
|
||||
</div>
|
||||
<div className="tiptap-toolbar-separator" aria-hidden />
|
||||
<div className="tiptap-toolbar-group">
|
||||
<ToolbarButton
|
||||
icon={Bold}
|
||||
label="Bold"
|
||||
active={editor.isActive("bold")}
|
||||
onClick={() => editor.chain().focus().toggleBold().run()}
|
||||
/>
|
||||
<ToolbarButton
|
||||
icon={Italic}
|
||||
label="Italic"
|
||||
active={editor.isActive("italic")}
|
||||
onClick={() => editor.chain().focus().toggleItalic().run()}
|
||||
/>
|
||||
<ToolbarButton
|
||||
icon={Strikethrough}
|
||||
label="Strike"
|
||||
active={editor.isActive("strike")}
|
||||
onClick={() => editor.chain().focus().toggleStrike().run()}
|
||||
/>
|
||||
<ToolbarButton
|
||||
icon={Code2}
|
||||
label="Code"
|
||||
active={editor.isActive("code")}
|
||||
onClick={() => editor.chain().focus().toggleCode().run()}
|
||||
/>
|
||||
</div>
|
||||
<div className="tiptap-toolbar-separator" aria-hidden />
|
||||
<div className="tiptap-toolbar-group">
|
||||
<ToolbarButton
|
||||
icon={Heading1}
|
||||
label="Heading 1"
|
||||
active={editor.isActive("heading", { level: 1 })}
|
||||
onClick={() => editor.chain().focus().toggleHeading({ level: 1 }).run()}
|
||||
/>
|
||||
<ToolbarButton
|
||||
icon={Heading2}
|
||||
label="Heading 2"
|
||||
active={editor.isActive("heading", { level: 2 })}
|
||||
onClick={() => editor.chain().focus().toggleHeading({ level: 2 }).run()}
|
||||
/>
|
||||
<ToolbarButton
|
||||
icon={Heading3}
|
||||
label="Heading 3"
|
||||
active={editor.isActive("heading", { level: 3 })}
|
||||
onClick={() => editor.chain().focus().toggleHeading({ level: 3 }).run()}
|
||||
/>
|
||||
</div>
|
||||
<div className="tiptap-toolbar-separator" aria-hidden />
|
||||
<div className="tiptap-toolbar-group">
|
||||
<ToolbarButton
|
||||
icon={List}
|
||||
label="Bullet list"
|
||||
active={editor.isActive("bulletList")}
|
||||
onClick={() => editor.chain().focus().toggleBulletList().run()}
|
||||
/>
|
||||
<ToolbarButton
|
||||
icon={ListOrdered}
|
||||
label="Numbered list"
|
||||
active={editor.isActive("orderedList")}
|
||||
onClick={() => editor.chain().focus().toggleOrderedList().run()}
|
||||
/>
|
||||
<ToolbarButton
|
||||
icon={Quote}
|
||||
label="Quote"
|
||||
active={editor.isActive("blockquote")}
|
||||
onClick={() => editor.chain().focus().toggleBlockquote().run()}
|
||||
/>
|
||||
<ToolbarButton
|
||||
icon={Code2}
|
||||
label="Code block"
|
||||
active={editor.isActive("codeBlock")}
|
||||
onClick={() => editor.chain().focus().toggleCodeBlock().run()}
|
||||
/>
|
||||
<ToolbarButton
|
||||
icon={Minus}
|
||||
label="Divider"
|
||||
onClick={() => editor.chain().focus().setHorizontalRule().run()}
|
||||
/>
|
||||
</div>
|
||||
<div className="tiptap-toolbar-separator" aria-hidden />
|
||||
<div className="tiptap-toolbar-group">
|
||||
<ToolbarButton
|
||||
icon={Link2}
|
||||
label="Link"
|
||||
active={editor.isActive("link")}
|
||||
onClick={handleLink}
|
||||
/>
|
||||
</div>
|
||||
<div className="tiptap-toolbar-pill">Markdown</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="tiptap-editor-pane">
|
||||
<div className="tiptap-pane-header">
|
||||
<span className="tiptap-pane-title">Editor</span>
|
||||
<span className="tiptap-pane-hint">Markdown + shortcuts</span>
|
||||
</div>
|
||||
<div className="tiptap-editor-surface">
|
||||
<EditorContent editor={editor} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue