@ihsanabuhanifah/react-math-editor 1.0.1 → 1.1.1

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
@@ -13,14 +13,17 @@ Designed specifically for educational platforms, exam builders (CBT), question b
13
13
 
14
14
  ## ✨ Features
15
15
 
16
+ - 🧠 **SmartContentEditor Included:** Advanced editor supporting resizable & alignable images (25%, 50%, 75%, 100%), document attachments, YouTube video embeds, and AI paste modal.
16
17
  - 📐 **Interactive LaTeX Math Formulas:** Popup dialog with live KaTeX preview. Click any formula chip inside the editor to edit it seamlessly.
17
18
  - 📘 **Built-in Formula Cheat Sheet:** Comprehensive LaTeX dictionary covering Algebra, Trigonometry, Calculus, Matrices, and Logic.
18
19
  - 📊 **Rich Table Support:** Insert tables (3x3), visually add/remove rows and columns, delete tables.
19
20
  - 📋 **Auto-convert Markdown Tables:** Copy-paste markdown tables from AI assistants (ChatGPT, Claude, DeepSeek) and they automatically convert into interactive HTML tables.
21
+ - 🤖 **Smart AI Paste:** Dedicated modal & paste listener that formats markdown from AI into clean visual Tiptap nodes.
22
+ - 🎥 **YouTube & Attachment Embeds:** Embed responsive 16:9 YouTube videos and downloadable document attachments.
20
23
  - 💻 **Syntax Highlighted Code Blocks:** Pre-configured code blocks with syntax highlighting using `highlight.js`.
21
- - 🖼️ **Vendor-Agnostic Image Upload:** Async callback prop (`onUploadImage`) easily connects to AWS S3, Cloudflare R2, Supabase, Firebase, or your custom REST API.
24
+ - 🖼️ **Vendor-Agnostic Uploads:** Async callback props (`onUploadImage`, `onUploadFile`) connect to any storage backend.
22
25
  - 🎨 **Self-Contained Styling:** Bundled standalone CSS (`style.css`), no TailwindCSS setup required on the consumer application.
23
- - 👁️ **RenderMathHTML Viewer:** Companion lightweight component to safely render and display saved HTML content with full KaTeX formulas and responsive tables.
26
+ - 👁️ **RenderMathHTML Viewer:** Companion lightweight component to safely render and display saved HTML content.
24
27
 
25
28
  ---
26
29
 
@@ -102,7 +105,20 @@ export function QuestionCard({ htmlContent }: { htmlContent: string }) {
102
105
 
103
106
  ## ⚙️ API & Props Reference
104
107
 
105
- ### `<TextEditor />`
108
+ ### `<SmartContentEditor />` *(Featured Full-Featured Component)*
109
+
110
+ | Prop | Type | Default | Description |
111
+ | :--- | :--- | :--- | :--- |
112
+ | `value` | `string` | `""` | Initial or controlled HTML content |
113
+ | `handleChange` / `onChange` | `(html: string) => void` | `undefined` | Callback fired on content change |
114
+ | `readOnly` | `boolean` | `false` | Read-only mode (ideal for question previews & test cards) |
115
+ | `minHeight` | `number` | `140` | Minimum height for editing area in pixels |
116
+ | `placeholder` | `string` | `"Tulis konten..."` | Placeholder text when empty |
117
+ | `onUploadImage` | `(file: File) => Promise<string>` | `undefined` | Async upload for image insertions, drag-drop, or screenshot paste |
118
+ | `onUploadFile` | `(file: File) => Promise<{ url, name, size }>` | `undefined` | Async upload for document attachment nodes |
119
+ | `className` | `string` | `""` | Optional CSS class name |
120
+
121
+ ### `<TextEditor />` *(Standard Rich Math Editor)*
106
122
 
107
123
  | Prop | Type | Default | Description |
108
124
  | :--- | :--- | :--- | :--- |
@@ -117,7 +133,7 @@ export function QuestionCard({ htmlContent }: { htmlContent: string }) {
117
133
  | `toolbarExtra` | `React.ReactNode` | `undefined` | Slot for custom action buttons in the toolbar |
118
134
  | `className` | `string` | `""` | Additional CSS class names for outer container |
119
135
 
120
- ### `<RenderMathHTML />`
136
+ ### `<RenderMathHTML />` *(Lightweight Output Viewer)*
121
137
 
122
138
  | Prop | Type | Default | Description |
123
139
  | :--- | :--- | :--- | :--- |
@@ -130,16 +146,36 @@ export function QuestionCard({ htmlContent }: { htmlContent: string }) {
130
146
 
131
147
  ## 💡 Framework Support
132
148
 
133
- ### Next.js (App Router / Pages Router)
134
- Because KaTeX and Tiptap interact with the browser DOM, wrap `TextEditor` with `'use client'` or dynamic import if using Server Components:
149
+ ### Next.js (App Router & Pages Router)
150
+ The library is pre-configured with `'use client';` and SSR hydration guards (`immediatelyRender: false`), making it fully compatible with Next.js:
135
151
 
136
152
  ```tsx
137
153
  'use client';
138
- import { TextEditor } from "@ihsanabuhanifah/react-math-editor";
154
+
155
+ import { SmartContentEditor, RenderMathHTML } from "@ihsanabuhanifah/react-math-editor";
139
156
  import "@ihsanabuhanifah/react-math-editor/dist/style.css";
157
+
158
+ export default function SoalPage() {
159
+ const [content, setContent] = useState("");
160
+
161
+ return <SmartContentEditor value={content} handleChange={setContent} />;
162
+ }
163
+ ```
164
+
165
+ Or with `next/dynamic` if you prefer client-only lazy loading:
166
+
167
+ ```tsx
168
+ import dynamic from "next/dynamic";
169
+ import "@ihsanabuhanifah/react-math-editor/dist/style.css";
170
+
171
+ const SmartContentEditor = dynamic(
172
+ () => import("@ihsanabuhanifah/react-math-editor").then((mod) => mod.SmartContentEditor),
173
+ { ssr: false }
174
+ );
140
175
  ```
141
176
 
142
- ### Vite / Create React App / Remix
177
+ ### Vite / Remix / Create React App
178
+ Works directly out of the box with zero extra configuration. Just import the component and the stylesheet.
143
179
  Works directly out of the box. Simply import the component and the stylesheet.
144
180
 
145
181
  ---
@@ -0,0 +1,27 @@
1
+ import { default as React } from 'react';
2
+
3
+ export declare let lastActiveSmartEditor: any;
4
+ export declare function setLastActiveSmartEditor(ed: any): void;
5
+ export declare function getLastActiveSmartEditor(): any;
6
+ export declare function parseYouTubeEmbedUrl(url: string): string | null;
7
+ export declare function convertAiMarkdownToTipTapHtml(markdown: string): string;
8
+ export interface SmartContentEditorProps {
9
+ value: string;
10
+ handleChange?: (html: string) => void;
11
+ onChange?: (html: string) => void;
12
+ readOnly?: boolean;
13
+ minHeight?: number;
14
+ placeholder?: string;
15
+ onUploadImage?: (file: File) => Promise<string>;
16
+ onUploadFile?: (file: File) => Promise<{
17
+ url: string;
18
+ name: string;
19
+ size?: string | number;
20
+ }>;
21
+ showMathGraph?: boolean;
22
+ onPreview?: () => void;
23
+ error?: string;
24
+ className?: string;
25
+ }
26
+ export declare function SmartContentEditor({ value, handleChange, onChange, readOnly, minHeight, placeholder, onUploadImage, onUploadFile, showMathGraph, onPreview, error, className, }: SmartContentEditorProps): React.JSX.Element;
27
+ export default SmartContentEditor;