Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: platejs editor #377

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
15 changes: 12 additions & 3 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,38 @@ ignorePaths:
- tsconfig.tsbuildinfo
- branch_out
words:
- ANTLR
- Arcjet
- atrule
- callees
- classname
- clsx
- combobox
- commitlint
- compat
- Draggables
- esbenp
- excalidraw
- frontmatter
- healthcheck
- hookform
- ianvs
- ixahmedxi
- ixahmedxii
- jiti
- lockb
- esbenp
- lucide
- mitigations
- neondatabase
- nextjs
- packagejson
- paralleldrive
- Posthog
- prismjs
- protobuf
- ratelimit
- Registrator
- Scroller
- serviceworker
- Shadcn
- Signin
Expand All @@ -45,12 +54,12 @@ words:
- superjson
- tailwindcss
- tanstack
- timeago
- Todos
- trpc
- tsbuildinfo
- tseslint
- typecheck
- udecode
- Uploadthing
- Upstash
- healthcheck
- timeago
95 changes: 74 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@
}
},
"dependencies": {
"@clerk/nextjs": "^5.4.1",
"@clerk/themes": "^2.1.27",
"@clerk/nextjs": "^5.5.2",
"@clerk/themes": "^2.1.29",
"@hookform/resolvers": "^3.9.0",
"@neondatabase/serverless": "^0.9.5",
"@paralleldrive/cuid2": "^2.2.2",
"@radix-ui/colors": "^3.0.0",
"@radix-ui/react-checkbox": "^1.1.1",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-dropdown-menu": "^2.1.1",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-navigation-menu": "^1.2.0",
Expand All @@ -70,28 +71,79 @@
"@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tabs": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.2",
"@react-email/components": "^0.0.25",
"@t3-oss/env-nextjs": "^0.11.1",
"@tanstack/react-query": "^5.54.1",
"@tanstack/react-query": "^5.56.2",
"@trpc/client": "next",
"@trpc/react-query": "next",
"@trpc/server": "next",
"@udecode/cn": "^38.0.1",
"@udecode/plate-alignment": "^38.0.1",
"@udecode/plate-autoformat": "^38.0.1",
"@udecode/plate-basic-marks": "^38.0.1",
"@udecode/plate-block-quote": "^38.0.1",
"@udecode/plate-break": "^38.0.1",
"@udecode/plate-caption": "^38.0.1",
"@udecode/plate-code-block": "^38.0.1",
"@udecode/plate-combobox": "^38.0.1",
"@udecode/plate-comments": "^38.0.1",
"@udecode/plate-common": "^38.0.4",
"@udecode/plate-csv": "^38.0.1",
"@udecode/plate-cursor": "^38.0.0",
"@udecode/plate-date": "^38.0.1",
"@udecode/plate-dnd": "^38.0.0",
"@udecode/plate-docx": "^38.0.1",
"@udecode/plate-emoji": "^38.0.1",
"@udecode/plate-excalidraw": "^38.0.1",
"@udecode/plate-find-replace": "^38.0.0",
"@udecode/plate-floating": "^38.0.1",
"@udecode/plate-font": "^38.0.1",
"@udecode/plate-heading": "^38.0.1",
"@udecode/plate-highlight": "^38.0.1",
"@udecode/plate-horizontal-rule": "^38.0.1",
"@udecode/plate-html": "^38.0.1",
"@udecode/plate-indent": "^38.0.1",
"@udecode/plate-indent-list": "^38.0.1",
"@udecode/plate-juice": "^38.0.1",
"@udecode/plate-kbd": "^38.0.1",
"@udecode/plate-layout": "^38.0.1",
"@udecode/plate-line-height": "^38.0.1",
"@udecode/plate-link": "^38.0.1",
"@udecode/plate-list": "^38.0.1",
"@udecode/plate-markdown": "^38.0.1",
"@udecode/plate-media": "^38.0.1",
"@udecode/plate-mention": "^38.0.1",
"@udecode/plate-node-id": "^38.0.1",
"@udecode/plate-normalizers": "^38.0.1",
"@udecode/plate-paragraph": "^36.0.0",
"@udecode/plate-reset-node": "^38.0.1",
"@udecode/plate-resizable": "^38.0.0",
"@udecode/plate-select": "^38.0.1",
"@udecode/plate-selection": "^38.0.0",
"@udecode/plate-tabbable": "^38.0.1",
"@udecode/plate-table": "^38.0.1",
"@udecode/plate-toggle": "^38.0.1",
"@udecode/plate-trailing-block": "^38.0.1",
"@upstash/redis": "^1.34.0",
"@vercel/analytics": "^1.3.1",
"@vercel/speed-insights": "^1.0.12",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"drizzle-orm": "^0.33.0",
"drizzle-zod": "^0.5.1",
"framer-motion": "^11.5.2",
"framer-motion": "^11.5.4",
"geist": "^1.3.1",
"jiti": "^1.21.6",
"lucide-react": "^0.438.0",
"next": "14.2.8",
"lucide-react": "^0.441.0",
"next": "14.2.11",
"next-mdx-remote": "^5.0.0",
"next-themes": "^0.3.0",
"prismjs": "^1.29.0",
"react": "^18.3.1",
"react-animate-height": "^3.2.3",
"react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^16.0.1",
"react-dom": "^18.3.1",
"react-email": "^3.0.1",
"react-hook-form": "^7.53.0",
Expand All @@ -106,51 +158,52 @@
},
"devDependencies": {
"@changesets/cli": "^2.27.8",
"@commitlint/cli": "^19.4.1",
"@commitlint/config-conventional": "^19.4.1",
"@commitlint/cz-commitlint": "^19.4.0",
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@commitlint/cz-commitlint": "^19.5.0",
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.0",
"@eslint/compat": "^1.1.1",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.9.1",
"@happy-dom/global-registrator": "^15.7.3",
"@eslint/js": "^9.10.0",
"@happy-dom/global-registrator": "^15.7.4",
"@ianvs/prettier-plugin-sort-imports": "^4.3.1",
"@next/eslint-plugin-next": "^14.2.8",
"@next/eslint-plugin-next": "^14.2.11",
"@tailwindcss/aspect-ratio": "^0.4.2",
"@tailwindcss/container-queries": "^0.1.1",
"@tailwindcss/typography": "^0.5.15",
"@total-typescript/ts-reset": "^0.6.1",
"@types/bun": "^1.1.8",
"@types/bun": "^1.1.9",
"@types/eslint": "^9.6.1",
"@types/eslint-config-prettier": "^6.11.3",
"@types/node": "^22.5.4",
"@types/node": "^22.5.5",
"@types/prismjs": "^1.26.4",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"commitizen": "^4.3.0",
"cspell": "^8.14.2",
"drizzle-kit": "^0.24.2",
"eslint": "^9.9.1",
"eslint": "^9.10.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jsdoc": "^50.2.2",
"eslint-plugin-jsdoc": "^50.2.3",
"eslint-plugin-jsx-a11y": "^6.10.0",
"eslint-plugin-react": "^7.35.2",
"eslint-plugin-react": "^7.36.1",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-regexp": "^2.6.0",
"eslint-plugin-security": "^3.0.1",
"eslint-plugin-tailwindcss": "^3.17.4",
"globals": "^15.9.0",
"husky": "^9.1.5",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"markdownlint": "^0.35.0",
"markdownlint-cli": "^0.41.0",
"postcss": "^8.4.45",
"prettier": "^3.3.3",
"prettier-plugin-curly": "^0.2.2",
"prettier-plugin-packagejson": "^2.5.2",
"tailwindcss": "^3.4.10",
"tailwindcss": "^3.4.11",
"tailwindcss-animate": "^1.0.7",
"typescript": "^5.5.4",
"typescript-eslint": "^8.4.0"
"typescript": "^5.6.2",
"typescript-eslint": "^8.5.0"
},
"trustedDependencies": [
"@clerk/shared",
Expand Down
14 changes: 14 additions & 0 deletions src/app/notebook/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import dynamic from 'next/dynamic';

const PlateEditor = dynamic(
() => import('@/editor').then((res) => res.PlateEditor),
{ ssr: false },
);

export default function NotebookPage() {
return (
<div className="mx-auto max-w-3xl py-12">
<PlateEditor />
</div>
);
}
52 changes: 52 additions & 0 deletions src/editor/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use client';

import {
createPlateEditor,
ParagraphPlugin,
Plate,
} from '@udecode/plate-common/react';
import { Editor } from './ui/editor';
import { createPlateUI } from './ui/components';
import { plugins } from './plugins';
import { HEADING_KEYS } from '@udecode/plate-heading';
import type { Value } from '@udecode/plate-common';
import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';

const initialValue = [
{
type: HEADING_KEYS.h1,
children: [{ text: '' }],
},
{
type: ParagraphPlugin.key,
children: [{ text: '' }],
},
];

export const PlateEditor = () => {
const localValue =
typeof window !== 'undefined' && localStorage.getItem('editorContent');

const editor = createPlateEditor({
value: localValue ? (JSON.parse(localValue) as Value) : initialValue,
plugins,
override: {
components: createPlateUI(),
},
});

return (
<DndProvider backend={HTML5Backend}>
<Plate
editor={editor}
onChange={({ value }) => {
console.log(value);
localStorage.setItem('editorContent', JSON.stringify(value));
}}
>
<Editor focusRing={false} variant="ghost" placeholder="Type here..." />
</Plate>
</DndProvider>
);
};
Loading