Skip to content

Commit

Permalink
feat: new tiptap
Browse files Browse the repository at this point in the history
  • Loading branch information
cesara committed Dec 15, 2023
1 parent 43232c2 commit 1a93652
Show file tree
Hide file tree
Showing 73 changed files with 12,202 additions and 4,681 deletions.
22 changes: 6 additions & 16 deletions examples/tiptap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,22 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@radix-ui/react-dialog": "^1.0.2",
"@radix-ui/react-popover": "^1.0.2",
"@radix-ui/react-select": "^1.1.1",
"@radix-ui/react-tabs": "^1.0.1",
"@radix-ui/react-tooltip": "^1.0.2",
"@rocicorp/reflect-yjs": "0.0.1",
"@rocicorp/reflect": "^0.38.202311200859",
"@tiptap/extension-collaboration-cursor": "^2.0.4",
"@rocicorp/reflect-yjs": "0.0.1",
"@tiptap/core": "^2.0.4",
"@tiptap/extension-character-count": "^2.0.4",
"@tiptap/extension-collaboration": "^2.0.4",
"@tiptap/extension-collaboration-cursor": "^2.0.4",
"@tiptap/extension-highlight": "^2.0.4",
"@tiptap/extension-image": "^2.0.4",
"@tiptap/extension-link": "^2.0.4",
"@tiptap/extension-placeholder": "^2.0.4",
"@tiptap/extension-task-item": "^2.0.4",
"@tiptap/extension-task-list": "^2.0.4",
"@tiptap/extension-text-align": "^2.0.4",
"@tiptap/extension-typography": "^2.0.4",
"@tiptap/extension-youtube": "^2.0.4",
"@tiptap/pm": "^2.0.4",
"@tiptap/react": "^2.0.4",
"@tiptap/starter-kit": "^2.0.4",
"@types/node": "^20.3.1",
"@types/react-dom": "^18.2.17",
"@types/react": "^18.2.38",
"clsx": "^2.0.0",
"@types/react-dom": "^18.2.17",
"concurrently": "^8.2.2",
"lexical": "^0.11.1",
"nanoid": "^5.0.3",
"next": "^13.5.4",
"typescript": "^5.3.2",
Expand Down
11,356 changes: 11,356 additions & 0 deletions examples/tiptap/public/remixicon.symbol.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 0 additions & 41 deletions examples/tiptap/src/components/Avatars.module.css

This file was deleted.

48 changes: 0 additions & 48 deletions examples/tiptap/src/components/Avatars.tsx

This file was deleted.

15 changes: 0 additions & 15 deletions examples/tiptap/src/components/CustomTaskItem.module.css

This file was deleted.

31 changes: 0 additions & 31 deletions examples/tiptap/src/components/CustomTaskItem.tsx

This file was deleted.

7 changes: 7 additions & 0 deletions examples/tiptap/src/components/MenuBar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.divider {
background-color: rgba(#fff, 0.25);
height: 1.25rem;
margin-left: 0.5rem;
margin-right: 0.75rem;
width: 1px;
}
151 changes: 151 additions & 0 deletions examples/tiptap/src/components/MenuBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
"use client";
import "./MenuBar.css";

import React, { Fragment } from "react";
import { Editor } from "@tiptap/core";

import MenuItem from "./MenuItem";

export type Item = {
icon?: string | undefined;
title?: string | undefined;
action?: () => boolean | undefined;
isActive?: () => boolean | undefined;
type?: "divider" | undefined;
};

export function MenuBar({ editor }: { editor: Editor }) {
const items: Item[] = [
{
icon: "bold",
title: "Bold",
action: () => editor.chain().focus().toggleBold().run(),
isActive: () => editor.isActive("bold"),
},
{
icon: "italic",
title: "Italic",
action: () => editor.chain().focus().toggleItalic().run(),
isActive: () => editor.isActive("italic"),
},
{
icon: "strikethrough",
title: "Strike",
action: () => editor.chain().focus().toggleStrike().run(),
isActive: () => editor.isActive("strike"),
},
{
icon: "code-view",
title: "Code",
action: () => editor.chain().focus().toggleCode().run(),
isActive: () => editor.isActive("code"),
},
{
icon: "mark-pen-line",
title: "Highlight",
action: () => editor.chain().focus().toggleHighlight().run(),
isActive: () => editor.isActive("highlight"),
},
{
type: "divider",
},
{
icon: "h-1",
title: "Heading 1",
action: () => editor.chain().focus().toggleHeading({ level: 1 }).run(),
isActive: () => editor.isActive("heading", { level: 1 }),
},
{
icon: "h-2",
title: "Heading 2",
action: () => editor.chain().focus().toggleHeading({ level: 2 }).run(),
isActive: () => editor.isActive("heading", { level: 2 }),
},
{
icon: "paragraph",
title: "Paragraph",
action: () => editor.chain().focus().setParagraph().run(),
isActive: () => editor.isActive("paragraph"),
},
{
icon: "list-unordered",
title: "Bullet List",
action: () => editor.chain().focus().toggleBulletList().run(),
isActive: () => editor.isActive("bulletList"),
},
{
icon: "list-ordered",
title: "Ordered List",
action: () => editor.chain().focus().toggleOrderedList().run(),
isActive: () => editor.isActive("orderedList"),
},
{
icon: "list-check-2",
title: "Task List",
action: () => editor.chain().focus().toggleTaskList().run(),
isActive: () => editor.isActive("taskList"),
},
{
icon: "code-box-line",
title: "Code Block",
action: () => editor.chain().focus().toggleCodeBlock().run(),
isActive: () => editor.isActive("codeBlock"),
},
{
type: "divider",
},
{
icon: "double-quotes-l",
title: "Blockquote",
action: () => editor.chain().focus().toggleBlockquote().run(),
isActive: () => editor.isActive("blockquote"),
},
{
icon: "separator",
title: "Horizontal Rule",
action: () => editor.chain().focus().setHorizontalRule().run(),
},
{
type: "divider",
},
{
icon: "text-wrap",
title: "Hard Break",
action: () => editor.chain().focus().setHardBreak().run(),
},
{
icon: "format-clear",
title: "Clear Format",
action: () => editor.chain().focus().clearNodes().unsetAllMarks().run(),
},
{
type: "divider",
},
{
icon: "arrow-go-back-line",
title: "Undo",
action: () => editor.chain().focus().undo().run(),
},
{
icon: "arrow-go-forward-line",
title: "Redo",
action: () => editor.chain().focus().redo().run(),
},
];

return (
<div className="editor__header">
{items.map((item, index) => (
<Fragment key={index}>
{item.type === "divider" ? (
<div className="divider" />
) : (
<MenuItem {...item} />
)}
</Fragment>
))}
</div>
);
}

export default MenuBar;
22 changes: 22 additions & 0 deletions examples/tiptap/src/components/MenuItem.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.menu-item {
background-color: transparent;
border: none;
border-radius: 0.4rem;
color: #fff;
cursor: pointer;
height: 1.75rem;
margin-right: 0.25rem;
padding: 0.25rem;
width: 1.75rem;
}

.menu-item svg {
fill: currentColor;
height: 100%;
width: 100%;
}

.menu-item:hover,
.menu-item.is-active {
background-color: #303030;
}
21 changes: 21 additions & 0 deletions examples/tiptap/src/components/MenuItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use client";
import "./MenuItem.css";

import React from "react";

import { Item } from "./MenuBar";
export function MenuItem({ icon, title, action, isActive }: Item) {
return (
<button
className={`menu-item${isActive && isActive() ? " is-active" : ""}`}
onClick={action}
title={title}
>
<svg className="remix">
<use xlinkHref={`/remixicon.symbol.svg#ri-${icon}`} />
</svg>
</button>
);
}

export default MenuItem;
Loading

0 comments on commit 1a93652

Please sign in to comment.