Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
feat: novel editor
Brad Barbin5691f7e20836
diff --git a/apps/carbon/app/components/Search/Search/Search.tsx b/apps/carbon/app/components/Search/Search/Search.tsxindex c5cd935d55..e6b153ee17 100644--- a/apps/carbon/app/components/Search/Search/Search.tsx+++ b/apps/carbon/app/components/Search/Search/Search.tsx@@ -9,13 +9,11 @@ import {CommandList,CommandSeparator,HStack,- Kbd,Modal,ModalContent,VStack,useDebounce,useDisclosure,- useKeyboardShortcuts,useMount,} from "@carbon/react";import { useNavigate } from "@remix-run/react";@@ -31,7 +29,9 @@ import { LuSearch } from "react-icons/lu";import { PiShareNetworkFill } from "react-icons/pi";import { RxMagnifyingGlass } from "react-icons/rx";import { useModules } from "~/components/Layout/Navigation/useModules";-import { useUser } from "~/hooks";+import { ShortcutKey } from "~/components/ShortcutKey";+import { useShortcutKeys, useUser } from "~/hooks";+import type { ShortcutDefinition } from "~/hooks/useShortcutKeys";import { useSupabase } from "~/lib/supabase";import { useAccountSubmodules } from "~/modules/account";import { useAccountingSubmodules } from "~/modules/accounting";@@ -55,6 +55,11 @@ type SearchResult = {description: string | null;};+const shortcut: ShortcutDefinition = {+ key: "K",+ modifiers: ["meta"],+};+const SearchModal = ({isOpen,onClose,@@ -265,8 +270,10 @@ function ResultIcon({ entity }: { entity: SearchResult["entity"] | "Module" }) {const SearchButton = () => {const searchModal = useDisclosure();- useKeyboardShortcuts({- "/": searchModal.onOpen,++ useShortcutKeys({+ shortcut: shortcut,+ action: searchModal.onOpen,});return (@@ -279,7 +286,7 @@ const SearchButton = () => {><HStack className="w-full"><div className="flex flex-grow">Search</div>- <Kbd>/</Kbd>+ <ShortcutKey variant="small" shortcut={shortcut} /></HStack></Button><SearchModal isOpen={searchModal.isOpen} onClose={searchModal.onClose} />diff --git a/apps/carbon/app/routes/x+/_layout.tsx b/apps/carbon/app/routes/x+/_layout.tsxindex 8aa3aedd77..c1f014f84a 100644--- a/apps/carbon/app/routes/x+/_layout.tsx+++ b/apps/carbon/app/routes/x+/_layout.tsx@@ -116,11 +116,11 @@ export default function AuthenticatedRoute() {<div className="min-h-full flex flex-col"><div className="flex-none" /><div className="h-screen min-h-[0px] basis-0 flex-1">- <div className="flex h-full ">+ <div className="flex h-full"><IconSidebar /><div className="flex w-full h-full"><div className="w-full h-full flex-1 overflow-hidden">- <main className="h-full flex flex-col flex-1 max-w-[calc(100vw-56px)] overflow-x-hidden bg-muted">+ <main className="h-full flex flex-col flex-1 max-w-[100vw] sm:max-w-[calc(100vw-56px)] overflow-x-hidden bg-muted"><Topbar /><main className="flex-1 overflow-y-auto max-h-[calc(100vh-49px)]"><Outlet />diff --git a/apps/carbon/app/routes/x+/scheduling+/wysiwyg.tsx b/apps/carbon/app/routes/x+/scheduling+/wysiwyg.tsxnew file mode 100644index 0000000000..54f3964628--- /dev/null+++ b/apps/carbon/app/routes/x+/scheduling+/wysiwyg.tsx@@ -0,0 +1,21 @@+import type { JSONContent } from "@carbon/react";+import { Editor } from "@carbon/react";+import { useState } from "react";+import ProseMirror from "~/styles/prosemirror.css?url";++export function links() {+ return [{ rel: "stylesheet", href: ProseMirror }];+}++export default function WysiwygRoute() {+ const [value, setValue] = useState<JSONContent>({+ type: "doc",+ content: [{ type: "paragraph", content: [{ text: "Hello, CarbonOS!" }] }],+ });++ return (+ <div className="flex flex-col h-full max-h-full overflow-auto relative">+ <Editor initialValue={value} onChange={setValue} />+ </div>+ );+}diff --git a/apps/carbon/app/styles/prosemirror.css b/apps/carbon/app/styles/prosemirror.cssnew file mode 100644index 0000000000..b43444bb3f--- /dev/null+++ b/apps/carbon/app/styles/prosemirror.css@@ -0,0 +1,166 @@+.ProseMirror .is-editor-empty:first-child::before {+ content: attr(data-placeholder);+ float: left;+ color: hsl(var(--muted-foreground));+ pointer-events: none;+ height: 0;+}+.ProseMirror .is-empty::before {+ content: attr(data-placeholder);+ float: left;+ color: hsl(var(--muted-foreground));+ pointer-events: none;+ height: 0;+}++/* Custom image styles */++.ProseMirror img {+ transition: filter 0.1s ease-in-out;++ &:hover {+ cursor: pointer;+ filter: brightness(90%);+ }++ &.ProseMirror-selectednode {+ outline: 3px solid #5abbf7;+ filter: brightness(90%);+ }+}++.img-placeholder {+ position: relative;++ &:before {+ content: "";+ box-sizing: border-box;+ position: absolute;+ top: 50%;+ left: 50%;+ width: 36px;+ height: 36px;+ border-radius: 50%;+ border: 3px solid var(--novel-stone-200);+ border-top-color: var(--novel-stone-800);+ animation: spinning 0.6s linear infinite;+ }+}++@keyframes spinning {+ to {+ transform: rotate(360deg);+ }+}++/* Custom TODO list checkboxes – shoutout to this awesome tutorial: https://moderncss.dev/pure-css-custom-checkbox-style/ */++ul[data-type="taskList"] li > label {+ margin-right: 0.2rem;+ user-select: none;+}++@media screen and (max-width: 768px) {+ ul[data-type="taskList"] li > label {+ margin-right: 0.5rem;+ }+}++ul[data-type="taskList"] li > label input[type="checkbox"] {+ -webkit-appearance: none;+ appearance: none;+ background-color: hsl(var(--background));+ margin: 0;+ cursor: pointer;+ width: 1.2em;+ height: 1.2em;+ position: relative;+ top: 5px;+ border: 2px solid hsl(var(--border));+ margin-right: 0.3rem;+ display: grid;+ place-content: center;++ &:hover {+ background-color: hsl(var(--accent));+ }++ &:active {+ background-color: hsl(var(--accent));+ }++ &::before {+ content: "";+ width: 0.65em;+ height: 0.65em;+ transform: scale(0);+ transition: 120ms transform ease-in-out;+ box-shadow: inset 1em 1em;+ transform-origin: center;+ clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);+ }++ &:checked::before {+ transform: scale(1);+ }+}++ul[data-type="taskList"] li[data-checked="true"] > div > p {+ color: var(--muted-foreground);+ text-decoration: line-through;+ text-decoration-thickness: 2px;+}++/* Overwrite tippy-box original max-width */++.tippy-box {+ max-width: 400px !important;+}++.ProseMirror:not(.dragging) .ProseMirror-selectednode {+ outline: none !important;+ background-color: var(--novel-highlight-blue);+ transition: background-color 0.2s;+ box-shadow: none;+}++.drag-handle {+ position: fixed;+ opacity: 1;+ transition: opacity ease-in 0.2s;+ border-radius: 0.25rem;++ background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10' style='fill: rgba(0, 0, 0, 0.5)'%3E%3Cpath d='M3,2 C2.44771525,2 2,1.55228475 2,1 C2,0.44771525 2.44771525,0 3,0 C3.55228475,0 4,0.44771525 4,1 C4,1.55228475 3.55228475,2 3,2 Z M3,6 C2.44771525,6 2,5.55228475 2,5 C2,4.44771525 2.44771525,4 3,4 C3.55228475,4 4,4.44771525 4,5 C4,5.55228475 3.55228475,6 3,6 Z M3,10 C2.44771525,10 2,9.55228475 2,9 C2,8.44771525 2.44771525,8 3,8 C3.55228475,8 4,8.44771525 4,9 C4,9.55228475 3.55228475,10 3,10 Z M7,2 C6.44771525,2 6,1.55228475 6,1 C6,0.44771525 6.44771525,0 7,0 C7.55228475,0 8,0.44771525 8,1 C8,1.55228475 7.55228475,2 7,2 Z M7,6 C6.44771525,6 6,5.55228475 6,5 C6,4.44771525 6.44771525,4 7,4 C7.55228475,4 8,4.44771525 8,5 C8,5.55228475 7.55228475,6 7,6 Z M7,10 C6.44771525,10 6,9.55228475 6,9 C6,8.44771525 6.44771525,8 7,8 C7.55228475,8 8,8.44771525 8,9 C8,9.55228475 7.55228475,10 7,10 Z'%3E%3C/path%3E%3C/svg%3E");+ background-size: calc(0.5em + 0.375rem) calc(0.5em + 0.375rem);+ background-repeat: no-repeat;+ background-position: center;+ width: 1.2rem;+ height: 1.5rem;+ z-index: 50;+ cursor: grab;++ &:hover {+ background-color: var(--novel-stone-100);+ transition: background-color 0.2s;+ }++ &:active {+ background-color: var(--novel-stone-200);+ transition: background-color 0.2s;+ cursor: grabbing;+ }++ &.hide {+ opacity: 0;+ pointer-events: none;+ }++ @media screen and (max-width: 600px) {+ display: none;+ pointer-events: none;+ }+}++.dark .drag-handle {+ background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10' style='fill: rgba(255, 255, 255, 0.5)'%3E%3Cpath d='M3,2 C2.44771525,2 2,1.55228475 2,1 C2,0.44771525 2.44771525,0 3,0 C3.55228475,0 4,0.44771525 4,1 C4,1.55228475 3.55228475,2 3,2 Z M3,6 C2.44771525,6 2,5.55228475 2,5 C2,4.44771525 2.44771525,4 3,4 C3.55228475,4 4,4.44771525 4,5 C4,5.55228475 3.55228475,6 3,6 Z M3,10 C2.44771525,10 2,9.55228475 2,9 C2,8.44771525 2.44771525,8 3,8 C3.55228475,8 4,8.44771525 4,9 C4,9.55228475 3.55228475,10 3,10 Z M7,2 C6.44771525,2 6,1.55228475 6,1 C6,0.44771525 6.44771525,0 7,0 C7.55228475,0 8,0.44771525 8,1 C8,1.55228475 7.55228475,2 7,2 Z M7,6 C6.44771525,6 6,5.55228475 6,5 C6,4.44771525 6.44771525,4 7,4 C7.55228475,4 8,4.44771525 8,5 C8,5.55228475 7.55228475,6 7,6 Z M7,10 C6.44771525,10 6,9.55228475 6,9 C6,8.44771525 6.44771525,8 7,8 C7.55228475,8 8,8.44771525 8,9 C8,9.55228475 7.55228475,10 7,10 Z'%3E%3C/path%3E%3C/svg%3E");+}diff --git a/packages/react/src/Editor/Editor.tsx b/packages/react/src/Editor/Editor.tsxnew file mode 100644index 0000000000..272147fe42--- /dev/null+++ b/packages/react/src/Editor/Editor.tsx@@ -0,0 +1,156 @@+"use client";++import type { JSONContent } from "novel";+import {+ EditorBubble,+ EditorCommand,+ EditorCommandEmpty,+ EditorCommandItem,+ EditorCommandList,+ EditorContent,+ EditorRoot,+} from "novel";+import {+ Command,+ ImageResizer,+ handleCommandNavigation,+ renderItems,+} from "novel/extensions";+import {+ createImageUpload,+ handleImageDrop,+ handleImagePaste,+} from "novel/plugins";+import { useMemo, useState } from "react";+import { toast } from "sonner";+import { Separator } from "../Separator";+import { ColorSelector } from "./components/ColorSelector";+import { LinkSelector } from "./components/LinkSelector";+import { NodeSelector } from "./components/NodeSelector";+import { TextButtons } from "./components/TextButton";+import { defaultExtensions } from "./extensions";+import { getSuggestionItems } from "./slash";++interface EditorProp {+ initialValue?: JSONContent;+ onChange: (value: JSONContent) => void;+ onUpload?: (file: File) => Promise<string>;+}++const defaultOnUpload = async (file: File) => {+ alert(+ "onUpload is not implemented. Please pass an onUpload function to the Editor. Trying to upload " ++ file.name+ );+};++const Editor = ({ initialValue, onChange, onUpload }: EditorProp) => {+ const [openNode, setOpenNode] = useState(false);+ const [openColor, setOpenColor] = useState(false);+ const [openLink, setOpenLink] = useState(false);++ const uploadFn = useMemo(() => {+ const uploadHandler = onUpload ? onUpload : defaultOnUpload;+ return createImageUpload({+ onUpload: uploadHandler,+ validateFn: (file) => {+ if (!file.type.includes("image/")) {+ toast.error("File type not supported.");+ return false;+ } else if (file.size / 1024 / 1024 > 20) {+ toast.error("File size too big (max 20MB).");+ return false;+ }+ return true;+ },+ });+ }, [onUpload]);++ const suggestionItems = useMemo(+ () => getSuggestionItems(uploadFn),+ [uploadFn]+ );++ const extensions = useMemo(+ () => [+ ...defaultExtensions,+ Command.configure({+ suggestion: {+ items: () => suggestionItems,+ render: renderItems,+ },+ }),+ ],+ [suggestionItems]+ );++ return (+ <EditorRoot>+ <EditorContent+ className="border border-border w-full h-full p-4"+ {...(initialValue && { initialContent: initialValue })}+ extensions={extensions}+ editorProps={{+ handleDOMEvents: {+ keydown: (_view, event) => handleCommandNavigation(event),+ },+ handlePaste: (view, event) => handleImagePaste(view, event, uploadFn),+ handleDrop: (view, event, _slice, moved) =>+ handleImageDrop(view, event, moved, uploadFn),+ attributes: {+ class: `prose prose-lg dark:prose-invert focus:outline-none max-w-full`,+ },+ }}+ onUpdate={({ editor }) => {+ onChange(editor.getJSON());+ }}+ slotAfter={<ImageResizer />}+ >+ <EditorCommand className="z-50 h-auto max-h-[330px] overflow-y-auto rounded-md border border-muted bg-background px-1 py-2 shadow-md transition-all">+ <EditorCommandEmpty className="px-2 text-muted-foreground">+ No results+ </EditorCommandEmpty>+ <EditorCommandList>+ {suggestionItems.map((item) => (+ <EditorCommandItem+ value={item.title}+ onCommand={(val) => item.command?.(val)}+ className={`flex w-full items-center space-x-2 rounded-md px-2 py-1 text-left text-sm hover:bg-accent aria-selected:bg-accent `}+ key={item.title}+ >+ <div className="flex h-10 w-10 items-center justify-center rounded-md border border-muted bg-background">+ {item.icon}+ </div>+ <div>+ <p className="font-medium">{item.title}</p>+ <p className="text-xs text-muted-foreground">+ {item.description}+ </p>+ </div>+ </EditorCommandItem>+ ))}+ </EditorCommandList>+ </EditorCommand>++ <EditorBubble+ tippyOptions={{+ placement: "top",+ }}+ className="flex w-fit max-w-[90vw] overflow-hidden rounded-md border border-muted bg-background shadow-xl p-2"+ >+ <Separator orientation="vertical" />+ <NodeSelector open={openNode} onOpenChange={setOpenNode} />+ <Separator orientation="vertical" />++ <LinkSelector open={openLink} onOpenChange={setOpenLink} />+ <Separator orientation="vertical" />+ <TextButtons />+ <Separator orientation="vertical" />+ <ColorSelector open={openColor} onOpenChange={setOpenColor} />+ </EditorBubble>+ </EditorContent>+ </EditorRoot>+ );+};++export default Editor;diff --git a/packages/react/src/Editor/components/ColorSelector.tsx b/packages/react/src/Editor/components/ColorSelector.tsxnew file mode 100644index 0000000000..ac36c50e31--- /dev/null+++ b/packages/react/src/Editor/components/ColorSelector.tsx@@ -0,0 +1,189 @@+import { EditorBubbleItem, useEditor } from "novel";+import { LuCheck, LuChevronDown } from "react-icons/lu";+import { RiPaintFill } from "react-icons/ri";++import { Button } from "../../Button";+import { Popover, PopoverContent, PopoverTrigger } from "../../Popover";++export interface BubbleColorMenuItem {+ name: string;+ color: string;+}++const TEXT_COLORS: BubbleColorMenuItem[] = [+ {+ name: "Default",+ color: "var(--novel-black)",+ },+ {+ name: "Purple",+ color: "#9333EA",+ },+ {+ name: "Red",+ color: "#E00000",+ },+ {+ name: "Yellow",+ color: "#EAB308",+ },+ {+ name: "Blue",+ color: "#2563EB",+ },+ {+ name: "Green",+ color: "#008A00",+ },+ {+ name: "Orange",+ color: "#FFA500",+ },+ {+ name: "Pink",+ color: "#BA4081",+ },+ {+ name: "Gray",+ color: "#A8A29E",+ },+];++const HIGHLIGHT_COLORS: BubbleColorMenuItem[] = [+ {+ name: "Default",+ color: "var(--novel-highlight-default)",+ },+ {+ name: "Purple",+ color: "var(--novel-highlight-purple)",+ },+ {+ name: "Red",+ color: "var(--novel-highlight-red)",+ },+ {+ name: "Yellow",+ color: "var(--novel-highlight-yellow)",+ },+ {+ name: "Blue",+ color: "var(--novel-highlight-blue)",+ },+ {+ name: "Green",+ color: "var(--novel-highlight-green)",+ },+ {+ name: "Orange",+ color: "var(--novel-highlight-orange)",+ },+ {+ name: "Pink",+ color: "var(--novel-highlight-pink)",+ },+ {+ name: "Gray",+ color: "var(--novel-highlight-gray)",+ },+];++interface ColorSelectorProps {+ open: boolean;+ onOpenChange: (open: boolean) => void;+}++export const ColorSelector = ({ open, onOpenChange }: ColorSelectorProps) => {+ const { editor } = useEditor();++ if (!editor) return null;+ const activeColorItem = TEXT_COLORS.find(({ color }) =>+ editor.isActive("textStyle", { color })+ );++ const activeHighlightItem = HIGHLIGHT_COLORS.find(({ color }) =>+ editor.isActive("highlight", { color })+ );++ return (+ <Popover modal={true} open={open} onOpenChange={onOpenChange}>+ <PopoverTrigger asChild>+ <Button+ variant="ghost"+ rightIcon={<LuChevronDown className="h-4 w-4" />}+ style={{+ color: activeColorItem?.color,+ backgroundColor: activeHighlightItem?.color,+ }}+ >+ <RiPaintFill />+ </Button>+ </PopoverTrigger>++ <PopoverContent+ sideOffset={5}+ className="my-1 flex max-h-80 w-48 flex-col overflow-hidden overflow-y-auto rounded border p-1 shadow-xl "+ align="start"+ >+ <div className="flex flex-col">+ <div className="my-1 px-2 text-sm font-semibold text-muted-foreground">+ Color+ </div>+ {TEXT_COLORS.map(({ name, color }, index) => (+ <EditorBubbleItem+ key={index}+ onSelect={() => {+ editor.commands.unsetColor();+ name !== "Default" &&+ editor+ .chain()+ .focus()+ .setColor(color || "")+ .run();+ }}+ className="flex cursor-pointer items-center justify-between px-2 py-1 text-sm hover:bg-accent"+ >+ <div className="flex items-center gap-2">+ <div+ className="rounded-sm border px-2 py-px font-medium"+ style={{ color }}+ >+ A+ </div>+ <span>{name}</span>+ </div>+ </EditorBubbleItem>+ ))}+ </div>+ <div>+ <div className="my-1 px-2 text-sm font-semibold text-muted-foreground">+ Background+ </div>+ {HIGHLIGHT_COLORS.map(({ name, color }, index) => (+ <EditorBubbleItem+ key={index}+ onSelect={() => {+ editor.commands.unsetHighlight();+ name !== "Default" && editor.commands.setHighlight({ color });+ }}+ className="flex cursor-pointer items-center justify-between px-2 py-1 text-sm hover:bg-accent"+ >+ <div className="flex items-center gap-2">+ <div+ className="rounded-sm border px-2 py-px font-medium"+ style={{ backgroundColor: color }}+ >+ A+ </div>+ <span>{name}</span>+ </div>+ {editor.isActive("highlight", { color }) && (+ <LuCheck className="h-4 w-4" />+ )}+ </EditorBubbleItem>+ ))}+ </div>+ </PopoverContent>+ </Popover>+ );+};diff --git a/packages/react/src/Editor/components/LinkSelector.tsx b/packages/react/src/Editor/components/LinkSelector.tsxnew file mode 100644index 0000000000..43877dc1c5--- /dev/null+++ b/packages/react/src/Editor/components/LinkSelector.tsx@@ -0,0 +1,83 @@+import { useEditor } from "novel";+import { useEffect, useRef } from "react";+import { LuCheck, LuLink, LuTrash } from "react-icons/lu";+import { IconButton } from "../../IconButton";+import { Popover, PopoverContent, PopoverTrigger } from "../../Popover";++export function isValidUrl(url: string) {+ try {+ new URL(url);+ return true;+ } catch (e) {+ return false;+ }+}+export function getUrlFromString(str: string) {+ if (isValidUrl(str)) return str;+ try {+ if (str.includes(".") && !str.includes(" ")) {+ return new URL(`https://${str}`).toString();+ }+ } catch (e) {+ return null;+ }+}+interface LinkSelectorProps {+ open: boolean;+ onOpenChange: (open: boolean) => void;+}++export const LinkSelector = ({ open, onOpenChange }: LinkSelectorProps) => {+ const inputRef = useRef<HTMLInputElement>(null);+ const { editor } = useEditor();++ // Autofocus on input by default+ useEffect(() => {+ inputRef.current && inputRef.current?.focus();+ });+ if (!editor) return null;++ return (+ <Popover modal={true} open={open} onOpenChange={onOpenChange}>+ <PopoverTrigger asChild>+ <IconButton aria-label="Link" icon={<LuLink />} variant="ghost" />+ </PopoverTrigger>+ <PopoverContent align="start" className="w-60 p-0" sideOffset={10}>+ <form+ onSubmit={(e) => {+ const target = e.currentTarget as HTMLFormElement;+ e.preventDefault();+ const input = target[0] as HTMLInputElement;+ const url = getUrlFromString(input.value);+ url && editor.chain().focus().setLink({ href: url }).run();+ }}+ className="flex p-1 "+ >+ <input+ ref={inputRef}+ type="text"+ placeholder="Paste a link"+ className="flex-1 bg-background p-1 text-sm outline-none"+ defaultValue={editor.getAttributes("link").href || ""}+ />+ {editor.getAttributes("link").href ? (+ <IconButton+ aria-label="Remove link"+ icon={<LuTrash className="h-4 w-4" />}+ variant="secondary"+ type="button"+ className="flex h-8 items-center rounded-sm p-1 text-red-600 transition-all hover:bg-red-100 dark:hover:bg-red-800"+ onClick={() => {+ editor.chain().focus().unsetLink().run();+ }}+ />+ ) : (+ <span className="h-8">+ <IconButton icon={<LuCheck />} aria-label="Linked" />+ </span>+ )}+ </form>+ </PopoverContent>+ </Popover>+ );+};diff --git a/packages/react/src/Editor/components/NodeSelector.tsx b/packages/react/src/Editor/components/NodeSelector.tsxnew file mode 100644index 0000000000..74879b285f--- /dev/null+++ b/packages/react/src/Editor/components/NodeSelector.tsx@@ -0,0 +1,138 @@+import type { EditorInstance } from "novel";+import { EditorBubbleItem, useEditor } from "novel";+import type { IconType } from "react-icons";+import {+ LuCheck,+ LuCheckSquare,+ LuChevronDown,+ LuCode,+ LuHeading1,+ LuHeading2,+ LuHeading3,+ LuListOrdered,+ LuText,+ LuTextQuote,+} from "react-icons/lu";++import { Popover } from "@radix-ui/react-popover";+import { Button } from "../../Button";+import { PopoverContent, PopoverTrigger } from "../../Popover";++export type SelectorItem = {+ name: string;+ icon: IconType;+ command: (editor: EditorInstance) => void;+ isActive: (editor: EditorInstance) => boolean;+};++const items: SelectorItem[] = [+ {+ name: "Text",+ icon: LuText,+ command: (editor) => editor.chain().focus().clearNodes().run(),+ // I feel like there has to be a more efficient way to do this – feel free to PR if you know how!+ isActive: (editor) =>+ editor.isActive("paragraph") &&+ !editor.isActive("bulletList") &&+ !editor.isActive("orderedList"),+ },+ {+ name: "Heading 1",+ icon: LuHeading1,+ command: (editor) =>+ editor.chain().focus().clearNodes().toggleHeading({ level: 1 }).run(),+ isActive: (editor) => editor.isActive("heading", { level: 1 }),+ },+ {+ name: "Heading 2",+ icon: LuHeading2,+ command: (editor) =>+ editor.chain().focus().clearNodes().toggleHeading({ level: 2 }).run(),+ isActive: (editor) => editor.isActive("heading", { level: 2 }),+ },+ {+ name: "Heading 3",+ icon: LuHeading3,+ command: (editor) =>+ editor.chain().focus().clearNodes().toggleHeading({ level: 3 }).run(),+ isActive: (editor) => editor.isActive("heading", { level: 3 }),+ },+ {+ name: "To-do List",+ icon: LuCheckSquare,+ command: (editor) =>+ editor.chain().focus().clearNodes().toggleTaskList().run(),+ isActive: (editor) => editor.isActive("taskItem"),+ },+ {+ name: "Bullet List",+ icon: LuListOrdered,+ command: (editor) =>+ editor.chain().focus().clearNodes().toggleBulletList().run(),+ isActive: (editor) => editor.isActive("bulletList"),+ },+ {+ name: "Numbered List",+ icon: LuListOrdered,+ command: (editor) =>+ editor.chain().focus().clearNodes().toggleOrderedList().run(),+ isActive: (editor) => editor.isActive("orderedList"),+ },+ {+ name: "Quote",+ icon: LuTextQuote,+ command: (editor) =>+ editor.chain().focus().clearNodes().toggleBlockquote().run(),+ isActive: (editor) => editor.isActive("blockquote"),+ },+ {+ name: "Code",+ icon: LuCode,+ command: (editor) =>+ editor.chain().focus().clearNodes().toggleCodeBlock().run(),+ isActive: (editor) => editor.isActive("codeBlock"),+ },+];+interface NodeSelectorProps {+ open: boolean;+ onOpenChange: (open: boolean) => void;+}++export const NodeSelector = ({ open, onOpenChange }: NodeSelectorProps) => {+ const { editor } = useEditor();+ if (!editor) return null;++ const activeItem = items.filter((item) => item.isActive(editor)).pop() ?? {+ name: "Multiple",+ };++ return (+ <Popover modal={true} open={open} onOpenChange={onOpenChange}>+ <PopoverTrigger asChild>+ <Button variant="ghost" rightIcon={<LuChevronDown />}>+ {activeItem.name}+ </Button>+ </PopoverTrigger>+ <PopoverContent sideOffset={5} align="start" className="w-48 p-1">+ {items.map((item, index) => (+ <EditorBubbleItem+ key={index}+ onSelect={(editor) => {+ item.command(editor);+ onOpenChange(false);+ }}+ className="flex cursor-pointer items-center justify-between rounded-sm px-2 py-1 text-sm hover:bg-accent"+ >+ <div className="flex items-center space-x-2">+ <div className="rounded-sm border p-1">+ <item.icon className="h-3 w-3" />+ </div>+ <span>{item.name}</span>+ </div>+ {activeItem.name === item.name && <LuCheck className="h-4 w-4" />}+ </EditorBubbleItem>+ ))}+ </PopoverContent>+ </Popover>+ );+};diff --git a/packages/react/src/Editor/components/TextButton.tsx b/packages/react/src/Editor/components/TextButton.tsxnew file mode 100644index 0000000000..ac76e988ab--- /dev/null+++ b/packages/react/src/Editor/components/TextButton.tsx@@ -0,0 +1,68 @@+import { EditorBubbleItem, useEditor } from "novel";+import {+ BsCodeSlash,+ BsTypeBold,+ BsTypeItalic,+ BsTypeStrikethrough,+ BsTypeUnderline,+} from "react-icons/bs";++import { IconButton } from "../../IconButton";+import type { SelectorItem } from "./NodeSelector";++export const TextButtons = () => {+ const { editor } = useEditor();+ if (!editor) return null;++ const items: SelectorItem[] = [+ {+ name: "bold",+ isActive: (editor) => editor.isActive("bold"),+ command: (editor) => editor.chain().focus().toggleBold().run(),+ icon: BsTypeBold,+ },+ {+ name: "italic",+ isActive: (editor) => editor.isActive("italic"),+ command: (editor) => editor.chain().focus().toggleItalic().run(),+ icon: BsTypeItalic,+ },+ {+ name: "underline",+ isActive: (editor) => editor.isActive("underline"),+ command: (editor) => editor.chain().focus().toggleUnderline().run(),+ icon: BsTypeUnderline,+ },+ {+ name: "strike",+ isActive: (editor) => editor.isActive("strike"),+ command: (editor) => editor.chain().focus().toggleStrike().run(),+ icon: BsTypeStrikethrough,+ },+ {+ name: "code",+ isActive: (editor) => editor.isActive("code"),+ command: (editor) => editor.chain().focus().toggleCode().run(),+ icon: BsCodeSlash,+ },+ ];++ return (+ <div className="flex">+ {items.map((item, index) => (+ <EditorBubbleItem+ key={index}+ onSelect={(editor) => {+ item.command(editor);+ }}+ >+ <IconButton+ aria-label={item.name}+ icon={<item.icon />}+ variant={item.isActive(editor) ? "active" : "ghost"}+ />+ </EditorBubbleItem>+ ))}+ </div>+ );+};diff --git a/packages/react/src/Editor/extensions.ts b/packages/react/src/Editor/extensions.tsnew file mode 100644index 0000000000..18ef8e38b0--- /dev/null+++ b/packages/react/src/Editor/extensions.ts@@ -0,0 +1,117 @@+import {+ AIHighlight,+ HorizontalRule,+ Placeholder,+ StarterKit,+ TaskItem,+ TaskList,+ TiptapImage,+ TiptapLink,+ UpdatedImage,+} from "novel/extensions";+import { UploadImagesPlugin } from "novel/plugins";++import { cx } from "class-variance-authority";++const aiHighlight = AIHighlight;+const placeholder = Placeholder;+const tiptapLink = TiptapLink.configure({+ HTMLAttributes: {+ class: cx(+ "text-muted-foreground underline underline-offset-[3px] hover:text-primary transition-colors cursor-pointer"+ ),+ },+});++const tiptapImage = TiptapImage.extend({+ addProseMirrorPlugins() {+ return [+ UploadImagesPlugin({+ imageClass: cx("opacity-40 rounded-lg border border-stone-200"),+ }),+ ];+ },+}).configure({+ allowBase64: true,+ HTMLAttributes: {+ class: cx("rounded-lg border border-muted"),+ },+});++const updatedImage = UpdatedImage.configure({+ HTMLAttributes: {+ class: cx("rounded-lg border border-muted"),+ },+});++const taskList = TaskList.configure({+ HTMLAttributes: {+ class: cx("not-prose pl-2 "),+ },+});+const taskItem = TaskItem.configure({+ HTMLAttributes: {+ class: cx("flex gap-2 items-start my-4"),+ },+ nested: true,+});++const horizontalRule = HorizontalRule.configure({+ HTMLAttributes: {+ class: cx("mt-4 mb-6 border-t border-muted-foreground"),+ },+});++const starterKit = StarterKit.configure({+ bulletList: {+ HTMLAttributes: {+ class: cx("list-disc list-outside leading-3 -mt-2"),+ },+ },+ orderedList: {+ HTMLAttributes: {+ class: cx("list-decimal list-outside leading-3 -mt-2"),+ },+ },+ listItem: {+ HTMLAttributes: {+ class: cx("leading-normal -mb-2"),+ },+ },+ blockquote: {+ HTMLAttributes: {+ class: cx("border-l-4 border-primary"),+ },+ },+ codeBlock: {+ HTMLAttributes: {+ class: cx(+ "rounded-md bg-muted text-muted-foreground border p-5 font-mono font-medium"+ ),+ },+ },+ code: {+ HTMLAttributes: {+ class: cx("rounded-md bg-muted px-1.5 py-1 font-mono font-medium"),+ spellcheck: "false",+ },+ },+ horizontalRule: false,+ dropcursor: {+ color: "#DBEAFE",+ width: 4,+ },+ gapcursor: false,+});++export const defaultExtensions = [+ starterKit,+ placeholder,+ tiptapLink,+ tiptapImage,+ updatedImage,+ taskList,+ taskItem,+ horizontalRule,+ aiHighlight,+];diff --git a/packages/react/src/Editor/index.ts b/packages/react/src/Editor/index.tsnew file mode 100644index 0000000000..7c3c23e9c9--- /dev/null+++ b/packages/react/src/Editor/index.ts@@ -0,0 +1,3 @@+import Editor from "./Editor";++export { Editor };diff --git a/packages/react/src/Editor/slash.tsx b/packages/react/src/Editor/slash.tsxnew file mode 100644index 0000000000..c757e526d2--- /dev/null+++ b/packages/react/src/Editor/slash.tsx@@ -0,0 +1,157 @@+import type { EditorView } from "@tiptap/pm/view";+import { createSuggestionItems } from "novel/extensions";+import {+ LuCheckSquare,+ LuCode,+ LuHeading1,+ LuHeading2,+ LuHeading3,+ LuImage,+ LuList,+ LuListOrdered,+ LuMessageSquarePlus,+ LuText,+ LuTextQuote,+} from "react-icons/lu";++export const getSuggestionItems = (+ uploadFn: (file: File, view: EditorView, pos: number) => void+) => {+ return createSuggestionItems([+ {+ title: "Send Feedback",+ description: "Let us know how we can improve.",+ icon: <LuMessageSquarePlus size={18} />,+ command: ({ editor, range }) => {+ editor.chain().focus().deleteRange(range).run();+ window.open("/feedback", "_blank");+ },+ },+ {+ title: "Text",+ description: "Just start typing with plain text.",+ searchTerms: ["p", "paragraph"],+ icon: <LuText size={18} />,+ command: ({ editor, range }) => {+ editor+ .chain()+ .focus()+ .deleteRange(range)+ .toggleNode("paragraph", "paragraph")+ .run();+ },+ },+ {+ title: "To-do List",+ description: "Track tasks with a to-do list.",+ searchTerms: ["todo", "task", "list", "check", "checkbox"],+ icon: <LuCheckSquare size={18} />,+ command: ({ editor, range }) => {+ editor.chain().focus().deleteRange(range).toggleTaskList().run();+ },+ },+ {+ title: "Heading 1",+ description: "Big section heading.",+ searchTerms: ["title", "big", "large"],+ icon: <LuHeading1 size={18} />,+ command: ({ editor, range }) => {+ editor+ .chain()+ .focus()+ .deleteRange(range)+ .setNode("heading", { level: 1 })+ .run();+ },+ },+ {+ title: "Heading 2",+ description: "Medium section heading.",+ searchTerms: ["subtitle", "medium"],+ icon: <LuHeading2 size={18} />,+ command: ({ editor, range }) => {+ editor+ .chain()+ .focus()+ .deleteRange(range)+ .setNode("heading", { level: 2 })+ .run();+ },+ },+ {+ title: "Heading 3",+ description: "Small section heading.",+ searchTerms: ["subtitle", "small"],+ icon: <LuHeading3 size={18} />,+ command: ({ editor, range }) => {+ editor+ .chain()+ .focus()+ .deleteRange(range)+ .setNode("heading", { level: 3 })+ .run();+ },+ },+ {+ title: "Bullet List",+ description: "Create a simple bullet list.",+ searchTerms: ["unordered", "point"],+ icon: <LuList size={18} />,+ command: ({ editor, range }) => {+ editor.chain().focus().deleteRange(range).toggleBulletList().run();+ },+ },+ {+ title: "Numbered List",+ description: "Create a list with numbering.",+ searchTerms: ["ordered"],+ icon: <LuListOrdered size={18} />,+ command: ({ editor, range }) => {+ editor.chain().focus().deleteRange(range).toggleOrderedList().run();+ },+ },+ {+ title: "Quote",+ description: "Capture a quote.",+ searchTerms: ["blockquote"],+ icon: <LuTextQuote size={18} />,+ command: ({ editor, range }) =>+ editor+ .chain()+ .focus()+ .deleteRange(range)+ .toggleNode("paragraph", "paragraph")+ .toggleBlockquote()+ .run(),+ },+ {+ title: "Code",+ description: "Capture a code snippet.",+ searchTerms: ["codeblock"],+ icon: <LuCode size={18} />,+ command: ({ editor, range }) =>+ editor.chain().focus().deleteRange(range).toggleCodeBlock().run(),+ },+ {+ title: "Image",+ description: "Upload an image from your computer.",+ searchTerms: ["photo", "picture", "media"],+ icon: <LuImage size={18} />,+ command: ({ editor, range }) => {+ editor.chain().focus().deleteRange(range).run();+ // upload image+ const input = document.createElement("input");+ input.type = "file";+ input.accept = "image/*";+ input.onchange = async () => {+ if (input.files?.length) {+ const file = input.files[0];+ const pos = editor.view.state.selection.from;+ uploadFn(file, editor.view, pos);+ }+ };+ input.click();+ },+ },+ ]);+};diff --git a/packages/react/src/RichText/Toolbar/BlockQuote.tsx b/packages/react/src/RichText/Toolbar/BlockQuote.tsxindex f870496e9f..458daaf3ab 100644--- a/packages/react/src/RichText/Toolbar/BlockQuote.tsx+++ b/packages/react/src/RichText/Toolbar/BlockQuote.tsx@@ -1,4 +1,4 @@-import { GoQuote } from "react-icons/go";+import { LuQuote } from "react-icons/lu";import type { EditorComponent } from "../types";import ToolbarButton from "./ToolbarButton";@@ -8,7 +8,7 @@ const BlockQuote: EditorComponent = ({ editor }) => {label="Blockquote"onClick={() => editor.chain().focus().toggleBlockquote().run()}isActive={editor.isActive("blockquote")}- icon={<GoQuote />}+ icon={<LuQuote />}disabled={!editor.isEditable}/>);diff --git a/packages/react/src/RichText/Toolbar/Code.tsx b/packages/react/src/RichText/Toolbar/Code.tsxindex 648a317a5f..169fd0a48b 100644--- a/packages/react/src/RichText/Toolbar/Code.tsx+++ b/packages/react/src/RichText/Toolbar/Code.tsx@@ -1,4 +1,4 @@-import { BsCode } from "react-icons/bs";+import { LuCode } from "react-icons/lu";import type { EditorComponent } from "../types";import ToolbarButton from "./ToolbarButton";@@ -8,7 +8,7 @@ const Code: EditorComponent = ({ editor }) => {label="Code"onClick={() => editor.chain().focus().toggleCode().run()}isActive={editor.isActive("code")}- icon={<BsCode />}+ icon={<LuCode />}disabled={!editor.isEditable}/>);diff --git a/packages/react/src/RichText/Toolbar/CodeBlock.tsx b/packages/react/src/RichText/Toolbar/CodeBlock.tsxindex b155b71d21..1f18b049b4 100644--- a/packages/react/src/RichText/Toolbar/CodeBlock.tsx+++ b/packages/react/src/RichText/Toolbar/CodeBlock.tsx@@ -1,4 +1,4 @@-import { BsCodeSlash } from "react-icons/bs";+import { LuCode2 } from "react-icons/lu";import type { EditorComponent } from "../types";import ToolbarButton from "./ToolbarButton";@@ -8,7 +8,7 @@ const CodeBlock: EditorComponent = ({ editor }) => {label="Codeblock"onClick={() => editor.chain().focus().toggleCodeBlock().run()}isActive={editor.isActive("codeBlock")}- icon={<BsCodeSlash />}+ icon={<LuCode2 />}disabled={!editor.isEditable}/>);diff --git a/packages/react/src/RichText/Toolbar/Heading.tsx b/packages/react/src/RichText/Toolbar/Heading.tsxindex 6a053a604b..969fe8d50b 100644--- a/packages/react/src/RichText/Toolbar/Heading.tsx+++ b/packages/react/src/RichText/Toolbar/Heading.tsx@@ -1,4 +1,4 @@-import { BsTypeH1, BsTypeH2, BsTypeH3 } from "react-icons/bs";+import { LuHeading1, LuHeading2, LuHeading3 } from "react-icons/lu";import type { EditorComponent } from "../types";import ToolbarButton from "./ToolbarButton";@@ -8,7 +8,7 @@ export const HeadingOne: EditorComponent = ({ editor }) => {label="Heading 1"onClick={() => editor.chain().focus().toggleHeading({ level: 1 }).run()}isActive={editor.isActive("heading", { level: 1 })}- icon={<BsTypeH1 />}+ icon={<LuHeading1 />}disabled={!editor.isEditable}/>);@@ -20,7 +20,7 @@ export const HeadingTwo: EditorComponent = ({ editor }) => {label="Heading 2"onClick={() => editor.chain().focus().toggleHeading({ level: 2 }).run()}isActive={editor.isActive("heading", { level: 2 })}- icon={<BsTypeH2 />}+ icon={<LuHeading2 />}disabled={!editor.isEditable}/>);@@ -32,7 +32,7 @@ export const HeadingThree: EditorComponent = ({ editor }) => {label="Heading 3"onClick={() => editor.chain().focus().toggleHeading({ level: 3 }).run()}isActive={editor.isActive("heading", { level: 3 })}- icon={<BsTypeH3 />}+ icon={<LuHeading3 />}disabled={!editor.isEditable}/>);diff --git a/packages/react/src/RichText/Toolbar/Italic.tsx b/packages/react/src/RichText/Toolbar/Italic.tsxindex 1506064957..f2c7e1f963 100644--- a/packages/react/src/RichText/Toolbar/Italic.tsx+++ b/packages/react/src/RichText/Toolbar/Italic.tsx@@ -1,4 +1,4 @@-import { BsTypeItalic } from "react-icons/bs";+import { LuItalic } from "react-icons/lu";import type { EditorComponent } from "../types";import ToolbarButton from "./ToolbarButton";@@ -8,7 +8,7 @@ const Italic: EditorComponent = ({ editor }) => {label="Italic"onClick={() => editor.chain().focus().toggleItalic().run()}isActive={editor.isActive("italic")}- icon={<BsTypeItalic />}+ icon={<LuItalic />}disabled={!editor.isEditable}>Idiff --git a/packages/react/src/RichText/Toolbar/OrderedList.tsx b/packages/react/src/RichText/Toolbar/OrderedList.tsxindex 1011c4886d..67f5001515 100644--- a/packages/react/src/RichText/Toolbar/OrderedList.tsx+++ b/packages/react/src/RichText/Toolbar/OrderedList.tsx@@ -1,4 +1,4 @@-import { BsListOl } from "react-icons/bs";+import { LuListOrdered } from "react-icons/lu";import type { EditorComponent } from "../types";import ToolbarButton from "./ToolbarButton";@@ -8,7 +8,7 @@ const OrderedList: EditorComponent = ({ editor }) => {label="Numbered list"onClick={() => editor.chain().focus().toggleOrderedList().run()}isActive={editor.isActive("orderedList")}- icon={<BsListOl />}+ icon={<LuListOrdered />}disabled={!editor.isEditable}/>);diff --git a/packages/react/src/RichText/Toolbar/Paragraph.tsx b/packages/react/src/RichText/Toolbar/Paragraph.tsxindex a0b59a6bc8..f839377ca0 100644--- a/packages/react/src/RichText/Toolbar/Paragraph.tsx+++ b/packages/react/src/RichText/Toolbar/Paragraph.tsx@@ -1,4 +1,4 @@-import { BsType } from "react-icons/bs";+import { LuText } from "react-icons/lu";import type { EditorComponent } from "../types";import ToolbarButton from "./ToolbarButton";@@ -8,7 +8,7 @@ const Paragraph: EditorComponent = ({ editor }) => {label="Normal text"onClick={() => editor.chain().focus().setParagraph().run()}isActive={editor.isActive("paragraph")}- icon={<BsType />}+ icon={<LuText />}disabled={!editor.isEditable}/>);diff --git a/packages/react/src/RichText/Toolbar/Strike.tsx b/packages/react/src/RichText/Toolbar/Strike.tsxindex 304ca350d0..fcc0fdd4ca 100644--- a/packages/react/src/RichText/Toolbar/Strike.tsx+++ b/packages/react/src/RichText/Toolbar/Strike.tsx@@ -1,4 +1,4 @@-import { BsTypeStrikethrough } from "react-icons/bs";+import { LuStrikethrough } from "react-icons/lu";import type { EditorComponent } from "../types";import ToolbarButton from "./ToolbarButton";@@ -8,7 +8,7 @@ const Strike: EditorComponent = ({ editor }) => {label="Strike"onClick={() => editor.chain().focus().toggleStrike().run()}isActive={editor.isActive("strike")}- icon={<BsTypeStrikethrough />}+ icon={<LuStrikethrough />}disabled={!editor.isEditable}/>);diff --git a/packages/react/src/Separator.tsx b/packages/react/src/Separator.tsxnew file mode 100644index 0000000000..9024895e41--- /dev/null+++ b/packages/react/src/Separator.tsx@@ -0,0 +1,31 @@+"use client";++import * as SeparatorPrimitive from "@radix-ui/react-separator";+import * as React from "react";++import { cn } from "./utils/cn";++const Separator = React.forwardRef<+ React.ElementRef<typeof SeparatorPrimitive.Root>,+ React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>+>(+ (+ { className, orientation = "horizontal", decorative = true, ...props },+ ref+ ) => (+ <SeparatorPrimitive.Root+ ref={ref}+ decorative={decorative}+ orientation={orientation}+ className={cn(+ "shrink-0 bg-border",+ orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",+ className+ )}+ {...props}+ />+ )+);+Separator.displayName = SeparatorPrimitive.Root.displayName;++export { Separator };diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsxindex c4f4fee7fa..135503fca1 100644--- a/packages/react/src/index.tsx+++ b/packages/react/src/index.tsx@@ -1,3 +1,4 @@+import type { JSONContent } from "novel";import { ActionMenu } from "./ActionMenu";import { Alert, AlertDescription, AlertTitle } from "./Alert";import type { AvatarProps } from "./Avatar";@@ -92,6 +93,7 @@ import {DropdownMenuSubTrigger,DropdownMenuTrigger,} from "./Dropdown";+import { Editor } from "./Editor";import { Enumerable } from "./Enumerable";import { File } from "./File";import {@@ -309,6 +311,7 @@ export {DropdownMenuSubContent,DropdownMenuSubTrigger,DropdownMenuTrigger,+ Editor,Enumerable,File,FormControl,@@ -445,6 +448,7 @@ export type {AvatarProps,ButtonProps,InputProps,+ JSONContent,NumberFieldProps,TextareaProps,};