tiptap-editor-codeveda 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,69 +1,273 @@
1
- # React + TypeScript + Vite
2
-
3
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
-
5
- Currently, two official plugins are available:
6
-
7
- - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
8
- - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
-
10
- ## Expanding the ESLint configuration
11
-
12
- If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
13
-
14
- ```js
15
- export default tseslint.config([
16
- globalIgnores(['dist']),
17
- {
18
- files: ['**/*.{ts,tsx}'],
19
- extends: [
20
- // Other configs...
21
-
22
- // Remove tseslint.configs.recommended and replace with this
23
- ...tseslint.configs.recommendedTypeChecked,
24
- // Alternatively, use this for stricter rules
25
- ...tseslint.configs.strictTypeChecked,
26
- // Optionally, add this for stylistic rules
27
- ...tseslint.configs.stylisticTypeChecked,
28
-
29
- // Other configs...
30
- ],
31
- languageOptions: {
32
- parserOptions: {
33
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
34
- tsconfigRootDir: import.meta.dirname,
35
- },
36
- // other options...
37
- },
38
- },
39
- ])
1
+ # Tiptap Editor Codeveda
2
+
3
+ A powerful, feature-rich rich text editor built with Tiptap and React. This package provides both an editor and viewer component with extensive functionality including tables, images, videos, code blocks, accordions, tabs, iframes, and more.
4
+
5
+ ## 🚀 Features
6
+
7
+ - **Rich Text Editing**: Bold, italic, underline, strikethrough, headings, lists
8
+ - **Tables**: Full table support with add/delete rows and columns
9
+ - **Media Support**: Image and video uploads with preview
10
+ - **Code Blocks**: Syntax-highlighted code blocks with multiple language support
11
+ - **Interactive Components**: Accordions, tabs, iframes for CodeSandbox/YouTube
12
+ - **Customizable**: Extensible with custom extensions and styling
13
+ - **TypeScript**: Full TypeScript support with type definitions
14
+ - **Read-only Mode**: Viewer component for displaying content
15
+
16
+ ## 📦 Installation
17
+
18
+ ```bash
19
+ npm install tiptap-editor-codeveda
20
+ ```
21
+
22
+ ## 🔧 Basic Usage
23
+
24
+ ### Simple Editor
25
+
26
+ ```tsx
27
+ import { TiptapEditor, useEditorContent } from "tiptap-editor-codeveda";
28
+
29
+ function MyApp() {
30
+ const { content, html, json, setContent } = useEditorContent();
31
+
32
+ return (
33
+ <div>
34
+ <TiptapEditor setEditorContent={setContent} />
35
+
36
+ {/* Display content */}
37
+ <div>
38
+ <h3>HTML Output:</h3>
39
+ <pre>{html}</pre>
40
+ </div>
41
+ </div>
42
+ );
43
+ }
44
+ ```
45
+
46
+ ### With File Upload Support
47
+
48
+ ```tsx
49
+ import { TiptapEditor, useEditorContent } from "tiptap-editor-codeveda";
50
+
51
+ function EditorWithUploads() {
52
+ const { content, setContent } = useEditorContent();
53
+
54
+ const handleImageUpload = async (file: File): Promise<string> => {
55
+ // Your image upload logic here
56
+ const formData = new FormData();
57
+ formData.append("image", file);
58
+
59
+ const response = await fetch("/api/upload/image", {
60
+ method: "POST",
61
+ body: formData,
62
+ });
63
+
64
+ const { imageUrl } = await response.json();
65
+ return imageUrl;
66
+ };
67
+
68
+ const handleVideoUpload = async (file: File): Promise<string> => {
69
+ // Your video upload logic here
70
+ const formData = new FormData();
71
+ formData.append("video", file);
72
+
73
+ const response = await fetch("/api/upload/video", {
74
+ method: "POST",
75
+ body: formData,
76
+ });
77
+
78
+ const { videoUrl } = await response.json();
79
+ return videoUrl;
80
+ };
81
+
82
+ return (
83
+ <TiptapEditor
84
+ setEditorContent={setContent}
85
+ onImageUpload={handleImageUpload}
86
+ onVideoUpload={handleVideoUpload}
87
+ />
88
+ );
89
+ }
90
+ ```
91
+
92
+ ### Read-only Viewer
93
+
94
+ ```tsx
95
+ import { TiptapViewer } from "tiptap-editor-codeveda";
96
+
97
+ function ContentViewer({ htmlContent }: { htmlContent: string }) {
98
+ return (
99
+ <TiptapViewer editorContent={htmlContent} styles="custom-viewer-styles" />
100
+ );
101
+ }
102
+ ```
103
+
104
+ ## 📖 API Reference
105
+
106
+ ### TiptapEditor Props
107
+
108
+ | Prop | Type | Description |
109
+ | ------------------ | ----------------------------------------- | ------------------------------------------ |
110
+ | `setEditorContent` | `(content: EditorContentPayload) => void` | Callback fired when editor content changes |
111
+ | `onImageUpload` | `(file: File) => Promise<string>` | Optional image upload handler |
112
+ | `onVideoUpload` | `(file: File) => Promise<string>` | Optional video upload handler |
113
+
114
+ ### TiptapViewer Props
115
+
116
+ | Prop | Type | Description |
117
+ | --------------- | -------- | -------------------------------- |
118
+ | `editorContent` | `string` | HTML content to display |
119
+ | `styles` | `string` | Optional CSS classes for styling |
120
+
121
+ ### useEditorContent Hook
122
+
123
+ Returns an object with:
124
+
125
+ ```tsx
126
+ {
127
+ content: EditorContentPayload; // Full content object
128
+ html: string; // HTML string
129
+ json: any; // JSON representation
130
+ setContent: (content: EditorContentPayload) => void; // Update function
131
+ }
40
132
  ```
41
133
 
42
- You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
43
-
44
- ```js
45
- // eslint.config.js
46
- import reactX from 'eslint-plugin-react-x'
47
- import reactDom from 'eslint-plugin-react-dom'
48
-
49
- export default tseslint.config([
50
- globalIgnores(['dist']),
51
- {
52
- files: ['**/*.{ts,tsx}'],
53
- extends: [
54
- // Other configs...
55
- // Enable lint rules for React
56
- reactX.configs['recommended-typescript'],
57
- // Enable lint rules for React DOM
58
- reactDom.configs.recommended,
59
- ],
60
- languageOptions: {
61
- parserOptions: {
62
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
63
- tsconfigRootDir: import.meta.dirname,
64
- },
65
- // other options...
66
- },
67
- },
68
- ])
134
+ ### EditorContentPayload Type
135
+
136
+ ```tsx
137
+ type EditorContentPayload = {
138
+ html: string;
139
+ json: any; // ProseMirror JSON document
140
+ };
141
+ ```
142
+
143
+ ## 🎨 Styling
144
+
145
+ The editor comes with default Tailwind CSS styles. You can customize the appearance by:
146
+
147
+ 1. **Override CSS classes**: The editor uses standard prose classes
148
+ 2. **Custom styles**: Pass custom CSS classes to the viewer
149
+ 3. **Theme customization**: Modify the default color scheme
150
+
151
+ ```css
152
+ /* Custom editor styles */
153
+ .tiptap-editor {
154
+ /* Your custom styles */
155
+ }
156
+
157
+ .tiptap-editor .ProseMirror {
158
+ /* Editor content area */
159
+ }
160
+ ```
161
+
162
+ ## 🔌 Available Features
163
+
164
+ ### Text Formatting
165
+
166
+ - **Headings**: H1, H2, H3
167
+ - **Text styles**: Bold, italic, underline, strikethrough
168
+ - **Lists**: Bullet points and numbered lists
169
+ - **Quotes**: Block quotes
170
+ - **Links**: Clickable links
171
+
172
+ ### Advanced Components
173
+
174
+ - **Tables**: Resizable tables with header support
175
+ - **Code blocks**: Syntax highlighting for multiple languages
176
+ - **Accordions**: Collapsible content sections
177
+ - **Tabs**: Tabbed content organization
178
+ - **Iframes**: Embed CodeSandbox, YouTube, etc.
179
+
180
+ ### Media
181
+
182
+ - **Images**: Upload or URL-based images with preview
183
+ - **Videos**: Upload or embed videos
184
+
185
+ ## 🛠️ Examples
186
+
187
+ ### Firebase Integration
188
+
189
+ ```tsx
190
+ import { initializeApp } from "firebase/app";
191
+ import { getStorage, ref, uploadBytes, getDownloadURL } from "firebase/storage";
192
+
193
+ // Initialize Firebase
194
+ const app = initializeApp(firebaseConfig);
195
+ const storage = getStorage(app);
196
+
197
+ const uploadToFirebase = async (
198
+ file: File,
199
+ folder: string
200
+ ): Promise<string> => {
201
+ const storageRef = ref(storage, `${folder}/${Date.now()}_${file.name}`);
202
+ const snapshot = await uploadBytes(storageRef, file);
203
+ return await getDownloadURL(snapshot.ref);
204
+ };
205
+
206
+ function FirebaseEditor() {
207
+ const { setContent } = useEditorContent();
208
+
209
+ return (
210
+ <TiptapEditor
211
+ setEditorContent={setContent}
212
+ onImageUpload={(file) => uploadToFirebase(file, "images")}
213
+ onVideoUpload={(file) => uploadToFirebase(file, "videos")}
214
+ />
215
+ );
216
+ }
217
+ ```
218
+
219
+ ### Content Management
220
+
221
+ ```tsx
222
+ import { useState, useEffect } from "react";
223
+ import {
224
+ TiptapEditor,
225
+ TiptapViewer,
226
+ useEditorContent,
227
+ } from "tiptap-editor-codeveda";
228
+
229
+ function ContentManager() {
230
+ const [isEditing, setIsEditing] = useState(false);
231
+ const [savedContent, setSavedContent] = useState("");
232
+ const { content, setContent } = useEditorContent();
233
+
234
+ const saveContent = () => {
235
+ setSavedContent(content.html);
236
+ setIsEditing(false);
237
+ // Save to your backend
238
+ };
239
+
240
+ return (
241
+ <div>
242
+ {isEditing ? (
243
+ <div>
244
+ <TiptapEditor setEditorContent={setContent} />
245
+ <button onClick={saveContent}>Save</button>
246
+ <button onClick={() => setIsEditing(false)}>Cancel</button>
247
+ </div>
248
+ ) : (
249
+ <div>
250
+ <TiptapViewer editorContent={savedContent} />
251
+ <button onClick={() => setIsEditing(true)}>Edit</button>
252
+ </div>
253
+ )}
254
+ </div>
255
+ );
256
+ }
69
257
  ```
258
+
259
+ ## 🤝 Contributing
260
+
261
+ Contributions are welcome! Please feel free to submit a Pull Request.
262
+
263
+ ## 📄 License
264
+
265
+ MIT License - feel free to use this in your projects.
266
+
267
+ ## 🐛 Issues
268
+
269
+ If you encounter any issues, please report them on the GitHub repository.
270
+
271
+ ---
272
+
273
+ Built with ❤️ using [Tiptap](https://tiptap.dev/) and React.
package/dist/index.d.ts CHANGED
@@ -1 +1,48 @@
1
- export {}
1
+ import { default as default_2 } from 'react';
2
+ import { JSX } from 'react/jsx-runtime';
3
+
4
+ export declare type EditorContentPayload = {
5
+ html: string;
6
+ json: any;
7
+ };
8
+
9
+ export declare const TiptapEditor: default_2.FC<TiptapProps>;
10
+
11
+ declare interface TiptapProps {
12
+ onImageUpload?: (file: File) => Promise<string>;
13
+ onVideoUpload?: (file: File) => Promise<string>;
14
+ setEditorContent?: (content: {
15
+ html: string;
16
+ json: any;
17
+ }) => void;
18
+ }
19
+
20
+ export declare const TiptapViewer: ({ styles, editorContent, }: {
21
+ styles?: string;
22
+ editorContent?: string;
23
+ }) => JSX.Element | null;
24
+
25
+ export declare function useEditorContent(initial?: EditorContentPayload): {
26
+ content: EditorContentPayload;
27
+ html: string;
28
+ json: any;
29
+ setContent: (next: EditorContentPayload) => void;
30
+ };
31
+
32
+ export { }
33
+
34
+
35
+ declare module "@tiptap/core" {
36
+ interface Commands<ReturnType> {
37
+ video: {
38
+ /**
39
+ * Add a video
40
+ */
41
+ setVideo: (options: {
42
+ src: string;
43
+ type?: string;
44
+ title?: string;
45
+ }) => ReturnType;
46
+ };
47
+ }
48
+ }