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

RFC: Headless core components & imperative support #136

Merged
merged 26 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9e171f0
Merge pull request #1 from steven-tey/main
andrewdoro Sep 5, 2023
adce09f
fix: add initial configuration
andrewdoro Sep 5, 2023
c7dfb18
fix: fix types errors
andrewdoro Sep 5, 2023
978a29f
feat: fix app file directory
andrewdoro Sep 5, 2023
feecc7a
fix: fix onHidden callback
andrewdoro Sep 5, 2023
42dc95c
fix: remove unused styles
andrewdoro Sep 5, 2023
2b812ea
Merge pull request #2 from steven-tey/main
andrewdoro Sep 6, 2023
4f3f133
fix: link dropdown
andrewdoro Sep 6, 2023
bf71749
Merge branch 'steven-tey:main' into main
andrewdoro Jan 29, 2024
3521707
feat: refactor composable react components
andrewdoro Feb 4, 2024
faf8c64
feat: add multiple package entries
andrewdoro Feb 7, 2024
3c9e491
feat: use cmdk for command & add syntethic events
andrewdoro Feb 7, 2024
ded1012
fix: fix command item type
andrewdoro Feb 7, 2024
db8eb96
feat: cleanup remaining extensions
andrewdoro Feb 8, 2024
fc0c45d
feat: cleanup next app
andrewdoro Feb 8, 2024
fead332
feat: add wip ai example
andrewdoro Feb 8, 2024
8e60398
chore: disable old novel build
andrewdoro Feb 8, 2024
f03025e
chore: fix more types
andrewdoro Feb 8, 2024
3a56333
fix: add comment for todo
andrewdoro Feb 9, 2024
85ac317
feat: refactor using shadcn ui
andrewdoro Feb 9, 2024
d27a572
fix: add modal to popover
andrewdoro Feb 9, 2024
c2fa92f
feat: add ollama config
andrewdoro Feb 9, 2024
b66afb7
fix: close openai modal
andrewdoro Feb 9, 2024
af2b9a4
fix: add types & cleanup next
andrewdoro Feb 9, 2024
11e41d4
chore: small cleanup components
andrewdoro Feb 9, 2024
fcda444
chore: remove old core
andrewdoro Feb 9, 2024
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
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"next": {
"rootDir": ["apps/*/"]
}
},
"rules": {
"no-unused-vars": "off"
}
}
2 changes: 1 addition & 1 deletion apps/web/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Github } from "@/ui/icons";
import Menu from "@/ui/menu";
import Editor from "@/ui/editor";
import { Editor } from "@novel/tailwind";

export default function Page() {
return (
Expand Down
1 change: 1 addition & 0 deletions apps/web/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
transpilePackages: ["@novel/headless"],
redirects: async () => {
return [
{
Expand Down
3 changes: 2 additions & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"lint": "next lint"
},
"dependencies": {
"@novel/headless": "workspace:^",
"@novel/tailwind": "workspace:^",
"@radix-ui/react-popover": "^1.0.6",
"@tiptap/core": "^2.0.3",
"@tiptap/extension-color": "^2.0.3",
Expand Down Expand Up @@ -41,7 +43,6 @@
"eventsource-parser": "^0.1.0",
"lucide-react": "^0.244.0",
"next": "13.4.8-canary.14",
"novel": "workspace:^",
"openai": "^4.3.1",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
28 changes: 0 additions & 28 deletions apps/web/ui/editor.tsx

This file was deleted.

1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
},
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"check-types": "tsc --noEmit"
},
"peerDependencies": {
Expand Down
9 changes: 2 additions & 7 deletions packages/core/src/ui/editor/plugins/upload-images.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@ const UploadImagesPlugin = () =>
const placeholder = document.createElement("div");
placeholder.setAttribute("class", "img-placeholder");
const image = document.createElement("img");
image.setAttribute(
"class",
"opacity-40 rounded-lg border border-stone-200"
);
image.setAttribute("class", "opacity-40 rounded-lg border border-stone-200");
image.src = src;
placeholder.appendChild(image);
const deco = Decoration.widget(pos + 1, placeholder, {
id,
});
set = set.add(tr.doc, [deco]);
} else if (action && action.remove) {
set = set.remove(
set.find(null, null, (spec) => spec.id == action.remove.id)
);
set = set.remove(set.find(null, null, (spec) => spec.id == action.remove.id));
}
return set;
},
Expand Down
82 changes: 82 additions & 0 deletions packages/headless/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"name": "@novel/headless",
"version": "0.1.19",
"description": "Notion-style WYSIWYG editor with AI-powered autocompletions",
"license": "Apache-2.0",
"main": "src/index.ts",
"scripts": {
"check-types": "tsc --noEmit"
},
"peerDependencies": {
"react": "^18.2.0"
},
"dependencies": {
"@radix-ui/react-popover": "^1.0.6",
"@radix-ui/react-slot": "^1.0.2",
"@tiptap/core": "^2.1.7",
"@tiptap/extension-color": "^2.1.7",
"@tiptap/extension-highlight": "^2.1.7",
"@tiptap/extension-horizontal-rule": "^2.1.7",
"@tiptap/extension-image": "^2.1.7",
"@tiptap/extension-link": "^2.1.7",
"@tiptap/extension-placeholder": "2.0.3",
"@tiptap/extension-task-item": "^2.1.7",
"@tiptap/extension-task-list": "^2.1.7",
"@tiptap/extension-text-style": "^2.1.7",
"@tiptap/extension-underline": "^2.1.7",
"@tiptap/pm": "^2.1.7",
"@tiptap/react": "^2.1.7",
"@tiptap/starter-kit": "^2.1.7",
"@tiptap/suggestion": "^2.1.7",
"@types/node": "18.15.3",
"@types/react": "18.0.28",
"@types/react-dom": "18.0.11",
"@upstash/ratelimit": "^0.4.4",
"@vercel/analytics": "^1.0.2",
"@vercel/blob": "^0.9.3",
"@vercel/kv": "^0.2.2",
"ai": "^2.2.11",
"clsx": "^1.2.1",
"eslint": "8.36.0",
"eslint-config-next": "13.2.4",
"eventsource-parser": "^0.1.0",
"lucide-react": "^0.244.0",
"next": "13.4.20-canary.15",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-markdown": "^8.0.7",
"sonner": "^0.7.0",
"tailwind-merge": "^1.14.0",
"tippy.js": "^6.3.7",
"tiptap-markdown": "^0.8.2",
"typescript": "4.9.5",
"use-debounce": "^9.0.4"
},
"devDependencies": {
"@types/react": "^18.2.5",
"eslint": "^7.32.0",
"postcss": "^8.4.29",
"react": "^18.2.0",
"tailwind-config": "workspace:*",
"tsconfig": "workspace:*",
"tsup": "^7.2.0",
"typescript": "^4.9.4"
},
"author": "Steven Tey <[email protected]>",
"homepage": "https://novel.sh",
"repository": {
"type": "git",
"url": "git+https:/steven-tey/novel.git"
},
"bugs": {
"url": "https:/steven-tey/novel/issues"
},
"keywords": [
"ai",
"novel",
"editor",
"markdown",
"nextjs",
"react"
]
}
36 changes: 36 additions & 0 deletions packages/headless/src/components/bubble/editor-bubble-item.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ComponentPropsWithoutRef, ReactNode } from "react";
import { Slot } from "@radix-ui/react-slot";
import { Editor } from "@tiptap/core";
import useEditor from "../../hooks/useEditor";
interface EditorBubbleItemProps extends ComponentPropsWithoutRef<"button"> {
children: ReactNode;
asChild?: boolean;
command: (editor: Editor) => void;
}

export interface BubbleMenuItem {
name: string;
isActive: (editor: Editor) => boolean;
command: (editor: Editor) => void;
icon: any;
}

const EditorBubbleItem = ({
children,
asChild = false,
command,
...props
}: EditorBubbleItemProps) => {
const { editor } = useEditor();
const Comp = asChild ? Slot : "button";

if (!editor) return null;

return (
<Comp {...props} onClick={() => command(editor)} type='button'>
{children}
</Comp>
);
};

export default EditorBubbleItem;
41 changes: 41 additions & 0 deletions packages/headless/src/components/bubble/editor-bubble.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { BubbleMenuProps, BubbleMenu as Menu, isNodeSelection } from "@tiptap/react";
import useEditor from "../../hooks/useEditor";

type Props = {
onHidden: () => void;
} & BubbleMenuProps;

const BubbleMenu = ({ children, onHidden, ...props }: Props) => {
const { editor } = useEditor();

if (!editor) return null;

const bubbleMenuProps: Omit<BubbleMenuProps, "children"> = {
editor,
shouldShow: ({ editor, state }) => {
const { selection } = state;
const { empty } = selection;

// don't show bubble menu if:
// - the selected node is an image
// - the selection is empty
// - the selection is a node selection (for drag handles)
if (editor.isActive("image") || empty || isNodeSelection(selection)) {
return false;
}
return true;
},
tippyOptions: {
moveTransition: "transform 0.15s ease-out",
onHidden,
},
};

return (
<Menu {...props} {...bubbleMenuProps}>
{children}
</Menu>
);
};

export default BubbleMenu;
35 changes: 35 additions & 0 deletions packages/headless/src/components/command/command-list-item.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ReactNode } from "react";
import { Slot } from "@radix-ui/react-slot";
import useEditor from "../../hooks/useEditor";

export interface CommandListItemProps {
title: string;
description: string;
icon: ReactNode;
active: boolean;
isLoading: boolean;
className: string;
onSelect: () => void;
asChild?: boolean;
children?: ReactNode;
}

const CommandListItem = ({
children,
asChild = false,
onSelect,
...props
}: CommandListItemProps) => {
const { editor } = useEditor();
const Comp = asChild ? Slot : "button";

if (!editor) return null;

return (
<Comp {...props} onClick={onSelect} type='button'>
{children}
</Comp>
);
};

export default CommandListItem;
Loading