Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
malezjaa committed Jan 1, 2024
1 parent 2dbacfc commit f1955cb
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion apps/web/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function Page() {
const [theme, setTheme] = useState<"dark" | "light">("dark");
return (
<div className="m-5">
<Editor onChange={(editor) => console.log(editor.getHTML())} />
<Editor onChange={(editor) => console.log(editor.getJSON())} />

<button onClick={() => setTheme(theme === "dark" ? "light" : "dark")}>
Toggle Theme
Expand Down
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@tiptap/react": "^2.1.13",
"eddies": "workspace:*",
"eddies": "0.0.5",
"lucide-react": "^0.303.0",
"next": "^14.0.3",
"react": "^18.2.0",
Expand Down
16 changes: 13 additions & 3 deletions apps/web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@
"name": "next"
}
],
"lib": ["dom", "dom.iterable", "esnext"],
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"incremental": true,
"resolveJsonModule": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"allowJs": true,
"jsx": "preserve",
"noEmit": true
"noEmit": true,
"skipLibCheck": true,
"strict": false,
"esModuleInterop": true,
"isolatedModules": true
},
"include": [
"next-env.d.ts",
Expand All @@ -21,5 +29,7 @@
"**/*.tsx",
".next/types/**/*.ts"
],
"exclude": ["node_modules"]
"exclude": [
"node_modules"
]
}
2 changes: 1 addition & 1 deletion packages/eddies/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eddies",
"version": "0.0.5",
"version": "0.0.6",
"author": "malezjaa <https://www.github.com/malezjaa>",
"description": "Fully featured, modern and extensible editor",
"homepage": "https://malezjaa.github.io/eddies/",
Expand Down
3 changes: 2 additions & 1 deletion packages/eddies/src/components/bubble-menu/bubble-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Editor, BubbleMenu as TiptapBubbleMenu } from "@tiptap/react";
import { BubbleMenu as TiptapBubbleMenu } from "@tiptap/react";
import { Editor } from "@tiptap/react";
import BubbleButton from "./bubble-button";
import {
BoldIcon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import {
Heading1,
Heading2,
Heading3,
TextQuote,
ListOrdered,
TextIcon,
Code,
CheckSquare,
} from "lucide-react";
import * as Popover from "@radix-ui/react-popover";
import { Dispatch, FC, SetStateAction, useState } from "react";
import { useState } from "react";

export default function NodeSelector({ editor }: { editor: Editor }) {
const [isOpen, setIsOpen] = useState(false);
Expand Down
21 changes: 11 additions & 10 deletions packages/eddies/src/editor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"use client";
import { useEditor, EditorContent } from "@tiptap/react";
import {
useEditor,
EditorContent,
Editor as TiptapEditor,
} from "@tiptap/react";
import { defaultExtensions } from "./extensions";
import Placeholder from "@tiptap/extension-placeholder";
import "./styles/index.css";
Expand All @@ -9,7 +13,8 @@ import BubbleMenu, {
defaultBubbleMenuItems,
} from "./components/bubble-menu/bubble-menu";
import BubbleButton from "./components/bubble-menu/bubble-button";
import { EditorProps, EditorType } from "./types";
import { EditorProps } from "./types";
import { Editor as CoreEditor } from "@tiptap/core";

export function Editor({
initialValue,
Expand All @@ -22,7 +27,7 @@ export function Editor({
limit = showCharacterCount ? 3000 : 0,
menu = true,
bubbleMenuItems = defaultBubbleMenuItems,
onChange = (editor: EditorType) =>
onChange = (editor: CoreEditor) =>
console.log("You should provide an onChange handler to the editor."),
}: EditorProps) {
const editor = useCustomEditor({
Expand Down Expand Up @@ -91,7 +96,7 @@ export const useCustomEditor = ({
editorProps = {},
showCharacterCount = false,
limit = showCharacterCount ? 3000 : 0,
onChange = (editor: EditorType) =>
onChange = (editor: CoreEditor) =>
console.log("You should provide an onChange handler to the editor."),
}: EditorProps) => {
return useEditor({
Expand All @@ -112,11 +117,7 @@ export const useCustomEditor = ({
}),
],
onUpdate: (e) => {
//@ts-ignore
onChange({
...e.editor,
getMarkdown: () => e.editor.storage.markdown.getMarkdown(),
});
onChange(e.editor as TiptapEditor);
},
editorProps: {
...editorProps,
Expand All @@ -128,5 +129,5 @@ export const useCustomEditor = ({
},
},
content: initialValue ?? "",
}) as EditorType;
}) as TiptapEditor;
};
10 changes: 2 additions & 8 deletions packages/eddies/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Extensions, Content, Editor as TiptapEditor } from "@tiptap/react";
import { EditorProps as TiptapEditorProps } from "@tiptap/pm/view";
import { BubbleMenuItem } from "./components/bubble-menu/bubble-menu";
import { Editor as CoreEditor } from "@tiptap/react";

export type EditorProps = {
/**
Expand Down Expand Up @@ -40,7 +41,7 @@ export type EditorProps = {
/**
* Handles the editor's value change.
*/
onChange?: (editor: EditorType) => void | Promise<void>;
onChange?: (editor: CoreEditor) => void | Promise<void>;

/**
* Show character count.
Expand Down Expand Up @@ -72,13 +73,6 @@ export type EditorProps = {
};
};

export type EditorType = TiptapEditor & {
/**
* Returns the markdown representation of the editor's content.
*/
getMarkdown: () => string;
};

export type CustomEditorProps = Pick<
EditorProps,
| "limit"
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f1955cb

Please sign in to comment.