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: Editor Core Packaging and Restructuring #2358

Merged
merged 59 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
0887b69
initialized tiptap component with common tailwind config
Palanikannan1437 Sep 8, 2023
b841df6
added common tailwind config to web
Palanikannan1437 Sep 8, 2023
e9e6f43
merge develop into packaging-tiptap
Palanikannan1437 Sep 19, 2023
8e76809
abstracted upload and delete functions
Palanikannan1437 Sep 19, 2023
35ffb85
removed tiptap pro extension
Palanikannan1437 Sep 19, 2023
e358487
fixed types
Palanikannan1437 Sep 19, 2023
46c7614
Merge branch 'develop' into packaging-tiptap
Palanikannan1437 Sep 19, 2023
7ef1745
removed old tailwind config and fixed plane package imports
Palanikannan1437 Sep 20, 2023
3b9c29c
exported tiptap editor with and without ref
Palanikannan1437 Sep 20, 2023
28697e3
updated package name to @plane/editor
Palanikannan1437 Sep 20, 2023
8e71ce0
finally fixed import errors
Palanikannan1437 Sep 20, 2023
5f8a0c3
Merge branch 'develop' into packaging-tiptap
Palanikannan1437 Sep 20, 2023
448d433
added turbo dependency for tiptap
Palanikannan1437 Sep 21, 2023
f0e246c
reverted back types and fixed tailwind
Palanikannan1437 Sep 22, 2023
fa01dfc
migrated all components to use the common package
Palanikannan1437 Sep 22, 2023
36fd719
removed old tiptap dependency
Palanikannan1437 Sep 22, 2023
0f9aae6
Merge branch 'develop' into packaging-tiptap
Palanikannan1437 Sep 22, 2023
9079fa4
improved dev experience to build the tiptap package before starting d…
Palanikannan1437 Sep 22, 2023
cbb1c18
resolved lock life and missing deps
Palanikannan1437 Sep 22, 2023
bb13f35
fixed dependency issue with react type resolution
Palanikannan1437 Sep 22, 2023
4981c3d
chore: updated pulls build CI for using turbo builds
henit-chobisa Sep 22, 2023
063f4c7
comment editor basic version added
Palanikannan1437 Sep 25, 2023
d639a01
new structure of editor components
Palanikannan1437 Sep 27, 2023
4298b05
refactored editor to not require workspace slug
Palanikannan1437 Sep 28, 2023
efcc7f2
added seperation of extensions and props
Palanikannan1437 Sep 28, 2023
a754300
Merge branch 'develop' into comment-editor
Palanikannan1437 Sep 28, 2023
da86f1a
refactoring to LiteTextEditor and RichTextEditor
Palanikannan1437 Sep 30, 2023
b5228bb
fixed global css issue with highlight js
Palanikannan1437 Oct 2, 2023
3d87a56
refactoring tiptap to core/lite/rich text editor
Palanikannan1437 Oct 2, 2023
de07f63
read only editor support added
Palanikannan1437 Oct 2, 2023
51e2815
replaced all read-only instances
Palanikannan1437 Oct 2, 2023
2c804c8
trimming html at start and end of content added
Palanikannan1437 Oct 2, 2023
b479718
onSubmit on enterkey captured
Palanikannan1437 Oct 2, 2023
857fa18
removed absolute imports from editor/core package
Palanikannan1437 Oct 3, 2023
0080880
removed absolute imports from lite-text-editor
Palanikannan1437 Oct 3, 2023
95e5a30
removed absolute imports from rich-text-editor
Palanikannan1437 Oct 3, 2023
f408eb3
fixed dependencies in editor package
Palanikannan1437 Oct 3, 2023
fc8284d
fixed tailwind config for editor
Palanikannan1437 Oct 3, 2023
ff29c1c
Enter key behaviour added for Comments
Palanikannan1437 Oct 3, 2023
99618e9
fixed modal form issue
Palanikannan1437 Oct 3, 2023
95439fb
added comment editor with fixed menu
Palanikannan1437 Oct 3, 2023
18c9e64
added support for range commands
Palanikannan1437 Oct 3, 2023
2fd9198
modified turbo config for build pipeline of space and web projects
Palanikannan1437 Oct 3, 2023
696a2e9
fixed shift enter behavior for lists
Palanikannan1437 Oct 4, 2023
a9d197c
removed extra margin from access specifiers
Palanikannan1437 Oct 4, 2023
0cf5ad6
Merge branch 'develop' into comment-editor
Palanikannan1437 Oct 4, 2023
a6b0ef2
removed tiptap instance from web
Palanikannan1437 Oct 4, 2023
cfadb5a
fixed bugs returning empty editor boxes
Palanikannan1437 Oct 4, 2023
37d5e83
fixed toggle Underline behvaiour
Palanikannan1437 Oct 5, 2023
6cb9f73
updated bubble menu to use core package's utilities
Palanikannan1437 Oct 9, 2023
8552ef2
added editor/core readme and fixed imports
Palanikannan1437 Oct 9, 2023
d9c3407
fixed ts issues with link plugin
Palanikannan1437 Oct 10, 2023
ede27b7
added usage of common dependance for slash commands
Palanikannan1437 Oct 10, 2023
3ea7ab3
completed core package's documentation
Palanikannan1437 Oct 10, 2023
67fd3e2
fixed tsconfig by removing path aliases
Palanikannan1437 Oct 10, 2023
8ba39dc
Completed readme for rich-text-editor
Palanikannan1437 Oct 10, 2023
2ce9f3b
Added rich text editor documentation
Palanikannan1437 Oct 10, 2023
b6f1cb7
changed readme title of core package
Palanikannan1437 Oct 10, 2023
59d2ce6
Merge branch 'develop' into comment-editor
Palanikannan1437 Oct 12, 2023
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
6 changes: 2 additions & 4 deletions .github/workflows/build-test-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ jobs:
- name: Build Plane's Main App
if: steps.changed-files.outputs.web_any_changed == 'true'
run: |
cd web
yarn
yarn build
yarn build --filter=web

- name: Build Plane's Deploy App
if: steps.changed-files.outputs.deploy_any_changed == 'true'
run: |
cd space
yarn
yarn build
yarn build --filter=space


4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ pnpm-lock.yaml
pnpm-workspace.yaml

.npmrc


## packages
dist
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"workspaces": [
"web",
"space",
"packages/*"
"packages/editor/*",
"packages/eslint-config-custom",
"packages/tailwind-config-custom",
"packages/tsconfig",
"packages/ui"
],
"scripts": {
"build": "turbo run build",
Expand All @@ -25,5 +29,8 @@
"tailwindcss": "^3.3.3",
"turbo": "latest"
},
"resolutions": {
"@types/react": "18.2.0"
},
"packageManager": "[email protected]"
}
42 changes: 42 additions & 0 deletions packages/editor/core/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# README for @plane/editor-core

## Description

The `@plane/editor-core` package serves as the foundation for our editor system. It provides the base functionality for our other editor packages, but it will not be used directly in any of the projects but only for extending other editors.

## Utilities

We provide a wide range of utilities for extending the core itself.

1. Merging classes and custom styling
2. Adding new extensions
3. Adding custom props
4. Base menu items, and their commands

This allows for extensive customization and flexibility in the Editors created using our `editor-core` package.

### Here's a detailed overview of what's exported


## Core features

- **Content Trimming**: The Editor’s content is now automatically trimmed of empty line breaks from the start and end before submitting it to the backend. This ensures cleaner, more consistent data.
- **Value Cleaning**: The Editor’s value is cleaned at the editor core level, eliminating the need for additional validation before sending from our app. This results in cleaner code and less potential for errors.
- **Turbo Pipeline**: We have added a turbo pipeline for both dev and build tasks for the editor package. This results in faster, more efficient development and build processes.

## Base extensions included

- BulletList
- OrderedList
- Blockquote
- Code
- Gapcursor
- Link
- Image
- Basic Marks
- Underline
- TextStyle
- Color
- TaskList
- Markdown
- Table
76 changes: 76 additions & 0 deletions packages/editor/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "@plane/editor-core",
"version": "0.0.1",
"description": "Core Editor that powers Plane",
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.mts",
"files": [
"dist/**/*"
],
"exports": {
".": {
"types": "./dist/index.d.mts",
"import": "./dist/index.mjs",
"module": "./dist/index.mjs"
}
},
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"check-types": "tsc --noEmit"
},
"peerDependencies": {
"react": "^18.2.0",
"react-dom": "18.2.0",
"next": "12.3.2",
"next-themes": "^0.2.1"
},
"dependencies": {
"@blueprintjs/popover2": "^2.0.10",
"@tiptap/core": "^2.1.7",
"@tiptap/extension-color": "^2.1.11",
"@tiptap/extension-image": "^2.1.7",
"@tiptap/extension-link": "^2.1.7",
"@tiptap/extension-table": "^2.1.6",
"@tiptap/extension-table-cell": "^2.1.6",
"@tiptap/extension-table-header": "^2.1.6",
"@tiptap/extension-table-row": "^2.1.6",
"@tiptap/extension-task-item": "^2.1.7",
"@tiptap/extension-task-list": "^2.1.7",
"@tiptap/extension-text-style": "^2.1.11",
"@tiptap/extension-underline": "^2.1.7",
"@tiptap/pm": "^2.1.7",
"@tiptap/react": "^2.1.7",
"@tiptap/starter-kit": "^2.1.10",
"@types/react": "^18.2.5",
"@types/react-dom": "18.0.11",
"@types/node": "18.15.3",
"class-variance-authority": "^0.7.0",
"clsx": "^1.2.1",
"eslint": "8.36.0",
"eslint-config-next": "13.2.4",
"eventsource-parser": "^0.1.0",
"lucide-react": "^0.244.0",
"react-markdown": "^8.0.7",
"tailwind-merge": "^1.14.0",
"tippy.js": "^6.3.7",
"tiptap-markdown": "^0.8.2",
"use-debounce": "^9.0.4"
},
"devDependencies": {
"eslint": "^7.32.0",
"postcss": "^8.4.29",
"tailwind-config-custom": "*",
"tsconfig": "*",
"tsup": "^7.2.0",
"typescript": "4.9.5"
},
"keywords": [
"editor",
"rich-text",
"markdown",
"nextjs",
"react"
]
}
9 changes: 9 additions & 0 deletions packages/editor/core/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// If you want to use other PostCSS plugins, see the following:
// https://tailwindcss.com/docs/using-with-preprocessors

module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
19 changes: 19 additions & 0 deletions packages/editor/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// styles
// import "./styles/tailwind.css";
// import "./styles/editor.css";

// utils
export * from "./lib/utils";
export { startImageUpload } from "./ui/plugins/upload-image";

// components
export { EditorContainer } from "./ui/components/editor-container";
export { EditorContentWrapper } from "./ui/components/editor-content";

// hooks
export { useEditor } from "./ui/hooks/useEditor";
export { useReadOnlyEditor } from "./ui/hooks/useReadOnlyEditor";

// helper items
export * from "./ui/menus/menu-items";
export * from "./lib/editor-commands";
91 changes: 91 additions & 0 deletions packages/editor/core/src/lib/editor-commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { Editor, Range } from "@tiptap/core";
import { UploadImage } from "../types/upload-image";
import { startImageUpload } from "../ui/plugins/upload-image";

export const toggleHeadingOne = (editor: Editor, range?: Range) => {
if (range) editor.chain().focus().deleteRange(range).setNode("heading", { level: 1 }).run();
else editor.chain().focus().toggleHeading({ level: 1 }).run()
};

export const toggleHeadingTwo = (editor: Editor, range?: Range) => {
if (range) editor.chain().focus().deleteRange(range).setNode("heading", { level: 2 }).run();
else editor.chain().focus().toggleHeading({ level: 2 }).run()
};

export const toggleHeadingThree = (editor: Editor, range?: Range) => {
if (range) editor.chain().focus().deleteRange(range).setNode("heading", { level: 3 }).run();
else editor.chain().focus().toggleHeading({ level: 3 }).run()
};

export const toggleBold = (editor: Editor, range?: Range) => {
if (range) editor.chain().focus().deleteRange(range).toggleBold().run();
else editor.chain().focus().toggleBold().run();
};

export const toggleItalic = (editor: Editor, range?: Range) => {
if (range) editor.chain().focus().deleteRange(range).toggleItalic().run();
else editor.chain().focus().toggleItalic().run();
};

export const toggleUnderline = (editor: Editor, range?: Range) => {
if (range) editor.chain().focus().deleteRange(range).toggleUnderline().run();
else editor.chain().focus().toggleUnderline().run();
};

export const toggleCode = (editor: Editor, range?: Range) => {
if (range) editor.chain().focus().deleteRange(range).toggleCode().run();
else editor.chain().focus().toggleCode().run();
};
export const toggleOrderedList = (editor: Editor, range?: Range) => {
if (range) editor.chain().focus().deleteRange(range).toggleOrderedList().run();
else editor.chain().focus().toggleOrderedList().run();
};

export const toggleBulletList = (editor: Editor, range?: Range) => {
if (range) editor.chain().focus().deleteRange(range).toggleBulletList().run();
else editor.chain().focus().toggleBulletList().run();
};

export const toggleTaskList = (editor: Editor, range?: Range) => {
if (range) editor.chain().focus().deleteRange(range).toggleTaskList().run();
else editor.chain().focus().toggleTaskList().run()
};

export const toggleStrike = (editor: Editor, range?: Range) => {
if (range) editor.chain().focus().deleteRange(range).toggleStrike().run();
else editor.chain().focus().toggleStrike().run();
};

export const toggleBlockquote = (editor: Editor, range?: Range) => {
if (range) editor.chain().focus().deleteRange(range).toggleNode("paragraph", "paragraph").toggleBlockquote().run();
else editor.chain().focus().toggleNode("paragraph", "paragraph").toggleBlockquote().run();
};

export const insertTableCommand = (editor: Editor, range?: Range) => {
if (range) editor.chain().focus().deleteRange(range).insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run();
else editor.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run();
};

export const unsetLinkEditor = (editor: Editor) => {
editor.chain().focus().unsetLink().run();
};

export const setLinkEditor = (editor: Editor, url: string) => {
editor.chain().focus().setLink({ href: url }).run();
};

export const insertImageCommand = (editor: Editor, uploadFile: UploadImage, setIsSubmitting?: (isSubmitting: "submitting" | "submitted" | "saved") => void, range?: Range) => {
if (range) editor.chain().focus().deleteRange(range).run();
const input = document.createElement("input");
input.type = "file";
input.accept = "image/*";
input.onchange = async () => {
if (input.files?.length) {
const file = input.files[0];
const pos = editor.view.state.selection.from;
startImageUpload(file, editor.view, pos, uploadFile, setIsSubmitting);
}
};
input.click();
};

45 changes: 45 additions & 0 deletions packages/editor/core/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
interface EditorClassNames {
noBorder?: boolean;
borderOnFocus?: boolean;
customClassName?: string;
}

export const getEditorClassNames = ({ noBorder, borderOnFocus, customClassName }: EditorClassNames) => cn(
'relative w-full max-w-full sm:rounded-lg mt-2 p-3 relative focus:outline-none rounded-md',
noBorder ? '' : 'border border-custom-border-200',
borderOnFocus ? 'focus:border border-custom-border-300' : 'focus:border-0',
customClassName
);

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

export const findTableAncestor = (
node: Node | null
): HTMLTableElement | null => {
while (node !== null && node.nodeName !== "TABLE") {
node = node.parentNode;
}
return node as HTMLTableElement;
};

export const getTrimmedHTML = (html: string) => {
html = html.replace(/^(<p><\/p>)+/, '');
html = html.replace(/(<p><\/p>)+$/, '');
return html;
}

export const isValidHttpUrl = (string: string): boolean => {
let url: URL;

try {
url = new URL(string);
} catch (_) {
return false;
}

return url.protocol === "http:" || url.protocol === "https:";
}
Loading
Loading