The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
rich text editor to partner lander
Pedro Ladeira7f999a6f7c08
diff --git a/apps/web/ui/partners/groups/design/lander/lander-rich-text-editor.tsx b/apps/web/ui/partners/groups/design/lander/lander-rich-text-editor.tsxnew file mode 100644index 0000000000..538ad60a27--- /dev/null+++ b/apps/web/ui/partners/groups/design/lander/lander-rich-text-editor.tsx@@ -0,0 +1,61 @@+"use client";++import {+ RichTextArea,+ RichTextFeature,+ RichTextProvider,+ RichTextToolbar,+} from "@dub/ui";+import { cn } from "@dub/utils";++export const LANDER_RICH_TEXT_FEATURES: RichTextFeature[] = [+ "bold",+ "italic",+ "links",+ "lists",+ "tables",+ "quote",+ "code",+];++export function LanderRichTextEditor({+ value,+ onChange,+ placeholder = "Start typing...",+ error,+ editorClassName,+}: {+ value?: string;+ onChange: (value: string) => void;+ placeholder?: string;+ error?: boolean;+ editorClassName?: string;+}) {+ return (+ <RichTextProvider+ features={LANDER_RICH_TEXT_FEATURES}+ markdown+ style="relaxed"+ placeholder={placeholder}+ editorClassName={cn(+ "block max-h-64 min-h-16 overflow-auto scrollbar-hide w-full resize-none border-none p-3 text-base sm:text-sm",+ editorClassName,+ )}+ initialValue={value ?? ""}+ onChange={(editor) => onChange((editor as any).getMarkdown() || "")}+ >+ <div+ className={cn(+ "overflow-hidden rounded-md border border-neutral-300 shadow-sm focus-within:border-neutral-500 focus-within:ring-1 focus-within:ring-neutral-500",+ error &&+ "border-red-600 focus-within:border-red-500 focus-within:ring-red-600",+ )}+ >+ <div className="flex flex-col">+ <RichTextArea />+ <RichTextToolbar className="flex-wrap px-1 pb-1" />+ </div>+ </div>+ </RichTextProvider>+ );+}diff --git a/apps/web/ui/partners/groups/design/lander/modals/accordion-block-modal.tsx b/apps/web/ui/partners/groups/design/lander/modals/accordion-block-modal.tsxindex 9cf6a422cc..23b34f0df1 100644--- a/apps/web/ui/partners/groups/design/lander/modals/accordion-block-modal.tsx+++ b/apps/web/ui/partners/groups/design/lander/modals/accordion-block-modal.tsx@@ -1,6 +1,7 @@"use client";import { programLanderAccordionBlockSchema } from "@/lib/zod/schemas/program-lander";+import { MaxCharactersCounter } from "@/ui/shared/max-characters-counter";import {Button,CircleWarning,@@ -10,10 +11,13 @@ import {} from "@dub/ui";import { cn } from "@dub/utils";import { Dispatch, SetStateAction, useId, useRef } from "react";-import { useForm } from "react-hook-form";+import { Controller, useForm } from "react-hook-form";import { v4 as uuid } from "uuid";import * as z from "zod/v4";import { EditList, ExpandableEditListItem } from "../../edit-list";+import { LanderRichTextEditor } from "../lander-rich-text-editor";++const ACCORDION_ITEM_CONTENT_MAX_LENGTH = 1000;type AccordionBlockData = z.infer<typeof programLanderAccordionBlockSchema@@ -31,7 +35,7 @@ export function AccordionBlockModal(props: AccordionBlockModalProps) {<ModalshowModal={props.showModal}setShowModal={props.setShowModal}- className=""+ className="max-w-screen-lg"><AccordionBlockModalInner {...props} /></Modal>@@ -48,6 +52,7 @@ function AccordionBlockModalInner({const {handleSubmit,register,+ control,watch,setValue,formState: { errors },@@ -198,20 +203,41 @@ function AccordionBlockModalInner({>Content</label>- <div className="mt-2 rounded-md shadow-sm">- <textarea- id={`${id}-${field.id}-content`}- rows={3}- maxLength={1000}- placeholder="Start typing"- className={cn(- "block max-h-32 min-h-16 w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",- fieldErrors?.content &&- "border-red-600 focus:border-red-500 focus:ring-red-600",+ <div className="mt-2">+ <Controller+ control={control}+ name={`items.${index}.content`}+ rules={{+ validate: (value) => {+ const content = value?.trim() ?? "";+ if (!content) return "Content is required";+ if (+ content.length >+ ACCORDION_ITEM_CONTENT_MAX_LENGTH+ ) {+ return `Content must be less than ${ACCORDION_ITEM_CONTENT_MAX_LENGTH} characters`;+ }+ return true;+ },+ }}+ render={({ field: contentField }) => (+ <LanderRichTextEditor+ key={field.id}+ value={contentField.value}+ onChange={contentField.onChange}+ placeholder="Start typing"+ error={Boolean(fieldErrors?.content)}+ editorClassName="max-h-32 min-h-16"+ />)}- {...register(`items.${index}.content`, {- required: "Content is required",- })}+ />+ </div>+ <div className="mt-1 text-left">+ <MaxCharactersCounter+ name={`items.${index}.content`}+ control={control}+ maxLength={ACCORDION_ITEM_CONTENT_MAX_LENGTH}+ spaced/></div></div>diff --git a/apps/web/ui/partners/groups/design/lander/modals/text-block-modal.tsx b/apps/web/ui/partners/groups/design/lander/modals/text-block-modal.tsxindex 26ee2a90eb..8282c3de80 100644--- a/apps/web/ui/partners/groups/design/lander/modals/text-block-modal.tsx+++ b/apps/web/ui/partners/groups/design/lander/modals/text-block-modal.tsx@@ -1,17 +1,14 @@"use client";import { programLanderTextBlockSchema } from "@/lib/zod/schemas/program-lander";-import {- Button,- MarkdownIcon,- Modal,- useEnterSubmit,- useMediaQuery,-} from "@dub/ui";-import { cn } from "@dub/utils";+import { MaxCharactersCounter } from "@/ui/shared/max-characters-counter";+import { Button, Modal, useMediaQuery } from "@dub/ui";import { Dispatch, SetStateAction, useId } from "react";-import { useForm } from "react-hook-form";+import { Controller, useForm } from "react-hook-form";import * as z from "zod/v4";+import { LanderRichTextEditor } from "../lander-rich-text-editor";++const TEXT_BLOCK_CONTENT_MAX_LENGTH = 10000;type TextBlockData = z.infer<typeof programLanderTextBlockSchema>["data"];@@ -24,7 +21,11 @@ type TextBlockModalProps = {export function TextBlockModal(props: TextBlockModalProps) {return (- <Modal showModal={props.showModal} setShowModal={props.setShowModal}>+ <Modal+ showModal={props.showModal}+ setShowModal={props.setShowModal}+ className="max-w-screen-lg"+ ><TextBlockModalInner {...props} /></Modal>);@@ -40,13 +41,12 @@ function TextBlockModalInner({const {handleSubmit,register,+ control,formState: { errors },} = useForm<TextBlockData>({defaultValues,});- const { handleKeyDown } = useEnterSubmit();-return (<><div className="p-4 pt-3">@@ -91,30 +91,37 @@ function TextBlockModalInner({>Content</label>- <div className="mt-2 rounded-md shadow-sm">- <textarea- id={`${id}-content`}- rows={12}- maxLength={10000}- onKeyDown={handleKeyDown}- placeholder="Start typing..."- className={cn(- "block max-h-64 min-h-16 w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",- errors.content &&- "border-red-600 focus:border-red-500 focus:ring-red-600",+ <div className="mt-2">+ <Controller+ control={control}+ name="content"+ rules={{+ validate: (value) => {+ const content = value?.trim() ?? "";+ if (!content) return "Content is required";+ if (content.length > TEXT_BLOCK_CONTENT_MAX_LENGTH) {+ return `Content must be less than ${TEXT_BLOCK_CONTENT_MAX_LENGTH} characters`;+ }+ return true;+ },+ }}+ render={({ field }) => (+ <LanderRichTextEditor+ value={field.value}+ onChange={field.onChange}+ error={Boolean(errors.content)}+ />)}- {...register("content", { required: "Content is required" })}/></div>- <a- href="https://www.markdownguide.org/extended-syntax/#tables"- target="_blank"- rel="noopener noreferrer"- className="text-content-subtle mt-1 flex items-center gap-1 text-xs"- >- <MarkdownIcon role="presentation" className="h-3 w-auto" />- <span className="sr-only">MarkdownIcon</span> supported- </a>+ <div className="mt-1 text-left">+ <MaxCharactersCounter+ name="content"+ control={control}+ maxLength={TEXT_BLOCK_CONTENT_MAX_LENGTH}+ spaced+ />+ </div></div><div className="flex items-center justify-end gap-2">diff --git a/apps/web/ui/partners/lander/blocks/block-markdown.tsx b/apps/web/ui/partners/lander/blocks/block-markdown.tsxindex 041f0e9a40..2ddb82762f 100644--- a/apps/web/ui/partners/lander/blocks/block-markdown.tsx+++ b/apps/web/ui/partners/lander/blocks/block-markdown.tsx@@ -22,6 +22,31 @@ export function BlockMarkdown({><MarkdownremarkPlugins={[remarkGfm]}+ unwrapDisallowed+ allowedElements={[+ "p",+ "br",+ "strong",+ "em",+ "a",+ "ul",+ "ol",+ "li",+ "blockquote",+ "code",+ "table",+ "thead",+ "tbody",+ "tr",+ "th",+ "td",+ "h1",+ "h2",+ "h3",+ "h4",+ "h5",+ "h6",+ ]}components={{a: ({ node, ...props }) => (<a {...props} target="_blank" rel="noopener noreferrer" />diff --git a/packages/ui/package.json b/packages/ui/package.jsonindex 48b2343be9..77d2f567e2 100644--- a/packages/ui/package.json+++ b/packages/ui/package.json@@ -77,6 +77,7 @@"@tiptap/extension-image": "^3.15.3","@tiptap/extension-link": "^3.15.3","@tiptap/extension-mention": "^3.15.3",+ "@tiptap/extension-table": "^3.15.3","@tiptap/extensions": "^3.15.3","@tiptap/markdown": "^3.15.3","@tiptap/pm": "^3.15.3",diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.tsindex a3c8dcc192..a0dc4f2116 100644--- a/packages/ui/src/icons/nucleo/index.ts+++ b/packages/ui/src/icons/nucleo/index.ts@@ -31,10 +31,10 @@ export * from "./calendar-refresh";export * from "./calendar6";export * from "./cards";export * from "./caret-up";-export * from "./chat-task";export * from "./chart-activity2";export * from "./chart-area2";export * from "./chart-line";+export * from "./chat-task";export * from "./check";export * from "./check2";export { CheckboxIcon } from "./checkbox";@@ -142,8 +142,8 @@ export * from "./input-password-pointer";export * from "./input-search";export * from "./invoice-dollar";export * from "./key";-export * from "./layout-sidebar";export * from "./layers-3";+export * from "./layout-sidebar";export * from "./license";export * from "./life-ring";export * from "./lines-y";@@ -170,6 +170,7 @@ export * from "./msgs";export * from "./msgs-dotted";export * from "./nodes-4";export * from "./note";+export * from "./numbered-list";export * from "./office-building";export * from "./page2";export * from "./paintbrush";@@ -185,6 +186,7 @@ export * from "./plus2";export * from "./post";export * from "./pyramid";export * from "./qrcode";+export * from "./quote";export * from "./receipt2";export * from "./referred-via";export * from "./refresh2";diff --git a/packages/ui/src/icons/nucleo/numbered-list.tsx b/packages/ui/src/icons/nucleo/numbered-list.tsxnew file mode 100644index 0000000000..334fcfc0c3--- /dev/null+++ b/packages/ui/src/icons/nucleo/numbered-list.tsx@@ -0,0 +1,54 @@+import { SVGProps } from "react";++export function NumberedList(props: SVGProps<SVGSVGElement>) {+ return (+ <svg+ height="18"+ width="18"+ viewBox="0 0 18 18"+ xmlns="http://www.w3.org/2000/svg"+ {...props}+ >+ <g fill="currentColor">+ <path+ d="M2.5,11.661c.259-.921,1.152-1.425,2.116-1.411,.965,.014,1.872,.446,1.929,1.411s-.965,1.612-2.023,2.044c-1.058,.432-1.936,.835-2.023,2.044H6.548"+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="9.5"+ x2="16.25"+ y1="5.25"+ y2="5.25"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="9.5"+ x2="16.25"+ y1="12.75"+ y2="12.75"+ />+ <path+ d="M4.75,7.5V2s-.63,1.108-1.967,1.364"+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ </g>+ </svg>+ );+}diff --git a/packages/ui/src/icons/nucleo/quote.tsx b/packages/ui/src/icons/nucleo/quote.tsxnew file mode 100644index 0000000000..132bf89308--- /dev/null+++ b/packages/ui/src/icons/nucleo/quote.tsx@@ -0,0 +1,22 @@+import { SVGProps } from "react";++export function Quote(props: SVGProps<SVGSVGElement>) {+ return (+ <svg+ height="18"+ width="18"+ viewBox="0 0 18 18"+ xmlns="http://www.w3.org/2000/svg"+ {...props}+ >+ <g fill="currentColor">+ <path d="M15.25,15H2.75c-.414,0-.75-.336-.75-.75s.336-.75,.75-.75H15.25c.414,0,.75,.336,.75,.75s-.336,.75-.75,.75Z" />+ <path d="M15.25,11.5H2.75c-.414,0-.75-.336-.75-.75s.336-.75,.75-.75H15.25c.414,0,.75,.336,.75,.75s-.336,.75-.75,.75Z" />+ <path d="M15.25,8h-3c-.414,0-.75-.336-.75-.75s.336-.75,.75-.75h3c.414,0,.75,.336,.75,.75s-.336,.75-.75,.75Z" />+ <path d="M15.25,4.5h-3c-.414,0-.75-.336-.75-.75s.336-.75,.75-.75h3c.414,0,.75,.336,.75,.75s-.336,.75-.75,.75Z" />+ <path d="M4.75,5h-1.202c.151-1.066,.645-1.355,1.147-1.551,.387-.15,.578-.585,.428-.971s-.589-.575-.971-.427c-1.469,.571-2.152,1.747-2.152,3.699v1.5c0,.414,.336,.75,.75,.75h2c.414,0,.75-.336,.75-.75v-1.5c0-.414-.336-.75-.75-.75Z" />+ <path d="M9.25,5h-1.202c.151-1.066,.645-1.355,1.147-1.551,.387-.15,.578-.585,.428-.971-.149-.386-.588-.575-.971-.427-1.469,.571-2.152,1.747-2.152,3.699v1.5c0,.414,.336,.75,.75,.75h2c.414,0,.75-.336,.75-.75v-1.5c0-.414-.336-.75-.75-.75Z" />+ </g>+ </svg>+ );+}diff --git a/packages/ui/src/rich-text-area/link-modal.tsx b/packages/ui/src/rich-text-area/link-modal.tsxindex 4ece879e02..5a643fcfd4 100644--- a/packages/ui/src/rich-text-area/link-modal.tsx+++ b/packages/ui/src/rich-text-area/link-modal.tsx@@ -47,6 +47,7 @@ function RichTextLinkModalInner({ state }: { state: RichTextLinkModalState }) {const handleSave = (e: FormEvent) => {e.preventDefault();+ e.stopPropagation();if (!editor) return;const finalHref = normalizeLinkHref(href);diff --git a/packages/ui/src/rich-text-area/rich-text-provider.tsx b/packages/ui/src/rich-text-area/rich-text-provider.tsxindex 32f1da616c..91a5028159 100644--- a/packages/ui/src/rich-text-area/rich-text-provider.tsx+++ b/packages/ui/src/rich-text-area/rich-text-provider.tsx@@ -3,6 +3,7 @@ import FileHandler from "@tiptap/extension-file-handler";import Image from "@tiptap/extension-image";import Link from "@tiptap/extension-link";import Mention from "@tiptap/extension-mention";+import { TableKit } from "@tiptap/extension-table";import { Placeholder } from "@tiptap/extensions";import { Markdown } from "@tiptap/markdown";import { Editor, useEditor } from "@tiptap/react";@@ -31,7 +32,7 @@ export const PROSE_STYLES = {relaxed: "",} as const;-const FEATURES = [+const CORE_FEATURES = ["images","variables","links",@@ -41,7 +42,15 @@ const FEATURES = ["strike",] as const;-export const DEFAULT_RICH_TEXT_FEATURES = FEATURES;+const FEATURES = [+ ...CORE_FEATURES,+ "lists",+ "tables",+ "quote",+ "code",+] as const;++export const DEFAULT_RICH_TEXT_FEATURES = CORE_FEATURES;const OPTIONAL_FEATURES = ["imageControls"] as const;@@ -101,7 +110,7 @@ export const RichTextProvider = forwardRef<({children,- features = FEATURES as any,+ features = DEFAULT_RICH_TEXT_FEATURES as any,markdown = false,style = "default",placeholder = "Start typing...",@@ -191,6 +200,19 @@ export const RichTextProvider = forwardRef<link: false,}),+ ...(features.includes("tables")+ ? [+ TableKit.configure({+ table: {+ resizable: false,+ HTMLAttributes: {+ class: "w-full border-collapse",+ },+ },+ }),+ ]+ : []),+...(features.includes("links")? [Link.extend({@@ -310,6 +332,8 @@ export const RichTextProvider = forwardRef<// "loose" list and gives paragraph spacing. Zero it so items sit 4px apart (the// <li> margins), and match the bullet color to the ordered list counters."[&_li>p]:my-0 marker:prose-ul:text-neutral-500",+ features.includes("tables") &&+ "[&_table]:my-3 [&_th]:border [&_td]:border [&_th]:border-neutral-200 [&_td]:border-neutral-200 [&_th]:bg-neutral-50 [&_th]:px-2 [&_td]:px-2 [&_th]:py-1.5 [&_td]:py-1.5 [&_th]:text-left",PROSE_STYLES[style],"[&_.ProseMirror-selectednode]:outline [&_.ProseMirror-selectednode]:outline-2 [&_.ProseMirror-selectednode]:outline-blue-500 [&_.ProseMirror-selectednode]:outline-offset-2","[&_.ProseMirror-selectednode:has(img)]:outline-none",diff --git a/packages/ui/src/rich-text-area/rich-text-toolbar.tsx b/packages/ui/src/rich-text-area/rich-text-toolbar.tsxindex b4b7c21798..a19a7ea8fc 100644--- a/packages/ui/src/rich-text-area/rich-text-toolbar.tsx+++ b/packages/ui/src/rich-text-area/rich-text-toolbar.tsx@@ -4,11 +4,16 @@ import { ReactNode, forwardRef, useRef } from "react";import { toast } from "sonner";import {AtSign,+ BulletList,+ Code,Heading1,Heading2,Hyperlink,Icon,ImageIcon,+ NumberedList,+ Quote,+ TableIcon,TextBold,TextItalic,TextStrike,@@ -35,6 +40,10 @@ export function RichTextToolbar({isStrike: Boolean(editor?.isActive("strike")),isHeading1: Boolean(editor?.isActive("heading", { level: 1 })),isHeading2: Boolean(editor?.isActive("heading", { level: 2 })),+ isBulletList: Boolean(editor?.isActive("bulletList")),+ isOrderedList: Boolean(editor?.isActive("orderedList")),+ isBlockquote: Boolean(editor?.isActive("blockquote")),+ isCode: Boolean(editor?.isActive("code")),isSelection: editor?.state.selection.from !== editor?.state.selection.to,}),});@@ -95,6 +104,52 @@ export function RichTextToolbar({/></>)}+ {features?.includes("lists") && (+ <>+ <RichTextToolbarButton+ icon={BulletList}+ label="Bullet list"+ isActive={editorState?.isBulletList}+ onClick={() => editor?.chain().focus().toggleBulletList().run()}+ />+ <RichTextToolbarButton+ icon={NumberedList}+ label="Numbered list"+ isActive={editorState?.isOrderedList}+ onClick={() => editor?.chain().focus().toggleOrderedList().run()}+ />+ </>+ )}+ {features?.includes("tables") && (+ <RichTextToolbarButton+ icon={TableIcon}+ label="Table"+ isActive={false}+ onClick={() =>+ editor+ ?.chain()+ .focus()+ .insertTable({ rows: 3, cols: 3, withHeaderRow: true })+ .run()+ }+ />+ )}+ {features?.includes("quote") && (+ <RichTextToolbarButton+ icon={Quote}+ label="Quote"+ isActive={editorState?.isBlockquote}+ onClick={() => editor?.chain().focus().toggleBlockquote().run()}+ />+ )}+ {features?.includes("code") && (+ <RichTextToolbarButton+ icon={Code}+ label="Inline code"+ isActive={editorState?.isCode}+ onClick={() => editor?.chain().focus().toggleCode().run()}+ />+ )}{features?.includes("links") && <LinkButton />}{features?.includes("variables") && (<RichTextToolbarButtondiff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 77ee7d2c94..91b9ef4808 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -807,6 +807,9 @@ importers:'@tiptap/extension-mention':specifier: ^3.15.3version: 3.15.3(@tiptap/[email protected](@tiptap/[email protected]))(@tiptap/[email protected])(@tiptap/[email protected](@tiptap/[email protected](@tiptap/[email protected]))(@tiptap/[email protected]))+ '@tiptap/extension-table':+ specifier: ^3.15.3'@tiptap/extensions':specifier: ^3.15.3@@ -5579,6 +5582,12 @@ packages:peerDependencies:'@tiptap/core': ^3.15.3+ '@tiptap/[email protected]':+ resolution: {integrity: sha512-dJk0u2JX1J/3x/ps641qdxQPOiie5txQhs2M1srgDeeFu//ORCePAxryJCw1bgf0TEVwFWwFTCtcOFR5SSgMZQ==}+ peerDependencies:+ '@tiptap/core': ^3.15.3+ '@tiptap/pm': ^3.15.3+'@tiptap/[email protected]':resolution: {integrity: sha512-x7SZLS537c7w789n8re0IktmkBZqz98dux/hwpFAcC4oL06YPjFG7Dy9mAiKcsKqKWI0eAyTQvMybz+TJusBbw==}peerDependencies:@@ -19236,6 +19245,11 @@ snapshots:dependencies:'@tiptap/core': 3.15.3(@tiptap/[email protected])+ '@tiptap/[email protected](@tiptap/[email protected](@tiptap/[email protected]))(@tiptap/[email protected])':+ dependencies:+ '@tiptap/core': 3.15.3(@tiptap/[email protected])+ '@tiptap/pm': 3.15.3+dependencies:'@tiptap/core': 3.15.3(@tiptap/[email protected])