Skip to content

Commit a60ccc4

Browse files
authored
Merge pull request #2 from PriDebnath/feat/tiptap-editor
Feat/tiptap editor
2 parents c474ae8 + 1dfa629 commit a60ccc4

147 files changed

Lines changed: 14277 additions & 222 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎frontend/package.json‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,40 @@
1313
"preview": "vite preview"
1414
},
1515
"dependencies": {
16+
"@floating-ui/react": "^0.27.16",
1617
"@radix-ui/react-dialog": "^1.1.15",
18+
"@radix-ui/react-dropdown-menu": "^2.1.16",
1719
"@radix-ui/react-label": "^2.1.8",
20+
"@radix-ui/react-popover": "^1.1.15",
1821
"@radix-ui/react-slot": "^1.2.4",
1922
"@tailwindcss/vite": "^4.1.18",
23+
"@tiptap/core": "^3.15.3",
24+
"@tiptap/extension-highlight": "^3.15.3",
25+
"@tiptap/extension-horizontal-rule": "^3.15.3",
26+
"@tiptap/extension-image": "^3.15.3",
27+
"@tiptap/extension-list": "^3.15.3",
28+
"@tiptap/extension-subscript": "^3.15.3",
29+
"@tiptap/extension-superscript": "^3.15.3",
30+
"@tiptap/extension-text-align": "^3.15.3",
31+
"@tiptap/extension-typography": "^3.15.3",
32+
"@tiptap/extensions": "^3.15.3",
2033
"@tiptap/pm": "^3.15.3",
2134
"@tiptap/react": "^3.15.3",
2235
"@tiptap/starter-kit": "^3.15.3",
2336
"class-variance-authority": "^0.7.1",
2437
"clsx": "^2.1.1",
38+
"dompurify": "^3.3.1",
39+
"lodash.throttle": "^4.1.1",
2540
"lucide-react": "^0.562.0",
2641
"react": "^19.2.0",
2742
"react-dom": "^19.2.0",
43+
"react-hotkeys-hook": "^5.2.1",
2844
"tailwind-merge": "^3.4.0",
2945
"tailwindcss": "^4.1.18"
3046
},
3147
"devDependencies": {
3248
"@eslint/js": "^9.39.1",
49+
"@types/lodash.throttle": "^4.1.9",
3350
"@types/node": "^24.10.1",
3451
"@types/react": "^19.2.5",
3552
"@types/react-dom": "^19.2.3",
@@ -39,6 +56,7 @@
3956
"eslint-plugin-react-hooks": "^7.0.1",
4057
"eslint-plugin-react-refresh": "^0.4.24",
4158
"globals": "^16.5.0",
59+
"sass-embedded": "^1.97.2",
4260
"tw-animate-css": "^1.4.0",
4361
"typescript": "~5.9.3",
4462
"typescript-eslint": "^8.46.4",

‎frontend/src/App.css‎

Whitespace-only changes.

‎frontend/src/App.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import './App.css'
21
import { useEffect, useState } from 'react'
32
import { PlusIcon, Home, BookOpen, Search, Settings, SearchIcon } from 'lucide-react'
43
import type { Quote } from '@/model/quote.model'
@@ -113,9 +112,9 @@ className="rounded-b-2xl sticky top-0 bg-purple-600 p-4">
113112
<span>Books</span>
114113
</button> */}
115114
<Button
116-
className="shadow-[0_0px_12px_rgba(1,255,1,0.4)] fixed bottom-4 !border-gray-500 border-lg !bg-white"
115+
className="shadow-[0_0px_12px_rgba(1,255,1,0.4)] fixed bottom-4 !border-gray-500 border-lg "
117116
onClick={openAddDialog}>
118-
<PlusIcon className='!text-green-500' />
117+
<PlusIcon className='' />
119118
</Button>
120119
{/* <button className="nav-item">
121120
<Search size={24} />
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import type { NodeWithPos } from "@tiptap/core"
2+
import { Extension } from "@tiptap/core"
3+
import type { EditorState, Transaction } from "@tiptap/pm/state"
4+
import { getSelectedNodesOfType } from "@/lib/tiptap-utils"
5+
import { updateNodesAttr } from "@/lib/tiptap-utils"
6+
7+
declare module "@tiptap/core" {
8+
interface Commands<ReturnType> {
9+
nodeBackground: {
10+
setNodeBackgroundColor: (backgroundColor: string) => ReturnType
11+
unsetNodeBackgroundColor: () => ReturnType
12+
toggleNodeBackgroundColor: (backgroundColor: string) => ReturnType
13+
}
14+
}
15+
}
16+
17+
export interface NodeBackgroundOptions {
18+
/**
19+
* Node types that should support background colors
20+
* @default ["paragraph", "heading", "blockquote", "taskList", "bulletList", "orderedList", "tableCell", "tableHeader"]
21+
*/
22+
types: string[]
23+
/**
24+
* Use inline style instead of data attribute
25+
* @default true
26+
*/
27+
useStyle?: boolean
28+
}
29+
30+
/**
31+
* Determines the target color for toggle operations
32+
*/
33+
function getToggleColor(
34+
targets: NodeWithPos[],
35+
inputColor: string
36+
): string | null {
37+
if (targets.length === 0) return null
38+
39+
for (const target of targets) {
40+
const currentColor = target.node.attrs?.backgroundColor ?? null
41+
if (currentColor !== inputColor) {
42+
return inputColor
43+
}
44+
}
45+
46+
return null
47+
}
48+
49+
export const NodeBackground = Extension.create<NodeBackgroundOptions>({
50+
name: "nodeBackground",
51+
52+
addOptions() {
53+
return {
54+
types: [
55+
"paragraph",
56+
"heading",
57+
"blockquote",
58+
"taskList",
59+
"bulletList",
60+
"orderedList",
61+
"tableCell",
62+
"tableHeader",
63+
],
64+
useStyle: true,
65+
}
66+
},
67+
68+
addGlobalAttributes() {
69+
return [
70+
{
71+
types: this.options.types,
72+
attributes: {
73+
backgroundColor: {
74+
default: null as string | null,
75+
76+
parseHTML: (element: HTMLElement) => {
77+
const styleColor = element.style?.backgroundColor
78+
if (styleColor) return styleColor
79+
80+
const dataColor = element.getAttribute("data-background-color")
81+
return dataColor || null
82+
},
83+
84+
renderHTML: (attributes) => {
85+
const color = attributes.backgroundColor as string | null
86+
if (!color) return {}
87+
88+
if (this.options.useStyle) {
89+
return {
90+
style: `background-color: ${color}`,
91+
}
92+
} else {
93+
return {
94+
"data-background-color": color,
95+
}
96+
}
97+
},
98+
},
99+
},
100+
},
101+
]
102+
},
103+
104+
addCommands() {
105+
/**
106+
* Generic command executor for background color operations
107+
*/
108+
const executeBackgroundCommand = (
109+
getTargetColor: (
110+
targets: NodeWithPos[],
111+
inputColor?: string
112+
) => string | null
113+
) => {
114+
return (inputColor?: string) =>
115+
({ state, tr }: { state: EditorState; tr: Transaction }) => {
116+
const targets = getSelectedNodesOfType(
117+
state.selection,
118+
this.options.types
119+
)
120+
121+
if (targets.length === 0) return false
122+
123+
const targetColor = getTargetColor(targets, inputColor)
124+
125+
return updateNodesAttr(tr, targets, "backgroundColor", targetColor)
126+
}
127+
}
128+
129+
return {
130+
/**
131+
* Set background color to specific value
132+
*/
133+
setNodeBackgroundColor: executeBackgroundCommand(
134+
(_, inputColor) => inputColor || null
135+
),
136+
137+
/**
138+
* Remove background color
139+
*/
140+
unsetNodeBackgroundColor: executeBackgroundCommand(() => null),
141+
142+
/**
143+
* Toggle background color (set if different/missing, unset if all have it)
144+
*/
145+
toggleNodeBackgroundColor: executeBackgroundCommand(
146+
(targets, inputColor) => getToggleColor(targets, inputColor || "")
147+
),
148+
}
149+
},
150+
})
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { memo } from "react"
2+
3+
type SvgProps = React.ComponentPropsWithoutRef<"svg">
4+
5+
export const AlignCenterIcon = memo(({ className, ...props }: SvgProps) => {
6+
return (
7+
<svg
8+
width="24"
9+
height="24"
10+
className={className}
11+
viewBox="0 0 24 24"
12+
fill="currentColor"
13+
xmlns="http://www.w3.org/2000/svg"
14+
{...props}
15+
>
16+
<path
17+
fillRule="evenodd"
18+
clipRule="evenodd"
19+
d="M2 6C2 5.44772 2.44772 5 3 5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H3C2.44772 7 2 6.55228 2 6Z"
20+
fill="currentColor"
21+
/>
22+
<path
23+
fillRule="evenodd"
24+
clipRule="evenodd"
25+
d="M6 12C6 11.4477 6.44772 11 7 11H17C17.5523 11 18 11.4477 18 12C18 12.5523 17.5523 13 17 13H7C6.44772 13 6 12.5523 6 12Z"
26+
fill="currentColor"
27+
/>
28+
<path
29+
fillRule="evenodd"
30+
clipRule="evenodd"
31+
d="M4 18C4 17.4477 4.44772 17 5 17H19C19.5523 17 20 17.4477 20 18C20 18.5523 19.5523 19 19 19H5C4.44772 19 4 18.5523 4 18Z"
32+
fill="currentColor"
33+
/>
34+
</svg>
35+
)
36+
})
37+
38+
AlignCenterIcon.displayName = "AlignCenterIcon"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { memo } from "react"
2+
3+
type SvgProps = React.ComponentPropsWithoutRef<"svg">
4+
5+
export const AlignJustifyIcon = memo(({ className, ...props }: SvgProps) => {
6+
return (
7+
<svg
8+
width="24"
9+
height="24"
10+
className={className}
11+
viewBox="0 0 24 24"
12+
fill="currentColor"
13+
xmlns="http://www.w3.org/2000/svg"
14+
{...props}
15+
>
16+
<path
17+
fillRule="evenodd"
18+
clipRule="evenodd"
19+
d="M2 6C2 5.44772 2.44772 5 3 5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H3C2.44772 7 2 6.55228 2 6Z"
20+
fill="currentColor"
21+
/>
22+
<path
23+
fillRule="evenodd"
24+
clipRule="evenodd"
25+
d="M2 12C2 11.4477 2.44772 11 3 11H21C21.5523 11 22 11.4477 22 12C22 12.5523 21.5523 13 21 13H3C2.44772 13 2 12.5523 2 12Z"
26+
fill="currentColor"
27+
/>
28+
<path
29+
fillRule="evenodd"
30+
clipRule="evenodd"
31+
d="M2 18C2 17.4477 2.44772 17 3 17H21C21.5523 17 22 17.4477 22 18C22 18.5523 21.5523 19 21 19H3C2.44772 19 2 18.5523 2 18Z"
32+
fill="currentColor"
33+
/>
34+
</svg>
35+
)
36+
})
37+
38+
AlignJustifyIcon.displayName = "AlignJustifyIcon"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { memo } from "react"
2+
3+
type SvgProps = React.ComponentPropsWithoutRef<"svg">
4+
5+
export const AlignLeftIcon = memo(({ className, ...props }: SvgProps) => {
6+
return (
7+
<svg
8+
width="24"
9+
height="24"
10+
className={className}
11+
viewBox="0 0 24 24"
12+
fill="currentColor"
13+
xmlns="http://www.w3.org/2000/svg"
14+
{...props}
15+
>
16+
<path
17+
fillRule="evenodd"
18+
clipRule="evenodd"
19+
d="M2 6C2 5.44772 2.44772 5 3 5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H3C2.44772 7 2 6.55228 2 6Z"
20+
fill="currentColor"
21+
/>
22+
<path
23+
fillRule="evenodd"
24+
clipRule="evenodd"
25+
d="M2 12C2 11.4477 2.44772 11 3 11H15C15.5523 11 16 11.4477 16 12C16 12.5523 15.5523 13 15 13H3C2.44772 13 2 12.5523 2 12Z"
26+
fill="currentColor"
27+
/>
28+
<path
29+
fillRule="evenodd"
30+
clipRule="evenodd"
31+
d="M2 18C2 17.4477 2.44772 17 3 17H17C17.5523 17 18 17.4477 18 18C18 18.5523 17.5523 19 17 19H3C2.44772 19 2 18.5523 2 18Z"
32+
fill="currentColor"
33+
/>
34+
</svg>
35+
)
36+
})
37+
38+
AlignLeftIcon.displayName = "AlignLeftIcon"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { memo } from "react"
2+
3+
type SvgProps = React.ComponentPropsWithoutRef<"svg">
4+
5+
export const AlignRightIcon = memo(({ className, ...props }: SvgProps) => {
6+
return (
7+
<svg
8+
width="24"
9+
height="24"
10+
className={className}
11+
viewBox="0 0 24 24"
12+
fill="currentColor"
13+
xmlns="http://www.w3.org/2000/svg"
14+
{...props}
15+
>
16+
<path
17+
fillRule="evenodd"
18+
clipRule="evenodd"
19+
d="M2 6C2 5.44772 2.44772 5 3 5H21C21.5523 5 22 5.44772 22 6C22 6.55228 21.5523 7 21 7H3C2.44772 7 2 6.55228 2 6Z"
20+
fill="currentColor"
21+
/>
22+
<path
23+
fillRule="evenodd"
24+
clipRule="evenodd"
25+
d="M8 12C8 11.4477 8.44772 11 9 11H21C21.5523 11 22 11.4477 22 12C22 12.5523 21.5523 13 21 13H9C8.44772 13 8 12.5523 8 12Z"
26+
fill="currentColor"
27+
/>
28+
<path
29+
fillRule="evenodd"
30+
clipRule="evenodd"
31+
d="M6 18C6 17.4477 6.44772 17 7 17H21C21.5523 17 22 17.4477 22 18C22 18.5523 21.5523 19 21 19H7C6.44772 19 6 18.5523 6 18Z"
32+
fill="currentColor"
33+
/>
34+
</svg>
35+
)
36+
})
37+
38+
AlignRightIcon.displayName = "AlignRightIcon"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { memo } from "react"
2+
3+
type SvgProps = React.ComponentPropsWithoutRef<"svg">
4+
5+
export const ArrowLeftIcon = memo(({ className, ...props }: SvgProps) => {
6+
return (
7+
<svg
8+
width="24"
9+
height="24"
10+
className={className}
11+
viewBox="0 0 24 24"
12+
fill="currentColor"
13+
xmlns="http://www.w3.org/2000/svg"
14+
{...props}
15+
>
16+
<path
17+
d="M12.7071 5.70711C13.0976 5.31658 13.0976 4.68342 12.7071 4.29289C12.3166 3.90237 11.6834 3.90237 11.2929 4.29289L4.29289 11.2929C3.90237 11.6834 3.90237 12.3166 4.29289 12.7071L11.2929 19.7071C11.6834 20.0976 12.3166 20.0976 12.7071 19.7071C13.0976 19.3166 13.0976 18.6834 12.7071 18.2929L7.41421 13L19 13C19.5523 13 20 12.5523 20 12C20 11.4477 19.5523 11 19 11L7.41421 11L12.7071 5.70711Z"
18+
fill="currentColor"
19+
/>
20+
</svg>
21+
)
22+
})
23+
24+
ArrowLeftIcon.displayName = "ArrowLeftIcon"

0 commit comments

Comments
 (0)