@ihsanabuhanifah/react-math-editor 1.0.0
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/LICENSE +21 -0
- package/README.md +176 -0
- package/dist/components/LatexCheatSheet.d.ts +15 -0
- package/dist/components/MathFormulaModal.d.ts +9 -0
- package/dist/components/RenderMathHTML.d.ts +10 -0
- package/dist/components/TextEditor.d.ts +15 -0
- package/dist/index.cjs +553 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +94789 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/markdownTable.d.ts +6 -0
- package/dist/style.css +1 -0
- package/package.json +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# @ihsanabuhanifah/react-math-editor
|
|
2
|
+
|
|
3
|
+
Komponen Rich Text Editor & Math Viewer modern untuk React. Ditenagai oleh **Tiptap** dan **KaTeX**, dirancang untuk mengetik soal, materi ujian, formula matematika LaTeX, tabel responsif, dan sintaks kode secara visual dan instan.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## ✨ Fitur Utama
|
|
11
|
+
|
|
12
|
+
- 📐 **Formula Matematika LaTeX Interaktif:** Dialog penulisan rumus dengan pratinjau instan (*live KaTeX preview*) dan klik langsung untuk mengedit rumus yang sudah ada.
|
|
13
|
+
- 📘 **Kamus Rumus LaTeX:** Cheat sheet terintegrasi lengkap dengan berbagai kategori (Aljabar, Trigonometri, Kalkulus, Matriks, Logika).
|
|
14
|
+
- 📊 **Tabel Responsif:** Sisipkan tabel, tambah/hapus baris & kolom secara visual.
|
|
15
|
+
- 📋 **Auto-convert Markdown Table:** Copy-paste tabel teks markdown dari AI (ChatGPT, DeepSeek, Claude) langsung otomatis diubah menjadi tabel HTML.
|
|
16
|
+
- 💻 **Blok Kode & Highlighting:** Syntax highlighting otomatis untuk berbagai bahasa pemrograman menggunakan `highlight.js`.
|
|
17
|
+
- 🖼️ **Upload Gambar Fleksibel:** Integrasikan dengan backend apa pun (AWS S3, Cloudflare R2, Supabase, Laravel, Express) via callback `onUploadImage`.
|
|
18
|
+
- 🎨 **Styles Mandiri:** File CSS terisolasi (`style.css`), tidak memerlukan konfigurasi Tailwind eksternal.
|
|
19
|
+
- 👁️ **RenderMathHTML Viewer:** Komponen terpisah untuk menampilkan output konten dengan perenderan KaTeX dan tabel responsif.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 📦 Instalasi
|
|
24
|
+
|
|
25
|
+
Install paket ini melalui package manager favorit Anda:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @ihsanabuhanifah/react-math-editor
|
|
29
|
+
# atau
|
|
30
|
+
yarn add @ihsanabuhanifah/react-math-editor
|
|
31
|
+
# atau
|
|
32
|
+
pnpm add @ihsanabuhanifah/react-math-editor
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Pastikan juga `react` dan `react-dom` versi 18 atau 19 sudah terpasang di project Anda.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 🚀 Panduan Penggunaan
|
|
40
|
+
|
|
41
|
+
### 1. Menggunakan Editor (`TextEditor`)
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import React, { useState } from "react";
|
|
45
|
+
import { TextEditor } from "@ihsanabuhanifah/react-math-editor";
|
|
46
|
+
import "@ihsanabuhanifah/react-math-editor/dist/style.css"; // Wajib diimport sekali
|
|
47
|
+
|
|
48
|
+
export function FormInputSoal() {
|
|
49
|
+
const [content, setContent] = useState("<p>Tentukan nilai dari $x^2 + 5x + 6 = 0$!</p>");
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<div style={{ maxWidth: 800, margin: "0 auto" }}>
|
|
53
|
+
<TextEditor
|
|
54
|
+
value={content}
|
|
55
|
+
onChange={(html) => setContent(html)}
|
|
56
|
+
placeholder="Ketik soal, rumus matematika, atau sisipkan tabel..."
|
|
57
|
+
minHeight={200}
|
|
58
|
+
// Handler upload gambar ke server Anda:
|
|
59
|
+
onUploadImage={async (file) => {
|
|
60
|
+
const formData = new FormData();
|
|
61
|
+
formData.append("image", file);
|
|
62
|
+
|
|
63
|
+
const res = await fetch("/api/upload", {
|
|
64
|
+
method: "POST",
|
|
65
|
+
body: formData,
|
|
66
|
+
});
|
|
67
|
+
const data = await res.json();
|
|
68
|
+
return data.url; // Harus mengembalikan string URL gambar
|
|
69
|
+
}}
|
|
70
|
+
/>
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
### 2. Menampilkan Hasil Konten (`RenderMathHTML`)
|
|
79
|
+
|
|
80
|
+
Komponen ini digunakan di halaman preview, ujian siswa, artikel, atau detail soal:
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
import React from "react";
|
|
84
|
+
import { RenderMathHTML } from "@ihsanabuhanifah/react-math-editor";
|
|
85
|
+
import "@ihsanabuhanifah/react-math-editor/dist/style.css";
|
|
86
|
+
|
|
87
|
+
export function DetailSoal({ soalHtml }: { soalHtml: string }) {
|
|
88
|
+
return (
|
|
89
|
+
<div className="card-soal">
|
|
90
|
+
<RenderMathHTML html={soalHtml} />
|
|
91
|
+
</div>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## 🛠️ API & Props Reference
|
|
99
|
+
|
|
100
|
+
### `<TextEditor />`
|
|
101
|
+
|
|
102
|
+
| Prop | Tipe | Default | Deskripsi |
|
|
103
|
+
| :--- | :--- | :--- | :--- |
|
|
104
|
+
| `value` | `string` | `""` | Konten HTML input awal |
|
|
105
|
+
| `onChange` | `(html: string) => void` | `undefined` | Callback saat isi editor berubah |
|
|
106
|
+
| `placeholder` | `string` | `"Tulis konten..."` | Teks placeholder saat editor kosong |
|
|
107
|
+
| `disabled` | `boolean` | `false` | Menonaktifkan interaksi editor |
|
|
108
|
+
| `readOnly` | `boolean` | `false` | Sembunyikan toolbar dan jadikan read-only |
|
|
109
|
+
| `minHeight` | `number \| string` | `140` | Tinggi minimum area ketik (px atau css string) |
|
|
110
|
+
| `maxHeight` | `number \| string` | `600` | Tinggi maksimum sebelum scroll |
|
|
111
|
+
| `onUploadImage` | `(file: File) => Promise<string>` | `undefined` | Fungsi async pengunggah gambar |
|
|
112
|
+
| `toolbarExtra` | `React.ReactNode` | `undefined` | Slot tombol tambahan di kanan toolbar |
|
|
113
|
+
| `className` | `string` | `""` | Kelas CSS tambahan pada container |
|
|
114
|
+
|
|
115
|
+
### `<RenderMathHTML />`
|
|
116
|
+
|
|
117
|
+
| Prop | Tipe | Default | Deskripsi |
|
|
118
|
+
| :--- | :--- | :--- | :--- |
|
|
119
|
+
| `html` | `string` | `""` | String HTML yang akan dirender |
|
|
120
|
+
| `className` | `string` | `""` | Kelas CSS kustom untuk container |
|
|
121
|
+
| `style` | `React.CSSProperties` | `undefined` | Objek inline style container |
|
|
122
|
+
| `resolveImageUrl` | `(url: string) => Promise<string> \| string` | `undefined` | Resolver opsional untuk URL gambar presigned/private |
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## 🌐 Cara Publikasi ke GitHub & NPM
|
|
127
|
+
|
|
128
|
+
### A. Publish ke NPM Registry
|
|
129
|
+
1. Masuk ke folder library:
|
|
130
|
+
```bash
|
|
131
|
+
cd packages/react-math-editor
|
|
132
|
+
```
|
|
133
|
+
2. Build bundle produksi:
|
|
134
|
+
```bash
|
|
135
|
+
npm run build
|
|
136
|
+
```
|
|
137
|
+
3. Login ke akun NPM Anda (jika belum):
|
|
138
|
+
```bash
|
|
139
|
+
npm login
|
|
140
|
+
```
|
|
141
|
+
4. Publikasikan paket:
|
|
142
|
+
```bash
|
|
143
|
+
npm publish --access public
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### B. Simpan di GitHub Repository
|
|
147
|
+
Anda bisa membuat repository baru di GitHub (misal `https://github.com/username/react-math-editor`):
|
|
148
|
+
```bash
|
|
149
|
+
cd packages/react-math-editor
|
|
150
|
+
git init
|
|
151
|
+
git add .
|
|
152
|
+
git commit -m "feat: initial release of react-math-editor"
|
|
153
|
+
git branch -M main
|
|
154
|
+
git remote add origin https://github.com/username/react-math-editor.git
|
|
155
|
+
git push -u origin main
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Setelah dipush ke GitHub, Anda bahkan bisa langsung menginstallnya di project lain tanpa harus publish ke NPM:
|
|
159
|
+
```bash
|
|
160
|
+
npm install git+https://github.com/username/react-math-editor.git
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### C. Testing Lokal Tanpa Publish (`npm pack`)
|
|
164
|
+
Jalankan di folder library:
|
|
165
|
+
```bash
|
|
166
|
+
npm pack
|
|
167
|
+
```
|
|
168
|
+
Perintah ini akan menghasilkan file seperti `luvie-react-math-editor-1.0.0.tgz`. Di aplikasi lain, cukup jalankan:
|
|
169
|
+
```bash
|
|
170
|
+
npm install /path/ke/luvie-react-math-editor-1.0.0.tgz
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## 📄 Lisensi
|
|
176
|
+
[MIT License](LICENSE) © 2026
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface FormulaItem {
|
|
4
|
+
name: string;
|
|
5
|
+
category: string;
|
|
6
|
+
code: string;
|
|
7
|
+
description: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const DEFAULT_FORMULAS: FormulaItem[];
|
|
10
|
+
export interface LatexCheatSheetModalProps {
|
|
11
|
+
isOpen: boolean;
|
|
12
|
+
onClose: () => void;
|
|
13
|
+
onSelectFormula: (code: string) => void;
|
|
14
|
+
}
|
|
15
|
+
export declare function LatexCheatSheetModal({ isOpen, onClose, onSelectFormula, }: LatexCheatSheetModalProps): React.JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface MathFormulaModalProps {
|
|
4
|
+
isOpen: boolean;
|
|
5
|
+
initialValue?: string;
|
|
6
|
+
onClose: () => void;
|
|
7
|
+
onSubmit: (latex: string) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function MathFormulaModal({ isOpen, initialValue, onClose, onSubmit, }: MathFormulaModalProps): React.JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface RenderMathHTMLProps {
|
|
4
|
+
html: string;
|
|
5
|
+
className?: string;
|
|
6
|
+
style?: React.CSSProperties;
|
|
7
|
+
resolveImageUrl?: (url: string) => Promise<string> | string;
|
|
8
|
+
}
|
|
9
|
+
export declare function RenderMathHTML({ html, className, style, resolveImageUrl, }: RenderMathHTMLProps): React.JSX.Element;
|
|
10
|
+
export default RenderMathHTML;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface TextEditorProps {
|
|
4
|
+
value?: string;
|
|
5
|
+
onChange?: (html: string) => void;
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
readOnly?: boolean;
|
|
9
|
+
className?: string;
|
|
10
|
+
minHeight?: number | string;
|
|
11
|
+
maxHeight?: number | string;
|
|
12
|
+
onUploadImage?: (file: File) => Promise<string>;
|
|
13
|
+
toolbarExtra?: React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
export declare function TextEditor({ value, onChange, placeholder, disabled, readOnly, className, minHeight, maxHeight, onUploadImage, toolbarExtra, }: TextEditorProps): React.JSX.Element;
|