Plate Editor
This commit is contained in:
		
							
								
								
									
										3817
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										3817
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										24
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								package.json
									
									
									
									
									
								
							@ -14,23 +14,7 @@
 | 
			
		||||
    "@dnd-kit/sortable": "^10.0.0",
 | 
			
		||||
    "@dnd-kit/utilities": "^3.2.2",
 | 
			
		||||
    "@hookform/resolvers": "^5.1.1",
 | 
			
		||||
    "@lexical/code": "^0.33.0",
 | 
			
		||||
    "@lexical/list": "^0.33.0",
 | 
			
		||||
    "@lexical/markdown": "^0.33.0",
 | 
			
		||||
    "@lexical/react": "^0.33.0",
 | 
			
		||||
    "@lexical/rich-text": "^0.33.0",
 | 
			
		||||
    "@milkdown/core": "^7.15.1",
 | 
			
		||||
    "@milkdown/plugin-block": "^7.15.1",
 | 
			
		||||
    "@milkdown/plugin-clipboard": "^7.15.1",
 | 
			
		||||
    "@milkdown/plugin-cursor": "^7.15.1",
 | 
			
		||||
    "@milkdown/plugin-history": "^7.15.1",
 | 
			
		||||
    "@milkdown/plugin-indent": "^7.15.1",
 | 
			
		||||
    "@milkdown/plugin-listener": "^7.15.1",
 | 
			
		||||
    "@milkdown/plugin-prism": "^7.15.1",
 | 
			
		||||
    "@milkdown/plugin-tooltip": "^7.15.1",
 | 
			
		||||
    "@milkdown/preset-gfm": "^7.15.1",
 | 
			
		||||
    "@milkdown/react": "^7.15.1",
 | 
			
		||||
    "@milkdown/theme-nord": "^7.15.1",
 | 
			
		||||
    "@platejs/basic-nodes": "^49.0.0",
 | 
			
		||||
    "@prisma/client": "^6.11.1",
 | 
			
		||||
    "@radix-ui/react-checkbox": "^1.3.2",
 | 
			
		||||
    "@radix-ui/react-dialog": "^1.1.14",
 | 
			
		||||
@ -40,25 +24,29 @@
 | 
			
		||||
    "@radix-ui/react-popover": "^1.1.14",
 | 
			
		||||
    "@radix-ui/react-progress": "^1.1.7",
 | 
			
		||||
    "@radix-ui/react-select": "^2.2.5",
 | 
			
		||||
    "@radix-ui/react-separator": "^1.1.7",
 | 
			
		||||
    "@radix-ui/react-slider": "^1.3.5",
 | 
			
		||||
    "@radix-ui/react-slot": "^1.2.3",
 | 
			
		||||
    "@radix-ui/react-switch": "^1.2.5",
 | 
			
		||||
    "@radix-ui/react-tabs": "^1.1.12",
 | 
			
		||||
    "@radix-ui/react-toggle": "^1.1.9",
 | 
			
		||||
    "@radix-ui/react-toggle-group": "^1.1.10",
 | 
			
		||||
    "@radix-ui/react-toolbar": "^1.1.10",
 | 
			
		||||
    "@radix-ui/react-tooltip": "^1.2.7",
 | 
			
		||||
    "class-variance-authority": "^0.7.1",
 | 
			
		||||
    "clsx": "^2.1.1",
 | 
			
		||||
    "cmdk": "^1.1.1",
 | 
			
		||||
    "lexical": "^0.33.0",
 | 
			
		||||
    "lucide-react": "^0.525.0",
 | 
			
		||||
    "next": "15.3.5",
 | 
			
		||||
    "next-auth": "^5.0.0-beta.29",
 | 
			
		||||
    "next-themes": "^0.4.6",
 | 
			
		||||
    "platejs": "^49.1.5",
 | 
			
		||||
    "react": "^19.0.0",
 | 
			
		||||
    "react-dom": "^19.0.0",
 | 
			
		||||
    "react-hook-form": "^7.59.0",
 | 
			
		||||
    "sonner": "^2.0.6",
 | 
			
		||||
    "tailwind-merge": "^3.3.1",
 | 
			
		||||
    "tailwind-scrollbar-hide": "^4.0.0",
 | 
			
		||||
    "zod": "^3.25.73"
 | 
			
		||||
  },
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										9
									
								
								src/app/editor/page.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/app/editor/page.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
import { PlateEditor } from '@/components/editor/plate-editor';
 | 
			
		||||
 | 
			
		||||
export default function Page() {
 | 
			
		||||
  return (
 | 
			
		||||
    <div className="h-screen w-full">
 | 
			
		||||
      <PlateEditor />
 | 
			
		||||
    </div>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
@ -1,4 +1,6 @@
 | 
			
		||||
@import "tailwindcss";
 | 
			
		||||
 | 
			
		||||
@plugin "tailwind-scrollbar-hide";
 | 
			
		||||
@import "tw-animate-css";
 | 
			
		||||
 | 
			
		||||
@custom-variant dark (&:is(.dark *));
 | 
			
		||||
@ -39,6 +41,8 @@
 | 
			
		||||
  --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
 | 
			
		||||
  --color-sidebar-border: var(--sidebar-border);
 | 
			
		||||
  --color-sidebar-ring: var(--sidebar-ring);
 | 
			
		||||
  --color-brand: var(--brand);
 | 
			
		||||
  --color-highlight: var(--highlight);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
:root {
 | 
			
		||||
@ -74,6 +78,8 @@
 | 
			
		||||
  --sidebar-accent-foreground: oklch(0.21 0.006 285.885);
 | 
			
		||||
  --sidebar-border: oklch(0.92 0.004 286.32);
 | 
			
		||||
  --sidebar-ring: oklch(0.606 0.25 292.717);
 | 
			
		||||
  --brand: oklch(0.623 0.214 259.815);
 | 
			
		||||
  --highlight: oklch(0.852 0.199 91.936);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.dark {
 | 
			
		||||
@ -108,6 +114,8 @@
 | 
			
		||||
  --sidebar-accent-foreground: oklch(0.985 0 0);
 | 
			
		||||
  --sidebar-border: oklch(1 0 0 / 10%);
 | 
			
		||||
  --sidebar-ring: oklch(0.541 0.281 293.009);
 | 
			
		||||
  --brand: oklch(0.707 0.165 254.624);
 | 
			
		||||
  --highlight: oklch(0.852 0.199 91.936);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.light-zinc {
 | 
			
		||||
@ -662,7 +670,6 @@
 | 
			
		||||
  --sidebar-ring: oklch(0.541 0.281 293.009);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@layer base {
 | 
			
		||||
  * {
 | 
			
		||||
    @apply border-border outline-ring/50;
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,4 @@
 | 
			
		||||
"use client"
 | 
			
		||||
 | 
			
		||||
import { MilkdownEditor } from "@/components/items/commissions/tos/editors/MilkdownEditor";
 | 
			
		||||
import { MilkdownProvider } from "@milkdown/react";
 | 
			
		||||
import TosEditor from "@/components/items/commissions/tos/TosEditor";
 | 
			
		||||
 | 
			
		||||
export default function TosPage() {
 | 
			
		||||
  return (
 | 
			
		||||
@ -9,7 +6,9 @@ export default function TosPage() {
 | 
			
		||||
      <div className="flex gap-4 justify-between pb-8">
 | 
			
		||||
        <h1 className="text-2xl font-bold mb-4">Terms of Service</h1>
 | 
			
		||||
      </div>
 | 
			
		||||
      <MilkdownProvider><MilkdownEditor /></MilkdownProvider>
 | 
			
		||||
      <div className="space-y-4 p-1 border rounded-xl bg-muted/20">
 | 
			
		||||
        <TosEditor />
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										54
									
								
								src/components/editor/plate-editor.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								src/components/editor/plate-editor.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,54 @@
 | 
			
		||||
'use client';
 | 
			
		||||
 | 
			
		||||
import { Plate, usePlateEditor } from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
import { BasicNodesKit } from '@/components/editor/plugins/basic-nodes-kit';
 | 
			
		||||
import { Editor, EditorContainer } from '@/components/ui/editor';
 | 
			
		||||
 | 
			
		||||
export function PlateEditor() {
 | 
			
		||||
  const editor = usePlateEditor({
 | 
			
		||||
    plugins: BasicNodesKit,
 | 
			
		||||
    value,
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <Plate editor={editor}>
 | 
			
		||||
      <EditorContainer>
 | 
			
		||||
        <Editor variant="demo" placeholder="Type..." />
 | 
			
		||||
      </EditorContainer>
 | 
			
		||||
    </Plate>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const value = [
 | 
			
		||||
  {
 | 
			
		||||
    children: [{ text: 'Basic Editor' }],
 | 
			
		||||
    type: 'h1',
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    children: [{ text: 'Heading 2' }],
 | 
			
		||||
    type: 'h2',
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    children: [{ text: 'Heading 3' }],
 | 
			
		||||
    type: 'h3',
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    children: [{ text: 'This is a blockquote element' }],
 | 
			
		||||
    type: 'blockquote',
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    children: [
 | 
			
		||||
      { text: 'Basic marks: ' },
 | 
			
		||||
      { bold: true, text: 'bold' },
 | 
			
		||||
      { text: ', ' },
 | 
			
		||||
      { italic: true, text: 'italic' },
 | 
			
		||||
      { text: ', ' },
 | 
			
		||||
      { text: 'underline', underline: true },
 | 
			
		||||
      { text: ', ' },
 | 
			
		||||
      { strikethrough: true, text: 'strikethrough' },
 | 
			
		||||
      { text: '.' },
 | 
			
		||||
    ],
 | 
			
		||||
    type: 'p',
 | 
			
		||||
  },
 | 
			
		||||
];
 | 
			
		||||
							
								
								
									
										26
									
								
								src/components/editor/plugins/basic-blocks-base-kit.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/components/editor/plugins/basic-blocks-base-kit.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,26 @@
 | 
			
		||||
import {
 | 
			
		||||
  BaseBlockquotePlugin,
 | 
			
		||||
  BaseH1Plugin,
 | 
			
		||||
  BaseH2Plugin,
 | 
			
		||||
  BaseH3Plugin,
 | 
			
		||||
  BaseHorizontalRulePlugin,
 | 
			
		||||
} from '@platejs/basic-nodes';
 | 
			
		||||
import { BaseParagraphPlugin } from 'platejs';
 | 
			
		||||
 | 
			
		||||
import { BlockquoteElementStatic } from '@/components/ui/blockquote-node-static';
 | 
			
		||||
import {
 | 
			
		||||
  H1ElementStatic,
 | 
			
		||||
  H2ElementStatic,
 | 
			
		||||
  H3ElementStatic,
 | 
			
		||||
} from '@/components/ui/heading-node-static';
 | 
			
		||||
import { HrElementStatic } from '@/components/ui/hr-node-static';
 | 
			
		||||
import { ParagraphElementStatic } from '@/components/ui/paragraph-node-static';
 | 
			
		||||
 | 
			
		||||
export const BaseBasicBlocksKit = [
 | 
			
		||||
  BaseParagraphPlugin.withComponent(ParagraphElementStatic),
 | 
			
		||||
  BaseH1Plugin.withComponent(H1ElementStatic),
 | 
			
		||||
  BaseH2Plugin.withComponent(H2ElementStatic),
 | 
			
		||||
  BaseH3Plugin.withComponent(H3ElementStatic),
 | 
			
		||||
  BaseBlockquotePlugin.withComponent(BlockquoteElementStatic),
 | 
			
		||||
  BaseHorizontalRulePlugin.withComponent(HrElementStatic),
 | 
			
		||||
];
 | 
			
		||||
							
								
								
									
										51
									
								
								src/components/editor/plugins/basic-blocks-kit.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								src/components/editor/plugins/basic-blocks-kit.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,51 @@
 | 
			
		||||
'use client';
 | 
			
		||||
 | 
			
		||||
import {
 | 
			
		||||
  BlockquotePlugin,
 | 
			
		||||
  H1Plugin,
 | 
			
		||||
  H2Plugin,
 | 
			
		||||
  H3Plugin,
 | 
			
		||||
  HorizontalRulePlugin,
 | 
			
		||||
} from '@platejs/basic-nodes/react';
 | 
			
		||||
import { ParagraphPlugin } from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
import { BlockquoteElement } from '@/components/ui/blockquote-node';
 | 
			
		||||
import { H1Element, H2Element, H3Element } from '@/components/ui/heading-node';
 | 
			
		||||
import { HrElement } from '@/components/ui/hr-node';
 | 
			
		||||
import { ParagraphElement } from '@/components/ui/paragraph-node';
 | 
			
		||||
 | 
			
		||||
export const BasicBlocksKit = [
 | 
			
		||||
  ParagraphPlugin.withComponent(ParagraphElement),
 | 
			
		||||
  H1Plugin.configure({
 | 
			
		||||
    node: {
 | 
			
		||||
      component: H1Element,
 | 
			
		||||
    },
 | 
			
		||||
    rules: {
 | 
			
		||||
      break: { empty: 'reset' },
 | 
			
		||||
    },
 | 
			
		||||
    shortcuts: { toggle: { keys: 'mod+alt+1' } },
 | 
			
		||||
  }),
 | 
			
		||||
  H2Plugin.configure({
 | 
			
		||||
    node: {
 | 
			
		||||
      component: H2Element,
 | 
			
		||||
    },
 | 
			
		||||
    rules: {
 | 
			
		||||
      break: { empty: 'reset' },
 | 
			
		||||
    },
 | 
			
		||||
    shortcuts: { toggle: { keys: 'mod+alt+2' } },
 | 
			
		||||
  }),
 | 
			
		||||
  H3Plugin.configure({
 | 
			
		||||
    node: {
 | 
			
		||||
      component: H3Element,
 | 
			
		||||
    },
 | 
			
		||||
    rules: {
 | 
			
		||||
      break: { empty: 'reset' },
 | 
			
		||||
    },
 | 
			
		||||
    shortcuts: { toggle: { keys: 'mod+alt+3' } },
 | 
			
		||||
  }),
 | 
			
		||||
  BlockquotePlugin.configure({
 | 
			
		||||
    node: { component: BlockquoteElement },
 | 
			
		||||
    shortcuts: { toggle: { keys: 'mod+shift+period' } },
 | 
			
		||||
  }),
 | 
			
		||||
  HorizontalRulePlugin.withComponent(HrElement),
 | 
			
		||||
];
 | 
			
		||||
							
								
								
									
										27
									
								
								src/components/editor/plugins/basic-marks-base-kit.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/components/editor/plugins/basic-marks-base-kit.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,27 @@
 | 
			
		||||
import {
 | 
			
		||||
  BaseBoldPlugin,
 | 
			
		||||
  BaseCodePlugin,
 | 
			
		||||
  BaseHighlightPlugin,
 | 
			
		||||
  BaseItalicPlugin,
 | 
			
		||||
  BaseKbdPlugin,
 | 
			
		||||
  BaseStrikethroughPlugin,
 | 
			
		||||
  BaseSubscriptPlugin,
 | 
			
		||||
  BaseSuperscriptPlugin,
 | 
			
		||||
  BaseUnderlinePlugin,
 | 
			
		||||
} from '@platejs/basic-nodes';
 | 
			
		||||
 | 
			
		||||
import { CodeLeafStatic } from '@/components/ui/code-node-static';
 | 
			
		||||
import { HighlightLeafStatic } from '@/components/ui/highlight-node-static';
 | 
			
		||||
import { KbdLeafStatic } from '@/components/ui/kbd-node-static';
 | 
			
		||||
 | 
			
		||||
export const BaseBasicMarksKit = [
 | 
			
		||||
  BaseBoldPlugin,
 | 
			
		||||
  BaseItalicPlugin,
 | 
			
		||||
  BaseUnderlinePlugin,
 | 
			
		||||
  BaseCodePlugin.withComponent(CodeLeafStatic),
 | 
			
		||||
  BaseStrikethroughPlugin,
 | 
			
		||||
  BaseSubscriptPlugin,
 | 
			
		||||
  BaseSuperscriptPlugin,
 | 
			
		||||
  BaseHighlightPlugin.withComponent(HighlightLeafStatic),
 | 
			
		||||
  BaseKbdPlugin.withComponent(KbdLeafStatic),
 | 
			
		||||
];
 | 
			
		||||
							
								
								
									
										41
									
								
								src/components/editor/plugins/basic-marks-kit.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								src/components/editor/plugins/basic-marks-kit.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,41 @@
 | 
			
		||||
'use client';
 | 
			
		||||
 | 
			
		||||
import {
 | 
			
		||||
  BoldPlugin,
 | 
			
		||||
  CodePlugin,
 | 
			
		||||
  HighlightPlugin,
 | 
			
		||||
  ItalicPlugin,
 | 
			
		||||
  KbdPlugin,
 | 
			
		||||
  StrikethroughPlugin,
 | 
			
		||||
  SubscriptPlugin,
 | 
			
		||||
  SuperscriptPlugin,
 | 
			
		||||
  UnderlinePlugin,
 | 
			
		||||
} from '@platejs/basic-nodes/react';
 | 
			
		||||
 | 
			
		||||
import { CodeLeaf } from '@/components/ui/code-node';
 | 
			
		||||
import { HighlightLeaf } from '@/components/ui/highlight-node';
 | 
			
		||||
import { KbdLeaf } from '@/components/ui/kbd-node';
 | 
			
		||||
 | 
			
		||||
export const BasicMarksKit = [
 | 
			
		||||
  BoldPlugin,
 | 
			
		||||
  ItalicPlugin,
 | 
			
		||||
  UnderlinePlugin,
 | 
			
		||||
  CodePlugin.configure({
 | 
			
		||||
    node: { component: CodeLeaf },
 | 
			
		||||
    shortcuts: { toggle: { keys: 'mod+e' } },
 | 
			
		||||
  }),
 | 
			
		||||
  StrikethroughPlugin.configure({
 | 
			
		||||
    shortcuts: { toggle: { keys: 'mod+shift+x' } },
 | 
			
		||||
  }),
 | 
			
		||||
  SubscriptPlugin.configure({
 | 
			
		||||
    shortcuts: { toggle: { keys: 'mod+comma' } },
 | 
			
		||||
  }),
 | 
			
		||||
  SuperscriptPlugin.configure({
 | 
			
		||||
    shortcuts: { toggle: { keys: 'mod+period' } },
 | 
			
		||||
  }),
 | 
			
		||||
  HighlightPlugin.configure({
 | 
			
		||||
    node: { component: HighlightLeaf },
 | 
			
		||||
    shortcuts: { toggle: { keys: 'mod+shift+h' } },
 | 
			
		||||
  }),
 | 
			
		||||
  KbdPlugin.withComponent(KbdLeaf),
 | 
			
		||||
];
 | 
			
		||||
							
								
								
									
										6
									
								
								src/components/editor/plugins/basic-nodes-kit.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/components/editor/plugins/basic-nodes-kit.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,6 @@
 | 
			
		||||
'use client';
 | 
			
		||||
 | 
			
		||||
import { BasicBlocksKit } from './basic-blocks-kit';
 | 
			
		||||
import { BasicMarksKit } from './basic-marks-kit';
 | 
			
		||||
 | 
			
		||||
export const BasicNodesKit = [...BasicBlocksKit, ...BasicMarksKit];
 | 
			
		||||
@ -1,44 +1,64 @@
 | 
			
		||||
"use client"
 | 
			
		||||
 | 
			
		||||
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
 | 
			
		||||
import { cn } from "@/lib/utils"
 | 
			
		||||
import { EditorContent, useEditor } from '@tiptap/react'
 | 
			
		||||
import StarterKit from '@tiptap/starter-kit'
 | 
			
		||||
import { Bold, Italic, Strikethrough } from "lucide-react"
 | 
			
		||||
import type { Value } from 'platejs';
 | 
			
		||||
 | 
			
		||||
import { BasicBlocksKit } from '@/components/editor/plugins/basic-blocks-kit';
 | 
			
		||||
import { BasicMarksKit } from '@/components/editor/plugins/basic-marks-kit';
 | 
			
		||||
import { Editor, EditorContainer } from '@/components/ui/editor';
 | 
			
		||||
import { FixedToolbar } from '@/components/ui/fixed-toolbar';
 | 
			
		||||
import { MarkToolbarButton } from '@/components/ui/mark-toolbar-button';
 | 
			
		||||
import { ToolbarButton } from '@/components/ui/toolbar';
 | 
			
		||||
import { Plate, usePlateEditor } from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const initialValue: Value = [
 | 
			
		||||
  {
 | 
			
		||||
    children: [{ text: 'Title' }],
 | 
			
		||||
    type: 'h3',
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    children: [{ text: 'This is a quote.' }],
 | 
			
		||||
    type: 'blockquote',
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    type: 'p',
 | 
			
		||||
    children: [
 | 
			
		||||
      { text: 'Hello! Try out the ' },
 | 
			
		||||
      { text: 'bold', bold: true },
 | 
			
		||||
      { text: ', ' },
 | 
			
		||||
      { text: 'italic', italic: true },
 | 
			
		||||
      { text: ', and ' },
 | 
			
		||||
      { text: 'underline', underline: true },
 | 
			
		||||
      { text: ' formatting.' },
 | 
			
		||||
    ],
 | 
			
		||||
  },
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
export default function TosEditor() {
 | 
			
		||||
  const editor = useEditor({
 | 
			
		||||
    extensions: [StarterKit],
 | 
			
		||||
    editorProps: {
 | 
			
		||||
      attributes: {
 | 
			
		||||
        class: 'prose prose-sm sm:prose-base lg:prose-lg xl:prose-2xl m-5 focus:outline-none',
 | 
			
		||||
      },
 | 
			
		||||
    },
 | 
			
		||||
    content: '<p>Hello World! 🌎️</p>',
 | 
			
		||||
    onUpdate: ({ editor }) => {
 | 
			
		||||
      onChange(editor.getHTML())
 | 
			
		||||
    },
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  if (!editor) return null
 | 
			
		||||
  const editor = usePlateEditor({
 | 
			
		||||
    plugins: [
 | 
			
		||||
      ...BasicBlocksKit,
 | 
			
		||||
      ...BasicMarksKit,
 | 
			
		||||
    ], // Add the mark plugins
 | 
			
		||||
    value: initialValue,         // Set initial content
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <div className="space-y-4">
 | 
			
		||||
      <ToggleGroup type="multiple" className="flex gap-1">
 | 
			
		||||
        <ToggleGroupItem onClick={() => editor.chain().focus().toggleBold().run()} pressed={editor.isActive("bold")}>
 | 
			
		||||
          <Bold className="h-4 w-4" />
 | 
			
		||||
        </ToggleGroupItem>
 | 
			
		||||
        <ToggleGroupItem onClick={() => editor.chain().focus().toggleItalic().run()} pressed={editor.isActive("italic")}>
 | 
			
		||||
          <Italic className="h-4 w-4" />
 | 
			
		||||
        </ToggleGroupItem>
 | 
			
		||||
        <ToggleGroupItem onClick={() => editor.chain().focus().toggleStrike().run()} pressed={editor.isActive("strike")}>
 | 
			
		||||
          <Strikethrough className="h-4 w-4" />
 | 
			
		||||
        </ToggleGroupItem>
 | 
			
		||||
      </ToggleGroup>
 | 
			
		||||
 | 
			
		||||
      <div className={cn("border rounded-md p-4 min-h-[200px]", "bg-background text-foreground")}>
 | 
			
		||||
        <EditorContent editor={editor} />
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
  )
 | 
			
		||||
    <Plate editor={editor}>      {/* Provides editor context */}
 | 
			
		||||
      <FixedToolbar className="justify-start rounded-t-lg">
 | 
			
		||||
        {/* Element Toolbar Buttons */}
 | 
			
		||||
        <ToolbarButton onClick={() => editor.tf.h1.toggle()}>H1</ToolbarButton>
 | 
			
		||||
        <ToolbarButton onClick={() => editor.tf.h2.toggle()}>H2</ToolbarButton>
 | 
			
		||||
        <ToolbarButton onClick={() => editor.tf.h3.toggle()}>H3</ToolbarButton>
 | 
			
		||||
        <ToolbarButton onClick={() => editor.tf.blockquote.toggle()}>Quote</ToolbarButton>
 | 
			
		||||
        {/* Mark Toolbar Buttons */}
 | 
			
		||||
        <MarkToolbarButton nodeType="bold" tooltip="Bold (⌘+B)">B</MarkToolbarButton>
 | 
			
		||||
        <MarkToolbarButton nodeType="italic" tooltip="Italic (⌘+I)">I</MarkToolbarButton>
 | 
			
		||||
        <MarkToolbarButton nodeType="underline" tooltip="Underline (⌘+U)">U</MarkToolbarButton>
 | 
			
		||||
      </FixedToolbar>
 | 
			
		||||
      <EditorContainer>         {/* Styles the editor area */}
 | 
			
		||||
        <Editor placeholder="Type your amazing content here..." />
 | 
			
		||||
      </EditorContainer>
 | 
			
		||||
    </Plate>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
@ -1,102 +0,0 @@
 | 
			
		||||
"use client"
 | 
			
		||||
 | 
			
		||||
import { CodeNode } from "@lexical/code"
 | 
			
		||||
import { LinkNode } from "@lexical/link"
 | 
			
		||||
import { ListItemNode, ListNode } from "@lexical/list"
 | 
			
		||||
import {
 | 
			
		||||
  InitialConfigType,
 | 
			
		||||
  LexicalComposer,
 | 
			
		||||
} from "@lexical/react/LexicalComposer"
 | 
			
		||||
import { ContentEditable } from "@lexical/react/LexicalContentEditable"
 | 
			
		||||
import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary"
 | 
			
		||||
import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin"
 | 
			
		||||
import { HorizontalRuleNode } from "@lexical/react/LexicalHorizontalRuleNode"
 | 
			
		||||
import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin"
 | 
			
		||||
import { ListPlugin } from "@lexical/react/LexicalListPlugin"
 | 
			
		||||
import { MarkdownShortcutPlugin } from "@lexical/react/LexicalMarkdownShortcutPlugin"
 | 
			
		||||
import { OnChangePlugin } from "@lexical/react/LexicalOnChangePlugin"
 | 
			
		||||
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin"
 | 
			
		||||
import { HeadingNode, QuoteNode } from "@lexical/rich-text"
 | 
			
		||||
import { EditorState } from "lexical"
 | 
			
		||||
import { useCallback } from "react"
 | 
			
		||||
import ToolbarPlugin from "./plugins/ToolbarPlugin"
 | 
			
		||||
 | 
			
		||||
type Props = {
 | 
			
		||||
  onChange?: (editorState: EditorState) => void
 | 
			
		||||
  placeholder?: string
 | 
			
		||||
  initialEditorState?: string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default function LexicalEditor({
 | 
			
		||||
  onChange,
 | 
			
		||||
  placeholder = "Write your Terms of Service here...",
 | 
			
		||||
  initialEditorState,
 | 
			
		||||
}: Props) {
 | 
			
		||||
  const initialConfig: InitialConfigType = {
 | 
			
		||||
    namespace: "TosEditor",
 | 
			
		||||
    editorState: initialEditorState ?? undefined,
 | 
			
		||||
    theme: {
 | 
			
		||||
      paragraph: "mb-2",
 | 
			
		||||
      heading: {
 | 
			
		||||
        h1: "text-2xl font-bold",
 | 
			
		||||
        h2: "text-xl font-semibold",
 | 
			
		||||
        h3: "text-lg font-medium",
 | 
			
		||||
      },
 | 
			
		||||
      quote: "border-l-4 pl-4 italic text-muted-foreground",
 | 
			
		||||
      list: {
 | 
			
		||||
        nested: {
 | 
			
		||||
          listitem: "ml-6",
 | 
			
		||||
        },
 | 
			
		||||
        ol: "list-decimal list-inside",
 | 
			
		||||
        ul: "list-disc list-inside",
 | 
			
		||||
        listitem: "my-1",
 | 
			
		||||
      },
 | 
			
		||||
      code: "bg-muted text-sm font-mono rounded p-1",
 | 
			
		||||
    },
 | 
			
		||||
    nodes: [
 | 
			
		||||
      HeadingNode,
 | 
			
		||||
      QuoteNode,
 | 
			
		||||
      CodeNode,
 | 
			
		||||
      ListNode,
 | 
			
		||||
      ListItemNode,
 | 
			
		||||
      HorizontalRuleNode,
 | 
			
		||||
      LinkNode,
 | 
			
		||||
    ],
 | 
			
		||||
    onError: (error) => {
 | 
			
		||||
      console.error("Lexical Error:", error)
 | 
			
		||||
    },
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const handleChange = useCallback(
 | 
			
		||||
    (editorState: EditorState) => {
 | 
			
		||||
      if (onChange) onChange(editorState)
 | 
			
		||||
    },
 | 
			
		||||
    [onChange]
 | 
			
		||||
  )
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <LexicalComposer initialConfig={initialConfig}>
 | 
			
		||||
      <div className="border rounded-md shadow-sm bg-background text-foreground p-4">
 | 
			
		||||
        <ToolbarPlugin />
 | 
			
		||||
        <div className="relative min-h-[200px] mt-2">
 | 
			
		||||
          <RichTextPlugin
 | 
			
		||||
            contentEditable={
 | 
			
		||||
              <ContentEditable className="min-h-[200px] border rounded-md p-4 bg-background text-foreground focus:outline-none" />
 | 
			
		||||
            }
 | 
			
		||||
            placeholder={
 | 
			
		||||
              <div className="absolute top-2 left-2 text-muted-foreground pointer-events-none text-sm">
 | 
			
		||||
                {placeholder}
 | 
			
		||||
              </div>
 | 
			
		||||
            }
 | 
			
		||||
            ErrorBoundary={LexicalErrorBoundary}
 | 
			
		||||
          />
 | 
			
		||||
        </div>
 | 
			
		||||
        <HistoryPlugin />
 | 
			
		||||
        <ListPlugin />
 | 
			
		||||
        <LinkPlugin />
 | 
			
		||||
        <MarkdownShortcutPlugin />
 | 
			
		||||
        <OnChangePlugin onChange={handleChange} />
 | 
			
		||||
      </div>
 | 
			
		||||
    </LexicalComposer>
 | 
			
		||||
  )
 | 
			
		||||
}
 | 
			
		||||
@ -1,87 +0,0 @@
 | 
			
		||||
"use client";
 | 
			
		||||
 | 
			
		||||
import { defaultValueCtx, Editor, rootCtx } from "@milkdown/core";
 | 
			
		||||
import { block } from "@milkdown/plugin-block";
 | 
			
		||||
import { clipboard } from "@milkdown/plugin-clipboard";
 | 
			
		||||
import { cursor } from "@milkdown/plugin-cursor";
 | 
			
		||||
import { history } from "@milkdown/plugin-history";
 | 
			
		||||
import { indent } from "@milkdown/plugin-indent";
 | 
			
		||||
import { listener, listenerCtx } from "@milkdown/plugin-listener";
 | 
			
		||||
import { prism } from "@milkdown/plugin-prism";
 | 
			
		||||
import { gfm } from "@milkdown/preset-gfm";
 | 
			
		||||
import { Milkdown, useEditor } from "@milkdown/react";
 | 
			
		||||
import { useState } from "react";
 | 
			
		||||
 | 
			
		||||
import { Button } from "@/components/ui/button";
 | 
			
		||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
 | 
			
		||||
import { Textarea } from "@/components/ui/textarea";
 | 
			
		||||
 | 
			
		||||
interface MilkdownEditorProps {
 | 
			
		||||
  initialMarkdown?: string;
 | 
			
		||||
  onSave?: (markdown: string, html: string) => void;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function MilkdownEditor({ initialMarkdown = "", onSave }: MilkdownEditorProps) {
 | 
			
		||||
  const [markdown, setMarkdown] = useState(initialMarkdown);
 | 
			
		||||
  const [html, setHtml] = useState("");
 | 
			
		||||
  const [mode, setMode] = useState<"editor" | "markdown">("editor");
 | 
			
		||||
 | 
			
		||||
  useEditor((root) => {
 | 
			
		||||
    return Editor.make()
 | 
			
		||||
      .config((ctx) => {
 | 
			
		||||
        ctx.set(rootCtx, root);
 | 
			
		||||
        ctx.set(defaultValueCtx, initialMarkdown);
 | 
			
		||||
 | 
			
		||||
        const listener = ctx.get(listenerCtx);
 | 
			
		||||
        listener.updated((_ctx, doc) => {
 | 
			
		||||
          const md = doc?.toString() ?? "";
 | 
			
		||||
          setMarkdown(md);
 | 
			
		||||
 | 
			
		||||
          const htmlContent = document.querySelector(".milkdown")?.innerHTML ?? "";
 | 
			
		||||
          setHtml(htmlContent);
 | 
			
		||||
        });
 | 
			
		||||
      })
 | 
			
		||||
      .use(gfm)
 | 
			
		||||
      .use(listener)
 | 
			
		||||
      .use(history)
 | 
			
		||||
      .use(clipboard)
 | 
			
		||||
      .use(cursor)
 | 
			
		||||
      .use(indent)
 | 
			
		||||
      .use(prism)
 | 
			
		||||
      .use(block);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  const handleSave = () => {
 | 
			
		||||
    onSave?.(markdown, html);
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <div className="w-full space-y-4">
 | 
			
		||||
      <Tabs value={mode} onValueChange={(value) => setMode(value as "editor" | "markdown")}>
 | 
			
		||||
        <TabsList className="w-full justify-start">
 | 
			
		||||
          <TabsTrigger value="editor">WYSIWYG</TabsTrigger>
 | 
			
		||||
          <TabsTrigger value="markdown">Markdown</TabsTrigger>
 | 
			
		||||
        </TabsList>
 | 
			
		||||
 | 
			
		||||
        <TabsContent value="editor">
 | 
			
		||||
          <div className="border rounded-lg p-4 bg-background">
 | 
			
		||||
            <Milkdown />
 | 
			
		||||
          </div>
 | 
			
		||||
        </TabsContent>
 | 
			
		||||
 | 
			
		||||
        <TabsContent value="markdown">
 | 
			
		||||
          <Textarea
 | 
			
		||||
            value={markdown}
 | 
			
		||||
            onChange={(e) => setMarkdown(e.target.value)}
 | 
			
		||||
            rows={20}
 | 
			
		||||
            className="font-mono"
 | 
			
		||||
          />
 | 
			
		||||
        </TabsContent>
 | 
			
		||||
      </Tabs>
 | 
			
		||||
 | 
			
		||||
      <div className="flex justify-end">
 | 
			
		||||
        <Button onClick={handleSave}>Save</Button>
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
@ -1,139 +0,0 @@
 | 
			
		||||
"use client"
 | 
			
		||||
 | 
			
		||||
import { Button } from "@/components/ui/button"
 | 
			
		||||
import { $createCodeNode } from "@lexical/code"
 | 
			
		||||
import { TOGGLE_LINK_COMMAND } from "@lexical/link"
 | 
			
		||||
import {
 | 
			
		||||
  INSERT_UNORDERED_LIST_COMMAND,
 | 
			
		||||
  REMOVE_LIST_COMMAND,
 | 
			
		||||
} from "@lexical/list"
 | 
			
		||||
import {
 | 
			
		||||
  useLexicalComposerContext,
 | 
			
		||||
} from "@lexical/react/LexicalComposerContext"
 | 
			
		||||
import {
 | 
			
		||||
  $createHeadingNode,
 | 
			
		||||
  $createQuoteNode,
 | 
			
		||||
} from "@lexical/rich-text"
 | 
			
		||||
import {
 | 
			
		||||
  $setBlocksType,
 | 
			
		||||
} from "@lexical/selection"
 | 
			
		||||
import {
 | 
			
		||||
  $createParagraphNode,
 | 
			
		||||
  $getSelection,
 | 
			
		||||
  $isRangeSelection,
 | 
			
		||||
  COMMAND_PRIORITY_CRITICAL,
 | 
			
		||||
  FORMAT_TEXT_COMMAND,
 | 
			
		||||
  SELECTION_CHANGE_COMMAND,
 | 
			
		||||
} from "lexical"
 | 
			
		||||
import { useEffect } from "react"
 | 
			
		||||
 | 
			
		||||
export default function ToolbarPlugin() {
 | 
			
		||||
  const [editor] = useLexicalComposerContext()
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    return editor.registerCommand(
 | 
			
		||||
      SELECTION_CHANGE_COMMAND,
 | 
			
		||||
      () => {
 | 
			
		||||
        const selection = $getSelection()
 | 
			
		||||
        if ($isRangeSelection(selection)) {
 | 
			
		||||
          // You can optionally handle selection changes here.
 | 
			
		||||
        }
 | 
			
		||||
        return false
 | 
			
		||||
      },
 | 
			
		||||
      COMMAND_PRIORITY_CRITICAL
 | 
			
		||||
    )
 | 
			
		||||
  }, [editor])
 | 
			
		||||
 | 
			
		||||
  const format = (formatType: "bold" | "italic" | "underline" | "strikethrough") => {
 | 
			
		||||
    editor.dispatchCommand(FORMAT_TEXT_COMMAND, formatType)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const setHeading = (tag: "h1" | "h2" | "h3" | "paragraph") => {
 | 
			
		||||
    editor.update(() => {
 | 
			
		||||
      const selection = $getSelection()
 | 
			
		||||
      if ($isRangeSelection(selection)) {
 | 
			
		||||
        if (tag === "paragraph") {
 | 
			
		||||
          $setBlocksType(selection, () => $createParagraphNode())
 | 
			
		||||
        } else {
 | 
			
		||||
          $setBlocksType(selection, () => $createHeadingNode(tag))
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const insertQuote = () => {
 | 
			
		||||
    editor.update(() => {
 | 
			
		||||
      const selection = $getSelection()
 | 
			
		||||
      if ($isRangeSelection(selection)) {
 | 
			
		||||
        $setBlocksType(selection, () => $createQuoteNode())
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const insertCodeBlock = () => {
 | 
			
		||||
    editor.update(() => {
 | 
			
		||||
      const selection = $getSelection()
 | 
			
		||||
      if ($isRangeSelection(selection)) {
 | 
			
		||||
        $setBlocksType(selection, () => $createCodeNode())
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const insertBulletList = () => {
 | 
			
		||||
    editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const removeList = () => {
 | 
			
		||||
    editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const toggleLink = () => {
 | 
			
		||||
    editor.dispatchCommand(TOGGLE_LINK_COMMAND, {
 | 
			
		||||
      url: "https://example.com", // optional: replace with modal input
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <div className="flex flex-wrap gap-2 border-b pb-2 mb-2">
 | 
			
		||||
      <Button type="button" variant="outline" size="sm" onClick={() => format("bold")}>
 | 
			
		||||
        Bold
 | 
			
		||||
      </Button>
 | 
			
		||||
      <Button type="button" variant="outline" size="sm" onClick={() => format("italic")}>
 | 
			
		||||
        Italic
 | 
			
		||||
      </Button>
 | 
			
		||||
      <Button type="button" variant="outline" size="sm" onClick={() => format("underline")}>
 | 
			
		||||
        Underline
 | 
			
		||||
      </Button>
 | 
			
		||||
      <Button type="button" variant="outline" size="sm" onClick={() => format("strikethrough")}>
 | 
			
		||||
        Strike
 | 
			
		||||
      </Button>
 | 
			
		||||
      <Button type="button" variant="ghost" size="sm" onClick={() => setHeading("paragraph")}>
 | 
			
		||||
        P
 | 
			
		||||
      </Button>
 | 
			
		||||
      <Button type="button" variant="ghost" size="sm" onClick={() => setHeading("h1")}>
 | 
			
		||||
        H1
 | 
			
		||||
      </Button>
 | 
			
		||||
      <Button type="button" variant="ghost" size="sm" onClick={() => setHeading("h2")}>
 | 
			
		||||
        H2
 | 
			
		||||
      </Button>
 | 
			
		||||
      <Button type="button" variant="ghost" size="sm" onClick={() => setHeading("h3")}>
 | 
			
		||||
        H3
 | 
			
		||||
      </Button>
 | 
			
		||||
      <Button type="button" variant="outline" size="sm" onClick={insertBulletList}>
 | 
			
		||||
        • List
 | 
			
		||||
      </Button>
 | 
			
		||||
      <Button type="button" variant="outline" size="sm" onClick={removeList}>
 | 
			
		||||
        ⛔ List
 | 
			
		||||
      </Button>
 | 
			
		||||
      <Button type="button" variant="outline" size="sm" onClick={insertQuote}>
 | 
			
		||||
        “ Quote
 | 
			
		||||
      </Button>
 | 
			
		||||
      <Button type="button" variant="outline" size="sm" onClick={insertCodeBlock}>
 | 
			
		||||
        Code
 | 
			
		||||
      </Button>
 | 
			
		||||
      <Button type="button" variant="outline" size="sm" onClick={toggleLink}>
 | 
			
		||||
        🔗 Link
 | 
			
		||||
      </Button>
 | 
			
		||||
    </div>
 | 
			
		||||
  )
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										13
									
								
								src/components/ui/blockquote-node-static.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/components/ui/blockquote-node-static.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,13 @@
 | 
			
		||||
import * as React from 'react';
 | 
			
		||||
 | 
			
		||||
import { type SlateElementProps, SlateElement } from 'platejs';
 | 
			
		||||
 | 
			
		||||
export function BlockquoteElementStatic(props: SlateElementProps) {
 | 
			
		||||
  return (
 | 
			
		||||
    <SlateElement
 | 
			
		||||
      as="blockquote"
 | 
			
		||||
      className="my-1 border-l-2 pl-6 italic"
 | 
			
		||||
      {...props}
 | 
			
		||||
    />
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										13
									
								
								src/components/ui/blockquote-node.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/components/ui/blockquote-node.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,13 @@
 | 
			
		||||
'use client';
 | 
			
		||||
 | 
			
		||||
import { type PlateElementProps, PlateElement } from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
export function BlockquoteElement(props: PlateElementProps) {
 | 
			
		||||
  return (
 | 
			
		||||
    <PlateElement
 | 
			
		||||
      as="blockquote"
 | 
			
		||||
      className="my-1 border-l-2 pl-6 italic"
 | 
			
		||||
      {...props}
 | 
			
		||||
    />
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										17
									
								
								src/components/ui/code-node-static.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/components/ui/code-node-static.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
			
		||||
import * as React from 'react';
 | 
			
		||||
 | 
			
		||||
import type { SlateLeafProps } from 'platejs';
 | 
			
		||||
 | 
			
		||||
import { SlateLeaf } from 'platejs';
 | 
			
		||||
 | 
			
		||||
export function CodeLeafStatic(props: SlateLeafProps) {
 | 
			
		||||
  return (
 | 
			
		||||
    <SlateLeaf
 | 
			
		||||
      {...props}
 | 
			
		||||
      as="code"
 | 
			
		||||
      className="rounded-md bg-muted px-[0.3em] py-[0.2em] font-mono text-sm whitespace-pre-wrap"
 | 
			
		||||
    >
 | 
			
		||||
      {props.children}
 | 
			
		||||
    </SlateLeaf>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								src/components/ui/code-node.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/components/ui/code-node.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
			
		||||
'use client';
 | 
			
		||||
 | 
			
		||||
import * as React from 'react';
 | 
			
		||||
 | 
			
		||||
import type { PlateLeafProps } from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
import { PlateLeaf } from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
export function CodeLeaf(props: PlateLeafProps) {
 | 
			
		||||
  return (
 | 
			
		||||
    <PlateLeaf
 | 
			
		||||
      {...props}
 | 
			
		||||
      as="code"
 | 
			
		||||
      className="rounded-md bg-muted px-[0.3em] py-[0.2em] font-mono text-sm whitespace-pre-wrap"
 | 
			
		||||
    >
 | 
			
		||||
      {props.children}
 | 
			
		||||
    </PlateLeaf>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										55
									
								
								src/components/ui/editor-static.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								src/components/ui/editor-static.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,55 @@
 | 
			
		||||
import * as React from 'react';
 | 
			
		||||
 | 
			
		||||
import type { VariantProps } from 'class-variance-authority';
 | 
			
		||||
 | 
			
		||||
import { cva } from 'class-variance-authority';
 | 
			
		||||
import { type PlateStaticProps, PlateStatic } from 'platejs';
 | 
			
		||||
 | 
			
		||||
import { cn } from '@/lib/utils';
 | 
			
		||||
 | 
			
		||||
export const editorVariants = cva(
 | 
			
		||||
  cn(
 | 
			
		||||
    'group/editor',
 | 
			
		||||
    'relative w-full cursor-text overflow-x-hidden break-words whitespace-pre-wrap select-text',
 | 
			
		||||
    'rounded-md ring-offset-background focus-visible:outline-none',
 | 
			
		||||
    'placeholder:text-muted-foreground/80 **:data-slate-placeholder:top-[auto_!important] **:data-slate-placeholder:text-muted-foreground/80 **:data-slate-placeholder:opacity-100!',
 | 
			
		||||
    '[&_strong]:font-bold'
 | 
			
		||||
  ),
 | 
			
		||||
  {
 | 
			
		||||
    defaultVariants: {
 | 
			
		||||
      variant: 'none',
 | 
			
		||||
    },
 | 
			
		||||
    variants: {
 | 
			
		||||
      disabled: {
 | 
			
		||||
        true: 'cursor-not-allowed opacity-50',
 | 
			
		||||
      },
 | 
			
		||||
      focused: {
 | 
			
		||||
        true: 'ring-2 ring-ring ring-offset-2',
 | 
			
		||||
      },
 | 
			
		||||
      variant: {
 | 
			
		||||
        ai: 'w-full px-0 text-base md:text-sm',
 | 
			
		||||
        aiChat:
 | 
			
		||||
          'max-h-[min(70vh,320px)] w-full max-w-[700px] overflow-y-auto px-5 py-3 text-base md:text-sm',
 | 
			
		||||
        default:
 | 
			
		||||
          'size-full px-16 pt-4 pb-72 text-base sm:px-[max(64px,calc(50%-350px))]',
 | 
			
		||||
        demo: 'size-full px-16 pt-4 pb-72 text-base sm:px-[max(64px,calc(50%-350px))]',
 | 
			
		||||
        fullWidth: 'size-full px-16 pt-4 pb-72 text-base sm:px-24',
 | 
			
		||||
        none: '',
 | 
			
		||||
        select: 'px-3 py-2 text-base data-readonly:w-fit',
 | 
			
		||||
      },
 | 
			
		||||
    },
 | 
			
		||||
  }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
export function EditorStatic({
 | 
			
		||||
  className,
 | 
			
		||||
  variant,
 | 
			
		||||
  ...props
 | 
			
		||||
}: PlateStaticProps & VariantProps<typeof editorVariants>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <PlateStatic
 | 
			
		||||
      className={cn(editorVariants({ variant }), className)}
 | 
			
		||||
      {...props}
 | 
			
		||||
    />
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										129
									
								
								src/components/ui/editor.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										129
									
								
								src/components/ui/editor.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,129 @@
 | 
			
		||||
'use client';
 | 
			
		||||
 | 
			
		||||
import * as React from 'react';
 | 
			
		||||
 | 
			
		||||
import type { VariantProps } from 'class-variance-authority';
 | 
			
		||||
import type { PlateContentProps, PlateViewProps } from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
import { cva } from 'class-variance-authority';
 | 
			
		||||
import { PlateContainer, PlateContent, PlateView } from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
import { cn } from '@/lib/utils';
 | 
			
		||||
 | 
			
		||||
const editorContainerVariants = cva(
 | 
			
		||||
  'relative w-full cursor-text overflow-y-auto caret-primary select-text selection:bg-brand/25 focus-visible:outline-none [&_.slate-selection-area]:z-50 [&_.slate-selection-area]:border [&_.slate-selection-area]:border-brand/25 [&_.slate-selection-area]:bg-brand/15',
 | 
			
		||||
  {
 | 
			
		||||
    defaultVariants: {
 | 
			
		||||
      variant: 'default',
 | 
			
		||||
    },
 | 
			
		||||
    variants: {
 | 
			
		||||
      variant: {
 | 
			
		||||
        comment: cn(
 | 
			
		||||
          'flex flex-wrap justify-between gap-1 px-1 py-0.5 text-sm',
 | 
			
		||||
          'rounded-md border-[1.5px] border-transparent bg-transparent',
 | 
			
		||||
          'has-[[data-slate-editor]:focus]:border-brand/50 has-[[data-slate-editor]:focus]:ring-2 has-[[data-slate-editor]:focus]:ring-brand/30',
 | 
			
		||||
          'has-aria-disabled:border-input has-aria-disabled:bg-muted'
 | 
			
		||||
        ),
 | 
			
		||||
        default: 'h-full',
 | 
			
		||||
        demo: 'h-[650px]',
 | 
			
		||||
        select: cn(
 | 
			
		||||
          'group rounded-md border border-input ring-offset-background focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2',
 | 
			
		||||
          'has-data-readonly:w-fit has-data-readonly:cursor-default has-data-readonly:border-transparent has-data-readonly:focus-within:[box-shadow:none]'
 | 
			
		||||
        ),
 | 
			
		||||
      },
 | 
			
		||||
    },
 | 
			
		||||
  }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
export function EditorContainer({
 | 
			
		||||
  className,
 | 
			
		||||
  variant,
 | 
			
		||||
  ...props
 | 
			
		||||
}: React.ComponentProps<'div'> & VariantProps<typeof editorContainerVariants>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <PlateContainer
 | 
			
		||||
      className={cn(
 | 
			
		||||
        'ignore-click-outside/toolbar',
 | 
			
		||||
        editorContainerVariants({ variant }),
 | 
			
		||||
        className
 | 
			
		||||
      )}
 | 
			
		||||
      {...props}
 | 
			
		||||
    />
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const editorVariants = cva(
 | 
			
		||||
  cn(
 | 
			
		||||
    'group/editor',
 | 
			
		||||
    'relative w-full cursor-text overflow-x-hidden break-words whitespace-pre-wrap select-text',
 | 
			
		||||
    'rounded-md ring-offset-background focus-visible:outline-none',
 | 
			
		||||
    'placeholder:text-muted-foreground/80 **:data-slate-placeholder:!top-1/2 **:data-slate-placeholder:-translate-y-1/2 **:data-slate-placeholder:text-muted-foreground/80 **:data-slate-placeholder:opacity-100!',
 | 
			
		||||
    '[&_strong]:font-bold'
 | 
			
		||||
  ),
 | 
			
		||||
  {
 | 
			
		||||
    defaultVariants: {
 | 
			
		||||
      variant: 'default',
 | 
			
		||||
    },
 | 
			
		||||
    variants: {
 | 
			
		||||
      disabled: {
 | 
			
		||||
        true: 'cursor-not-allowed opacity-50',
 | 
			
		||||
      },
 | 
			
		||||
      focused: {
 | 
			
		||||
        true: 'ring-2 ring-ring ring-offset-2',
 | 
			
		||||
      },
 | 
			
		||||
      variant: {
 | 
			
		||||
        ai: 'w-full px-0 text-base md:text-sm',
 | 
			
		||||
        aiChat:
 | 
			
		||||
          'max-h-[min(70vh,320px)] w-full max-w-[700px] overflow-y-auto px-3 py-2 text-base md:text-sm',
 | 
			
		||||
        comment: cn('rounded-none border-none bg-transparent text-sm'),
 | 
			
		||||
        default:
 | 
			
		||||
          'size-full px-16 pt-4 pb-72 text-base sm:px-[max(64px,calc(50%-350px))]',
 | 
			
		||||
        demo: 'size-full px-16 pt-4 pb-72 text-base sm:px-[max(64px,calc(50%-350px))]',
 | 
			
		||||
        fullWidth: 'size-full px-16 pt-4 pb-72 text-base sm:px-24',
 | 
			
		||||
        none: '',
 | 
			
		||||
        select: 'px-3 py-2 text-base data-readonly:w-fit',
 | 
			
		||||
      },
 | 
			
		||||
    },
 | 
			
		||||
  }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
export type EditorProps = PlateContentProps &
 | 
			
		||||
  VariantProps<typeof editorVariants>;
 | 
			
		||||
 | 
			
		||||
export const Editor = React.forwardRef<HTMLDivElement, EditorProps>(
 | 
			
		||||
  ({ className, disabled, focused, variant, ...props }, ref) => {
 | 
			
		||||
    return (
 | 
			
		||||
      <PlateContent
 | 
			
		||||
        ref={ref}
 | 
			
		||||
        className={cn(
 | 
			
		||||
          editorVariants({
 | 
			
		||||
            disabled,
 | 
			
		||||
            focused,
 | 
			
		||||
            variant,
 | 
			
		||||
          }),
 | 
			
		||||
          className
 | 
			
		||||
        )}
 | 
			
		||||
        disabled={disabled}
 | 
			
		||||
        disableDefaultStyles
 | 
			
		||||
        {...props}
 | 
			
		||||
      />
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
Editor.displayName = 'Editor';
 | 
			
		||||
 | 
			
		||||
export function EditorView({
 | 
			
		||||
  className,
 | 
			
		||||
  variant,
 | 
			
		||||
  ...props
 | 
			
		||||
}: PlateViewProps & VariantProps<typeof editorVariants>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <PlateView
 | 
			
		||||
      {...props}
 | 
			
		||||
      className={cn(editorVariants({ variant }), className)}
 | 
			
		||||
    />
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
EditorView.displayName = 'EditorView';
 | 
			
		||||
							
								
								
									
										17
									
								
								src/components/ui/fixed-toolbar.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/components/ui/fixed-toolbar.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
			
		||||
'use client';
 | 
			
		||||
 | 
			
		||||
import { cn } from '@/lib/utils';
 | 
			
		||||
 | 
			
		||||
import { Toolbar } from './toolbar';
 | 
			
		||||
 | 
			
		||||
export function FixedToolbar(props: React.ComponentProps<typeof Toolbar>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <Toolbar
 | 
			
		||||
      {...props}
 | 
			
		||||
      className={cn(
 | 
			
		||||
        'sticky top-0 left-0 z-50 scrollbar-hide w-full justify-between overflow-x-auto rounded-t-lg border-b border-b-border bg-background/95 p-1 backdrop-blur-sm supports-backdrop-blur:bg-background/60',
 | 
			
		||||
        props.className
 | 
			
		||||
      )}
 | 
			
		||||
    />
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										68
									
								
								src/components/ui/heading-node-static.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								src/components/ui/heading-node-static.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,68 @@
 | 
			
		||||
import * as React from 'react';
 | 
			
		||||
 | 
			
		||||
import type { SlateElementProps } from 'platejs';
 | 
			
		||||
 | 
			
		||||
import { type VariantProps, cva } from 'class-variance-authority';
 | 
			
		||||
import { SlateElement } from 'platejs';
 | 
			
		||||
 | 
			
		||||
const headingVariants = cva('relative mb-1', {
 | 
			
		||||
  variants: {
 | 
			
		||||
    variant: {
 | 
			
		||||
      h1: 'mt-[1.6em] pb-1 font-heading text-4xl font-bold',
 | 
			
		||||
      h2: 'mt-[1.4em] pb-px font-heading text-2xl font-semibold tracking-tight',
 | 
			
		||||
      h3: 'mt-[1em] pb-px font-heading text-xl font-semibold tracking-tight',
 | 
			
		||||
      h4: 'mt-[0.75em] font-heading text-lg font-semibold tracking-tight',
 | 
			
		||||
      h5: 'mt-[0.75em] text-lg font-semibold tracking-tight',
 | 
			
		||||
      h6: 'mt-[0.75em] text-base font-semibold tracking-tight',
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
export function HeadingElementStatic({
 | 
			
		||||
  variant = 'h1',
 | 
			
		||||
  ...props
 | 
			
		||||
}: SlateElementProps & VariantProps<typeof headingVariants>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <SlateElement
 | 
			
		||||
      as={variant!}
 | 
			
		||||
      className={headingVariants({ variant })}
 | 
			
		||||
      {...props}
 | 
			
		||||
    >
 | 
			
		||||
      {props.children}
 | 
			
		||||
    </SlateElement>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function H1ElementStatic(props: SlateElementProps) {
 | 
			
		||||
  return <HeadingElementStatic variant="h1" {...props} />;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function H2ElementStatic(
 | 
			
		||||
  props: React.ComponentProps<typeof HeadingElementStatic>
 | 
			
		||||
) {
 | 
			
		||||
  return <HeadingElementStatic variant="h2" {...props} />;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function H3ElementStatic(
 | 
			
		||||
  props: React.ComponentProps<typeof HeadingElementStatic>
 | 
			
		||||
) {
 | 
			
		||||
  return <HeadingElementStatic variant="h3" {...props} />;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function H4ElementStatic(
 | 
			
		||||
  props: React.ComponentProps<typeof HeadingElementStatic>
 | 
			
		||||
) {
 | 
			
		||||
  return <HeadingElementStatic variant="h4" {...props} />;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function H5ElementStatic(
 | 
			
		||||
  props: React.ComponentProps<typeof HeadingElementStatic>
 | 
			
		||||
) {
 | 
			
		||||
  return <HeadingElementStatic variant="h5" {...props} />;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function H6ElementStatic(
 | 
			
		||||
  props: React.ComponentProps<typeof HeadingElementStatic>
 | 
			
		||||
) {
 | 
			
		||||
  return <HeadingElementStatic variant="h6" {...props} />;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										60
									
								
								src/components/ui/heading-node.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								src/components/ui/heading-node.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,60 @@
 | 
			
		||||
'use client';
 | 
			
		||||
 | 
			
		||||
import * as React from 'react';
 | 
			
		||||
 | 
			
		||||
import type { PlateElementProps } from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
import { type VariantProps, cva } from 'class-variance-authority';
 | 
			
		||||
import { PlateElement } from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
const headingVariants = cva('relative mb-1', {
 | 
			
		||||
  variants: {
 | 
			
		||||
    variant: {
 | 
			
		||||
      h1: 'mt-[1.6em] pb-1 font-heading text-4xl font-bold',
 | 
			
		||||
      h2: 'mt-[1.4em] pb-px font-heading text-2xl font-semibold tracking-tight',
 | 
			
		||||
      h3: 'mt-[1em] pb-px font-heading text-xl font-semibold tracking-tight',
 | 
			
		||||
      h4: 'mt-[0.75em] font-heading text-lg font-semibold tracking-tight',
 | 
			
		||||
      h5: 'mt-[0.75em] text-lg font-semibold tracking-tight',
 | 
			
		||||
      h6: 'mt-[0.75em] text-base font-semibold tracking-tight',
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
export function HeadingElement({
 | 
			
		||||
  variant = 'h1',
 | 
			
		||||
  ...props
 | 
			
		||||
}: PlateElementProps & VariantProps<typeof headingVariants>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <PlateElement
 | 
			
		||||
      as={variant!}
 | 
			
		||||
      className={headingVariants({ variant })}
 | 
			
		||||
      {...props}
 | 
			
		||||
    >
 | 
			
		||||
      {props.children}
 | 
			
		||||
    </PlateElement>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function H1Element(props: PlateElementProps) {
 | 
			
		||||
  return <HeadingElement variant="h1" {...props} />;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function H2Element(props: PlateElementProps) {
 | 
			
		||||
  return <HeadingElement variant="h2" {...props} />;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function H3Element(props: PlateElementProps) {
 | 
			
		||||
  return <HeadingElement variant="h3" {...props} />;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function H4Element(props: PlateElementProps) {
 | 
			
		||||
  return <HeadingElement variant="h4" {...props} />;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function H5Element(props: PlateElementProps) {
 | 
			
		||||
  return <HeadingElement variant="h5" {...props} />;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function H6Element(props: PlateElementProps) {
 | 
			
		||||
  return <HeadingElement variant="h6" {...props} />;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										13
									
								
								src/components/ui/highlight-node-static.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/components/ui/highlight-node-static.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,13 @@
 | 
			
		||||
import * as React from 'react';
 | 
			
		||||
 | 
			
		||||
import type { SlateLeafProps } from 'platejs';
 | 
			
		||||
 | 
			
		||||
import { SlateLeaf } from 'platejs';
 | 
			
		||||
 | 
			
		||||
export function HighlightLeafStatic(props: SlateLeafProps) {
 | 
			
		||||
  return (
 | 
			
		||||
    <SlateLeaf {...props} as="mark" className="bg-highlight/30 text-inherit">
 | 
			
		||||
      {props.children}
 | 
			
		||||
    </SlateLeaf>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										15
									
								
								src/components/ui/highlight-node.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/components/ui/highlight-node.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
			
		||||
'use client';
 | 
			
		||||
 | 
			
		||||
import * as React from 'react';
 | 
			
		||||
 | 
			
		||||
import type { PlateLeafProps } from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
import { PlateLeaf } from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
export function HighlightLeaf(props: PlateLeafProps) {
 | 
			
		||||
  return (
 | 
			
		||||
    <PlateLeaf {...props} as="mark" className="bg-highlight/30 text-inherit">
 | 
			
		||||
      {props.children}
 | 
			
		||||
    </PlateLeaf>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										22
									
								
								src/components/ui/hr-node-static.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/components/ui/hr-node-static.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,22 @@
 | 
			
		||||
import * as React from 'react';
 | 
			
		||||
 | 
			
		||||
import type { SlateElementProps } from 'platejs';
 | 
			
		||||
 | 
			
		||||
import { SlateElement } from 'platejs';
 | 
			
		||||
 | 
			
		||||
import { cn } from '@/lib/utils';
 | 
			
		||||
 | 
			
		||||
export function HrElementStatic(props: SlateElementProps) {
 | 
			
		||||
  return (
 | 
			
		||||
    <SlateElement {...props}>
 | 
			
		||||
      <div className="cursor-text py-6" contentEditable={false}>
 | 
			
		||||
        <hr
 | 
			
		||||
          className={cn(
 | 
			
		||||
            'h-0.5 rounded-sm border-none bg-muted bg-clip-content'
 | 
			
		||||
          )}
 | 
			
		||||
        />
 | 
			
		||||
      </div>
 | 
			
		||||
      {props.children}
 | 
			
		||||
    </SlateElement>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										35
									
								
								src/components/ui/hr-node.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/components/ui/hr-node.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,35 @@
 | 
			
		||||
'use client';
 | 
			
		||||
 | 
			
		||||
import * as React from 'react';
 | 
			
		||||
 | 
			
		||||
import type { PlateElementProps } from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
import {
 | 
			
		||||
  PlateElement,
 | 
			
		||||
  useFocused,
 | 
			
		||||
  useReadOnly,
 | 
			
		||||
  useSelected,
 | 
			
		||||
} from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
import { cn } from '@/lib/utils';
 | 
			
		||||
 | 
			
		||||
export function HrElement(props: PlateElementProps) {
 | 
			
		||||
  const readOnly = useReadOnly();
 | 
			
		||||
  const selected = useSelected();
 | 
			
		||||
  const focused = useFocused();
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <PlateElement {...props}>
 | 
			
		||||
      <div className="py-6" contentEditable={false}>
 | 
			
		||||
        <hr
 | 
			
		||||
          className={cn(
 | 
			
		||||
            'h-0.5 rounded-sm border-none bg-muted bg-clip-content',
 | 
			
		||||
            selected && focused && 'ring-2 ring-ring ring-offset-2',
 | 
			
		||||
            !readOnly && 'cursor-pointer'
 | 
			
		||||
          )}
 | 
			
		||||
        />
 | 
			
		||||
      </div>
 | 
			
		||||
      {props.children}
 | 
			
		||||
    </PlateElement>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										17
									
								
								src/components/ui/kbd-node-static.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/components/ui/kbd-node-static.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
			
		||||
import * as React from 'react';
 | 
			
		||||
 | 
			
		||||
import type { SlateLeafProps } from 'platejs';
 | 
			
		||||
 | 
			
		||||
import { SlateLeaf } from 'platejs';
 | 
			
		||||
 | 
			
		||||
export function KbdLeafStatic(props: SlateLeafProps) {
 | 
			
		||||
  return (
 | 
			
		||||
    <SlateLeaf
 | 
			
		||||
      {...props}
 | 
			
		||||
      as="kbd"
 | 
			
		||||
      className="rounded border border-border bg-muted px-1.5 py-0.5 font-mono text-sm shadow-[rgba(255,_255,_255,_0.1)_0px_0.5px_0px_0px_inset,_rgb(248,_249,_250)_0px_1px_5px_0px_inset,_rgb(193,_200,_205)_0px_0px_0px_0.5px,_rgb(193,_200,_205)_0px_2px_1px_-1px,_rgb(193,_200,_205)_0px_1px_0px_0px] dark:shadow-[rgba(255,_255,_255,_0.1)_0px_0.5px_0px_0px_inset,_rgb(26,_29,_30)_0px_1px_5px_0px_inset,_rgb(76,_81,_85)_0px_0px_0px_0.5px,_rgb(76,_81,_85)_0px_2px_1px_-1px,_rgb(76,_81,_85)_0px_1px_0px_0px]"
 | 
			
		||||
    >
 | 
			
		||||
      {props.children}
 | 
			
		||||
    </SlateLeaf>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								src/components/ui/kbd-node.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/components/ui/kbd-node.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
			
		||||
'use client';
 | 
			
		||||
 | 
			
		||||
import * as React from 'react';
 | 
			
		||||
 | 
			
		||||
import type { PlateLeafProps } from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
import { PlateLeaf } from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
export function KbdLeaf(props: PlateLeafProps) {
 | 
			
		||||
  return (
 | 
			
		||||
    <PlateLeaf
 | 
			
		||||
      {...props}
 | 
			
		||||
      as="kbd"
 | 
			
		||||
      className="rounded border border-border bg-muted px-1.5 py-0.5 font-mono text-sm shadow-[rgba(255,_255,_255,_0.1)_0px_0.5px_0px_0px_inset,_rgb(248,_249,_250)_0px_1px_5px_0px_inset,_rgb(193,_200,_205)_0px_0px_0px_0.5px,_rgb(193,_200,_205)_0px_2px_1px_-1px,_rgb(193,_200,_205)_0px_1px_0px_0px] dark:shadow-[rgba(255,_255,_255,_0.1)_0px_0.5px_0px_0px_inset,_rgb(26,_29,_30)_0px_1px_5px_0px_inset,_rgb(76,_81,_85)_0px_0px_0px_0.5px,_rgb(76,_81,_85)_0px_2px_1px_-1px,_rgb(76,_81,_85)_0px_1px_0px_0px]"
 | 
			
		||||
    >
 | 
			
		||||
      {props.children}
 | 
			
		||||
    </PlateLeaf>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										21
									
								
								src/components/ui/mark-toolbar-button.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/components/ui/mark-toolbar-button.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,21 @@
 | 
			
		||||
'use client';
 | 
			
		||||
 | 
			
		||||
import * as React from 'react';
 | 
			
		||||
 | 
			
		||||
import { useMarkToolbarButton, useMarkToolbarButtonState } from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
import { ToolbarButton } from './toolbar';
 | 
			
		||||
 | 
			
		||||
export function MarkToolbarButton({
 | 
			
		||||
  clear,
 | 
			
		||||
  nodeType,
 | 
			
		||||
  ...props
 | 
			
		||||
}: React.ComponentProps<typeof ToolbarButton> & {
 | 
			
		||||
  nodeType: string;
 | 
			
		||||
  clear?: string[] | string;
 | 
			
		||||
}) {
 | 
			
		||||
  const state = useMarkToolbarButtonState({ clear, nodeType });
 | 
			
		||||
  const { props: buttonProps } = useMarkToolbarButton(state);
 | 
			
		||||
 | 
			
		||||
  return <ToolbarButton {...props} {...buttonProps} />;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										15
									
								
								src/components/ui/paragraph-node-static.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/components/ui/paragraph-node-static.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
			
		||||
import * as React from 'react';
 | 
			
		||||
 | 
			
		||||
import type { SlateElementProps } from 'platejs';
 | 
			
		||||
 | 
			
		||||
import { SlateElement } from 'platejs';
 | 
			
		||||
 | 
			
		||||
import { cn } from '@/lib/utils';
 | 
			
		||||
 | 
			
		||||
export function ParagraphElementStatic(props: SlateElementProps) {
 | 
			
		||||
  return (
 | 
			
		||||
    <SlateElement {...props} className={cn('m-0 px-0 py-1')}>
 | 
			
		||||
      {props.children}
 | 
			
		||||
    </SlateElement>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										17
									
								
								src/components/ui/paragraph-node.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/components/ui/paragraph-node.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
			
		||||
'use client';
 | 
			
		||||
 | 
			
		||||
import * as React from 'react';
 | 
			
		||||
 | 
			
		||||
import type { PlateElementProps } from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
import { PlateElement } from 'platejs/react';
 | 
			
		||||
 | 
			
		||||
import { cn } from '@/lib/utils';
 | 
			
		||||
 | 
			
		||||
export function ParagraphElement(props: PlateElementProps) {
 | 
			
		||||
  return (
 | 
			
		||||
    <PlateElement {...props} className={cn('m-0 px-0 py-1')}>
 | 
			
		||||
      {props.children}
 | 
			
		||||
    </PlateElement>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										28
									
								
								src/components/ui/separator.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/components/ui/separator.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,28 @@
 | 
			
		||||
"use client"
 | 
			
		||||
 | 
			
		||||
import * as React from "react"
 | 
			
		||||
import * as SeparatorPrimitive from "@radix-ui/react-separator"
 | 
			
		||||
 | 
			
		||||
import { cn } from "@/lib/utils"
 | 
			
		||||
 | 
			
		||||
function Separator({
 | 
			
		||||
  className,
 | 
			
		||||
  orientation = "horizontal",
 | 
			
		||||
  decorative = true,
 | 
			
		||||
  ...props
 | 
			
		||||
}: React.ComponentProps<typeof SeparatorPrimitive.Root>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <SeparatorPrimitive.Root
 | 
			
		||||
      data-slot="separator"
 | 
			
		||||
      decorative={decorative}
 | 
			
		||||
      orientation={orientation}
 | 
			
		||||
      className={cn(
 | 
			
		||||
        "bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",
 | 
			
		||||
        className
 | 
			
		||||
      )}
 | 
			
		||||
      {...props}
 | 
			
		||||
    />
 | 
			
		||||
  )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export { Separator }
 | 
			
		||||
							
								
								
									
										389
									
								
								src/components/ui/toolbar.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										389
									
								
								src/components/ui/toolbar.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,389 @@
 | 
			
		||||
'use client';
 | 
			
		||||
 | 
			
		||||
import * as React from 'react';
 | 
			
		||||
 | 
			
		||||
import * as ToolbarPrimitive from '@radix-ui/react-toolbar';
 | 
			
		||||
import * as TooltipPrimitive from '@radix-ui/react-tooltip';
 | 
			
		||||
import { type VariantProps, cva } from 'class-variance-authority';
 | 
			
		||||
import { ChevronDown } from 'lucide-react';
 | 
			
		||||
 | 
			
		||||
import {
 | 
			
		||||
  DropdownMenuLabel,
 | 
			
		||||
  DropdownMenuRadioGroup,
 | 
			
		||||
  DropdownMenuSeparator,
 | 
			
		||||
} from '@/components/ui/dropdown-menu';
 | 
			
		||||
import { Separator } from '@/components/ui/separator';
 | 
			
		||||
import { Tooltip, TooltipTrigger } from '@/components/ui/tooltip';
 | 
			
		||||
import { cn } from '@/lib/utils';
 | 
			
		||||
 | 
			
		||||
export function Toolbar({
 | 
			
		||||
  className,
 | 
			
		||||
  ...props
 | 
			
		||||
}: React.ComponentProps<typeof ToolbarPrimitive.Root>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <ToolbarPrimitive.Root
 | 
			
		||||
      className={cn('relative flex items-center select-none', className)}
 | 
			
		||||
      {...props}
 | 
			
		||||
    />
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function ToolbarToggleGroup({
 | 
			
		||||
  className,
 | 
			
		||||
  ...props
 | 
			
		||||
}: React.ComponentProps<typeof ToolbarPrimitive.ToolbarToggleGroup>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <ToolbarPrimitive.ToolbarToggleGroup
 | 
			
		||||
      className={cn('flex items-center', className)}
 | 
			
		||||
      {...props}
 | 
			
		||||
    />
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function ToolbarLink({
 | 
			
		||||
  className,
 | 
			
		||||
  ...props
 | 
			
		||||
}: React.ComponentProps<typeof ToolbarPrimitive.Link>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <ToolbarPrimitive.Link
 | 
			
		||||
      className={cn('font-medium underline underline-offset-4', className)}
 | 
			
		||||
      {...props}
 | 
			
		||||
    />
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function ToolbarSeparator({
 | 
			
		||||
  className,
 | 
			
		||||
  ...props
 | 
			
		||||
}: React.ComponentProps<typeof ToolbarPrimitive.Separator>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <ToolbarPrimitive.Separator
 | 
			
		||||
      className={cn('mx-2 my-1 w-px shrink-0 bg-border', className)}
 | 
			
		||||
      {...props}
 | 
			
		||||
    />
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// From toggleVariants
 | 
			
		||||
const toolbarButtonVariants = cva(
 | 
			
		||||
  "inline-flex cursor-pointer items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-[color,box-shadow] outline-none hover:bg-muted hover:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-checked:bg-accent aria-checked:text-accent-foreground aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
 | 
			
		||||
  {
 | 
			
		||||
    defaultVariants: {
 | 
			
		||||
      size: 'default',
 | 
			
		||||
      variant: 'default',
 | 
			
		||||
    },
 | 
			
		||||
    variants: {
 | 
			
		||||
      size: {
 | 
			
		||||
        default: 'h-9 min-w-9 px-2',
 | 
			
		||||
        lg: 'h-10 min-w-10 px-2.5',
 | 
			
		||||
        sm: 'h-8 min-w-8 px-1.5',
 | 
			
		||||
      },
 | 
			
		||||
      variant: {
 | 
			
		||||
        default: 'bg-transparent',
 | 
			
		||||
        outline:
 | 
			
		||||
          'border border-input bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground',
 | 
			
		||||
      },
 | 
			
		||||
    },
 | 
			
		||||
  }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
const dropdownArrowVariants = cva(
 | 
			
		||||
  cn(
 | 
			
		||||
    'inline-flex items-center justify-center rounded-r-md text-sm font-medium text-foreground transition-colors disabled:pointer-events-none disabled:opacity-50'
 | 
			
		||||
  ),
 | 
			
		||||
  {
 | 
			
		||||
    defaultVariants: {
 | 
			
		||||
      size: 'sm',
 | 
			
		||||
      variant: 'default',
 | 
			
		||||
    },
 | 
			
		||||
    variants: {
 | 
			
		||||
      size: {
 | 
			
		||||
        default: 'h-9 w-6',
 | 
			
		||||
        lg: 'h-10 w-8',
 | 
			
		||||
        sm: 'h-8 w-4',
 | 
			
		||||
      },
 | 
			
		||||
      variant: {
 | 
			
		||||
        default:
 | 
			
		||||
          'bg-transparent hover:bg-muted hover:text-muted-foreground aria-checked:bg-accent aria-checked:text-accent-foreground',
 | 
			
		||||
        outline:
 | 
			
		||||
          'border border-l-0 border-input bg-transparent hover:bg-accent hover:text-accent-foreground',
 | 
			
		||||
      },
 | 
			
		||||
    },
 | 
			
		||||
  }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
type ToolbarButtonProps = {
 | 
			
		||||
  isDropdown?: boolean;
 | 
			
		||||
  pressed?: boolean;
 | 
			
		||||
} & Omit<
 | 
			
		||||
  React.ComponentPropsWithoutRef<typeof ToolbarToggleItem>,
 | 
			
		||||
  'asChild' | 'value'
 | 
			
		||||
> &
 | 
			
		||||
  VariantProps<typeof toolbarButtonVariants>;
 | 
			
		||||
 | 
			
		||||
export const ToolbarButton = withTooltip(function ToolbarButton({
 | 
			
		||||
  children,
 | 
			
		||||
  className,
 | 
			
		||||
  isDropdown,
 | 
			
		||||
  pressed,
 | 
			
		||||
  size = 'sm',
 | 
			
		||||
  variant,
 | 
			
		||||
  ...props
 | 
			
		||||
}: ToolbarButtonProps) {
 | 
			
		||||
  return typeof pressed === 'boolean' ? (
 | 
			
		||||
    <ToolbarToggleGroup disabled={props.disabled} value="single" type="single">
 | 
			
		||||
      <ToolbarToggleItem
 | 
			
		||||
        className={cn(
 | 
			
		||||
          toolbarButtonVariants({
 | 
			
		||||
            size,
 | 
			
		||||
            variant,
 | 
			
		||||
          }),
 | 
			
		||||
          isDropdown && 'justify-between gap-1 pr-1',
 | 
			
		||||
          className
 | 
			
		||||
        )}
 | 
			
		||||
        value={pressed ? 'single' : ''}
 | 
			
		||||
        {...props}
 | 
			
		||||
      >
 | 
			
		||||
        {isDropdown ? (
 | 
			
		||||
          <>
 | 
			
		||||
            <div className="flex flex-1 items-center gap-2 whitespace-nowrap">
 | 
			
		||||
              {children}
 | 
			
		||||
            </div>
 | 
			
		||||
            <div>
 | 
			
		||||
              <ChevronDown
 | 
			
		||||
                className="size-3.5 text-muted-foreground"
 | 
			
		||||
                data-icon
 | 
			
		||||
              />
 | 
			
		||||
            </div>
 | 
			
		||||
          </>
 | 
			
		||||
        ) : (
 | 
			
		||||
          children
 | 
			
		||||
        )}
 | 
			
		||||
      </ToolbarToggleItem>
 | 
			
		||||
    </ToolbarToggleGroup>
 | 
			
		||||
  ) : (
 | 
			
		||||
    <ToolbarPrimitive.Button
 | 
			
		||||
      className={cn(
 | 
			
		||||
        toolbarButtonVariants({
 | 
			
		||||
          size,
 | 
			
		||||
          variant,
 | 
			
		||||
        }),
 | 
			
		||||
        isDropdown && 'pr-1',
 | 
			
		||||
        className
 | 
			
		||||
      )}
 | 
			
		||||
      {...props}
 | 
			
		||||
    >
 | 
			
		||||
      {children}
 | 
			
		||||
    </ToolbarPrimitive.Button>
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
export function ToolbarSplitButton({
 | 
			
		||||
  className,
 | 
			
		||||
  ...props
 | 
			
		||||
}: React.ComponentPropsWithoutRef<typeof ToolbarButton>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <ToolbarButton
 | 
			
		||||
      className={cn('group flex gap-0 px-0 hover:bg-transparent', className)}
 | 
			
		||||
      {...props}
 | 
			
		||||
    />
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type ToolbarSplitButtonPrimaryProps = Omit<
 | 
			
		||||
  React.ComponentPropsWithoutRef<typeof ToolbarToggleItem>,
 | 
			
		||||
  'value'
 | 
			
		||||
> &
 | 
			
		||||
  VariantProps<typeof toolbarButtonVariants>;
 | 
			
		||||
 | 
			
		||||
export function ToolbarSplitButtonPrimary({
 | 
			
		||||
  children,
 | 
			
		||||
  className,
 | 
			
		||||
  size = 'sm',
 | 
			
		||||
  variant,
 | 
			
		||||
  ...props
 | 
			
		||||
}: ToolbarSplitButtonPrimaryProps) {
 | 
			
		||||
  return (
 | 
			
		||||
    <span
 | 
			
		||||
      className={cn(
 | 
			
		||||
        toolbarButtonVariants({
 | 
			
		||||
          size,
 | 
			
		||||
          variant,
 | 
			
		||||
        }),
 | 
			
		||||
        'rounded-r-none',
 | 
			
		||||
        'group-data-[pressed=true]:bg-accent group-data-[pressed=true]:text-accent-foreground',
 | 
			
		||||
        className
 | 
			
		||||
      )}
 | 
			
		||||
      {...props}
 | 
			
		||||
    >
 | 
			
		||||
      {children}
 | 
			
		||||
    </span>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function ToolbarSplitButtonSecondary({
 | 
			
		||||
  className,
 | 
			
		||||
  size,
 | 
			
		||||
  variant,
 | 
			
		||||
  ...props
 | 
			
		||||
}: React.ComponentPropsWithoutRef<'span'> &
 | 
			
		||||
  VariantProps<typeof dropdownArrowVariants>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <span
 | 
			
		||||
      className={cn(
 | 
			
		||||
        dropdownArrowVariants({
 | 
			
		||||
          size,
 | 
			
		||||
          variant,
 | 
			
		||||
        }),
 | 
			
		||||
        'group-data-[pressed=true]:bg-accent group-data-[pressed=true]:text-accent-foreground',
 | 
			
		||||
        className
 | 
			
		||||
      )}
 | 
			
		||||
      onClick={(e) => e.stopPropagation()}
 | 
			
		||||
      role="button"
 | 
			
		||||
      {...props}
 | 
			
		||||
    >
 | 
			
		||||
      <ChevronDown className="size-3.5 text-muted-foreground" data-icon />
 | 
			
		||||
    </span>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function ToolbarToggleItem({
 | 
			
		||||
  className,
 | 
			
		||||
  size = 'sm',
 | 
			
		||||
  variant,
 | 
			
		||||
  ...props
 | 
			
		||||
}: React.ComponentProps<typeof ToolbarPrimitive.ToggleItem> &
 | 
			
		||||
  VariantProps<typeof toolbarButtonVariants>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <ToolbarPrimitive.ToggleItem
 | 
			
		||||
      className={cn(toolbarButtonVariants({ size, variant }), className)}
 | 
			
		||||
      {...props}
 | 
			
		||||
    />
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function ToolbarGroup({
 | 
			
		||||
  children,
 | 
			
		||||
  className,
 | 
			
		||||
}: React.ComponentProps<'div'>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <div
 | 
			
		||||
      className={cn(
 | 
			
		||||
        'group/toolbar-group',
 | 
			
		||||
        'relative hidden has-[button]:flex',
 | 
			
		||||
        className
 | 
			
		||||
      )}
 | 
			
		||||
    >
 | 
			
		||||
      <div className="flex items-center">{children}</div>
 | 
			
		||||
 | 
			
		||||
      <div className="mx-1.5 py-0.5 group-last/toolbar-group:hidden!">
 | 
			
		||||
        <Separator orientation="vertical" />
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type TooltipProps<T extends React.ElementType> = {
 | 
			
		||||
  tooltip?: React.ReactNode;
 | 
			
		||||
  tooltipContentProps?: Omit<
 | 
			
		||||
    React.ComponentPropsWithoutRef<typeof TooltipContent>,
 | 
			
		||||
    'children'
 | 
			
		||||
  >;
 | 
			
		||||
  tooltipProps?: Omit<
 | 
			
		||||
    React.ComponentPropsWithoutRef<typeof Tooltip>,
 | 
			
		||||
    'children'
 | 
			
		||||
  >;
 | 
			
		||||
  tooltipTriggerProps?: React.ComponentPropsWithoutRef<typeof TooltipTrigger>;
 | 
			
		||||
} & React.ComponentProps<T>;
 | 
			
		||||
 | 
			
		||||
function withTooltip<T extends React.ElementType>(Component: T) {
 | 
			
		||||
  return function ExtendComponent({
 | 
			
		||||
    tooltip,
 | 
			
		||||
    tooltipContentProps,
 | 
			
		||||
    tooltipProps,
 | 
			
		||||
    tooltipTriggerProps,
 | 
			
		||||
    ...props
 | 
			
		||||
  }: TooltipProps<T>) {
 | 
			
		||||
    const [mounted, setMounted] = React.useState(false);
 | 
			
		||||
 | 
			
		||||
    React.useEffect(() => {
 | 
			
		||||
      setMounted(true);
 | 
			
		||||
    }, []);
 | 
			
		||||
 | 
			
		||||
    const component = <Component {...(props as React.ComponentProps<T>)} />;
 | 
			
		||||
 | 
			
		||||
    if (tooltip && mounted) {
 | 
			
		||||
      return (
 | 
			
		||||
        <Tooltip {...tooltipProps}>
 | 
			
		||||
          <TooltipTrigger asChild {...tooltipTriggerProps}>
 | 
			
		||||
            {component}
 | 
			
		||||
          </TooltipTrigger>
 | 
			
		||||
 | 
			
		||||
          <TooltipContent {...tooltipContentProps}>{tooltip}</TooltipContent>
 | 
			
		||||
        </Tooltip>
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return component;
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function TooltipContent({
 | 
			
		||||
  children,
 | 
			
		||||
  className,
 | 
			
		||||
  // CHANGE
 | 
			
		||||
  sideOffset = 4,
 | 
			
		||||
  ...props
 | 
			
		||||
}: React.ComponentProps<typeof TooltipPrimitive.Content>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <TooltipPrimitive.Portal>
 | 
			
		||||
      <TooltipPrimitive.Content
 | 
			
		||||
        className={cn(
 | 
			
		||||
          'z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md bg-primary px-3 py-1.5 text-xs text-balance text-primary-foreground',
 | 
			
		||||
          className
 | 
			
		||||
        )}
 | 
			
		||||
        data-slot="tooltip-content"
 | 
			
		||||
        sideOffset={sideOffset}
 | 
			
		||||
        {...props}
 | 
			
		||||
      >
 | 
			
		||||
        {children}
 | 
			
		||||
        {/* CHANGE */}
 | 
			
		||||
        {/* <TooltipPrimitive.Arrow className="z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-primary fill-primary" /> */}
 | 
			
		||||
      </TooltipPrimitive.Content>
 | 
			
		||||
    </TooltipPrimitive.Portal>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function ToolbarMenuGroup({
 | 
			
		||||
  children,
 | 
			
		||||
  className,
 | 
			
		||||
  label,
 | 
			
		||||
  ...props
 | 
			
		||||
}: React.ComponentProps<typeof DropdownMenuRadioGroup> & { label?: string }) {
 | 
			
		||||
  return (
 | 
			
		||||
    <>
 | 
			
		||||
      <DropdownMenuSeparator
 | 
			
		||||
        className={cn(
 | 
			
		||||
          'hidden',
 | 
			
		||||
          'mb-0 shrink-0 peer-has-[[role=menuitem]]/menu-group:block peer-has-[[role=menuitemradio]]/menu-group:block peer-has-[[role=option]]/menu-group:block'
 | 
			
		||||
        )}
 | 
			
		||||
      />
 | 
			
		||||
 | 
			
		||||
      <DropdownMenuRadioGroup
 | 
			
		||||
        {...props}
 | 
			
		||||
        className={cn(
 | 
			
		||||
          'hidden',
 | 
			
		||||
          'peer/menu-group group/menu-group my-1.5 has-[[role=menuitem]]:block has-[[role=menuitemradio]]:block has-[[role=option]]:block',
 | 
			
		||||
          className
 | 
			
		||||
        )}
 | 
			
		||||
      >
 | 
			
		||||
        {label && (
 | 
			
		||||
          <DropdownMenuLabel className="text-xs font-semibold text-muted-foreground select-none">
 | 
			
		||||
            {label}
 | 
			
		||||
          </DropdownMenuLabel>
 | 
			
		||||
        )}
 | 
			
		||||
        {children}
 | 
			
		||||
      </DropdownMenuRadioGroup>
 | 
			
		||||
    </>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										61
									
								
								src/components/ui/tooltip.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								src/components/ui/tooltip.tsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,61 @@
 | 
			
		||||
"use client"
 | 
			
		||||
 | 
			
		||||
import * as React from "react"
 | 
			
		||||
import * as TooltipPrimitive from "@radix-ui/react-tooltip"
 | 
			
		||||
 | 
			
		||||
import { cn } from "@/lib/utils"
 | 
			
		||||
 | 
			
		||||
function TooltipProvider({
 | 
			
		||||
  delayDuration = 0,
 | 
			
		||||
  ...props
 | 
			
		||||
}: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <TooltipPrimitive.Provider
 | 
			
		||||
      data-slot="tooltip-provider"
 | 
			
		||||
      delayDuration={delayDuration}
 | 
			
		||||
      {...props}
 | 
			
		||||
    />
 | 
			
		||||
  )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function Tooltip({
 | 
			
		||||
  ...props
 | 
			
		||||
}: React.ComponentProps<typeof TooltipPrimitive.Root>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <TooltipProvider>
 | 
			
		||||
      <TooltipPrimitive.Root data-slot="tooltip" {...props} />
 | 
			
		||||
    </TooltipProvider>
 | 
			
		||||
  )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function TooltipTrigger({
 | 
			
		||||
  ...props
 | 
			
		||||
}: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
 | 
			
		||||
  return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function TooltipContent({
 | 
			
		||||
  className,
 | 
			
		||||
  sideOffset = 0,
 | 
			
		||||
  children,
 | 
			
		||||
  ...props
 | 
			
		||||
}: React.ComponentProps<typeof TooltipPrimitive.Content>) {
 | 
			
		||||
  return (
 | 
			
		||||
    <TooltipPrimitive.Portal>
 | 
			
		||||
      <TooltipPrimitive.Content
 | 
			
		||||
        data-slot="tooltip-content"
 | 
			
		||||
        sideOffset={sideOffset}
 | 
			
		||||
        className={cn(
 | 
			
		||||
          "bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",
 | 
			
		||||
          className
 | 
			
		||||
        )}
 | 
			
		||||
        {...props}
 | 
			
		||||
      >
 | 
			
		||||
        {children}
 | 
			
		||||
        <TooltipPrimitive.Arrow className="bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" />
 | 
			
		||||
      </TooltipPrimitive.Content>
 | 
			
		||||
    </TooltipPrimitive.Portal>
 | 
			
		||||
  )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
 | 
			
		||||
		Reference in New Issue
	
	Block a user