axiom-editor 1.0.2 → 1.0.4

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Aditya
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 CHANGED
@@ -1,99 +1,231 @@
1
1
  # AxiomEditor
2
2
 
3
- A premium, modular narrative architecture block editor built on React, Tiptap, and Tailwind CSS.
3
+ A premium, modular narrative architecture block editor built on **React**, **Tiptap**, and **Tailwind CSS**.
4
4
 
5
- AxiomEditor provides a ready-to-use monolithic editor wrapper while remaining completely modular, allowing developers to construct custom editing layouts by arranging the core providers, toolbars, and canvas elements.
5
+ AxiomEditor is designed for modern developers who need a gorgeous, distraction-free editing interface out of the box, but require the flexibility to tear it down and build custom compositions. By default, it ships with a dark-mode obsidian aesthetic, custom multi-color highlights, drag-and-drop media embeds, and clean AST rendering support.
6
6
 
7
7
  ---
8
8
 
9
- ## Features
9
+ ## Key Features
10
10
 
11
- - 📝 **Tiptap Core Integration:** Clean, extensible rich-text editing.
12
- - 🎨 **Themeable Design System:** Easily toggle between dark, light, or custom color schemes using CSS Custom Properties (CSS variables).
13
- - 🧩 **Modular Architecture:** Arrange toolbars, scroll windows, and modals wherever they fit best in your layout.
14
- - 🖋️ **Advanced Multi-Color Styling:** Highlight, bold, underline, or strike-through words with custom colors concurrently.
15
- - 🖼️ **Media Embeds:** Built-in support for YouTube, X (Twitter), Instagram, and inline image uploads.
16
- - 🤖 **Developer AST Output:** Export and render raw serialized JSON nodes dynamically.
11
+ * ✨ **Monolithic & Modular APIs:** Use the all-in-one `<AxiomEditor />` component for instant setup, or compose custom layouts using `<AxiomEditorProvider />`, `<AxiomToolbar />`, and `<AxiomContent />`.
12
+ * 🚀 **Advanced Slash Commands:** Press `/` on a blank line to trigger a fluid slash command dropdown with smooth transitions and keyboard navigation support.
13
+ * 🎨 **Full Design Token Control:** Every color, border, and background is mapped to standard CSS custom properties. Customize the editor to light mode, amber mode, or your corporate brand with single CSS overrides.
14
+ * 🌈 **Simultaneous Multi-Color Highlighting:** Support for concurrently underlining or striking-through text in multiple custom colors (Bone, Amber, Charcoal, Obsidian, and Accent Primary).
15
+ * 🖼️ **Advanced Media System:** Drop-in embeds for **YouTube** videos, **X (Twitter)** posts, **Instagram** reels, and inline image uploads with resizing handles and captions.
16
+ * 📊 **Sync & Word Count Indicator:** Minimalist bottom status bar showing word counts and a Pulsing Sync indicator representing save-states.
17
+ * 💾 **Serialized JSON AST Parser:** Direct access to Tiptap JSON abstract syntax trees (AST) and a fast renderer component (`<AxiomJSONRenderer />`) to display them on user pages.
17
18
 
18
19
  ---
19
20
 
20
21
  ## Installation
21
22
 
22
- Install the package and its peer dependencies in your React project:
23
+ Install the package and its required peer dependencies in your React project:
23
24
 
24
25
  ```bash
25
26
  npm install axiom-editor lucide-react react react-dom
26
27
  ```
27
28
 
29
+ ### Import Styles
30
+ Make sure to import the editor stylesheet in your main entry file (e.g., `main.tsx` or `_app.tsx`):
31
+
32
+ ```tsx
33
+ import 'axiom-editor/style.css';
34
+ ```
35
+
28
36
  ---
29
37
 
30
- ## Quick Start
38
+ ## Implementation Guide
31
39
 
32
- Import the editor and its stylesheet, and mount it in your React application:
40
+ ### 1. Quick Start (Monolithic Layout)
41
+
42
+ For standard setups, use the monolithic wrapper which includes a top sticky toolbar, a fixed-height editor canvas, and automated media modal routing.
33
43
 
34
44
  ```tsx
35
45
  import React, { useState } from 'react';
36
46
  import { AxiomEditor } from 'axiom-editor';
37
- import 'axiom-editor/style.css'; // Don't forget to import the CSS!
47
+ import type { JSONContent } from '@tiptap/core';
48
+ import 'axiom-editor/style.css';
38
49
 
39
50
  function App() {
40
- const [content, setContent] = useState('<p>Welcome to AxiomEditor!</p>');
51
+ const [content, setContent] = useState<JSONContent | string>('<p>Write your narrative here...</p>');
41
52
 
42
53
  return (
43
- <div style={{ padding: '2rem', background: '#121212' }}>
44
- <AxiomEditor
45
- initialContent={content}
46
- onChange={(json, html) => setContent(html)}
47
- />
54
+ <div className="min-h-screen bg-neutral-900 p-8 flex items-center justify-center">
55
+ <div className="w-full max-w-4xl bg-neutral-950 p-6 rounded-2xl border border-neutral-800">
56
+ <AxiomEditor
57
+ initialContent={content}
58
+ onChange={(json, html) => {
59
+ console.log('JSON AST:', json);
60
+ console.log('HTML String:', html);
61
+ }}
62
+ />
63
+ </div>
48
64
  </div>
49
65
  );
50
66
  }
67
+
68
+ export default App;
69
+ ```
70
+
71
+ ---
72
+
73
+ ### 2. Advanced Modular UI Composition
74
+
75
+ If you want a custom layout—such as placing the toolbar at the bottom, embedding the editor canvas in a floating card, or building custom sidebar controls—you can compose the subcomponents directly.
76
+
77
+ All child components inside `<AxiomEditorProvider />` share the editor context automatically via the `useAxiomEditor` hook.
78
+
79
+ ```tsx
80
+ import React from 'react';
81
+ import {
82
+ AxiomEditorProvider,
83
+ AxiomToolbar,
84
+ AxiomContent,
85
+ MediaMenu,
86
+ useAxiomEditor
87
+ } from 'axiom-editor';
88
+
89
+ function CustomSyncIndicator() {
90
+ const { editor } = useAxiomEditor();
91
+ if (!editor) return null;
92
+
93
+ return (
94
+ <div className="text-xs text-neutral-500 font-mono">
95
+ Words: {editor.storage.characterCount.words()}
96
+ </div>
97
+ );
98
+ }
99
+
100
+ function CustomLayoutEditor() {
101
+ return (
102
+ <AxiomEditorProvider initialContent="Composition is key.">
103
+ <div className="flex flex-col gap-6 p-4 border rounded-3xl bg-black">
104
+
105
+ {/* Render Canvas First */}
106
+ <div className="p-4 bg-zinc-900/50 rounded-2xl">
107
+ <AxiomContent />
108
+ </div>
109
+
110
+ {/* Render Toolbar Below the Canvas */}
111
+ <div className="p-2 border-t border-zinc-800 flex items-center justify-between">
112
+ <AxiomToolbar />
113
+ <CustomSyncIndicator />
114
+ </div>
115
+
116
+ {/* The Media Insertion Modals */}
117
+ <MediaMenu />
118
+ </div>
119
+ </AxiomEditorProvider>
120
+ );
121
+ }
122
+ ```
123
+
124
+ ---
125
+
126
+ ### 3. Native Image Upload Handler
127
+
128
+ Configure the `uploadImage` hook to handle local file selection and return a secure uploaded image URL. Below is a production-ready example integrating with **Cloudinary**:
129
+
130
+ ```tsx
131
+ const handleImageUpload = async (file: File): Promise<string> => {
132
+ const formData = new FormData();
133
+ formData.append('file', file);
134
+ formData.append('upload_preset', 'your_unsigned_preset'); // Replace with your preset
135
+ formData.append('cloud_name', 'your_cloudinary_cloud_name'); // Replace with your cloud name
136
+
137
+ const response = await fetch(
138
+ `https://api.cloudinary.com/v1_1/your_cloudinary_cloud_name/image/upload`,
139
+ {
140
+ method: 'POST',
141
+ body: formData,
142
+ }
143
+ );
144
+
145
+ if (!response.ok) {
146
+ throw new Error('Image upload failed');
147
+ }
148
+
149
+ const result = await response.json();
150
+ return result.secure_url; // Returns the public hosting URL for Tiptap
151
+ };
152
+
153
+ // Usage:
154
+ // <AxiomEditor uploadImage={handleImageUpload} ... />
51
155
  ```
52
156
 
53
157
  ---
54
158
 
55
159
  ## Custom Theming
56
160
 
57
- AxiomEditor is styled using Tailwind classes mapped internally to CSS custom properties. By default, it runs in a sleek dark theme.
161
+ AxiomEditor namespaced classes are bound to CSS variables, preventing compilation purges in host projects and ensuring complete customizability. By default, it features a rich dark-mode theme.
58
162
 
59
- To change the theme or create your own, simply target the `.axiom-editor-wrapper` selector in your own CSS and override the custom properties:
163
+ To override colors, target the `.axiom-editor-wrapper` wrapper in your CSS:
60
164
 
61
- ### Example: Light Mode Theme
62
165
  ```css
166
+ /* Custom Light Mode Theme */
63
167
  .axiom-editor-wrapper {
64
- --axiom-bg: #ffffff; /* Editor background */
65
- --axiom-bg-card: #f4f4f5; /* Dropdown backgrounds */
66
- --axiom-text: #09090b; /* Main text color */
67
- --axiom-text-muted: #71717a; /* Subtitles & placeholders */
68
- --axiom-border: #e4e4e7; /* Borders & dividers */
69
- --axiom-primary: #ef4444; /* Active highlights & accents */
168
+ --axiom-bg: #ffffff;
169
+ --axiom-bg-card: #f4f4f5;
170
+ --axiom-text: #09090b;
171
+ --axiom-text-muted: #71717a;
172
+ --axiom-border: #e4e4e7;
173
+ --axiom-border-separator: #d4d4d8;
174
+ --axiom-primary: #f59e0b; /* Amber accent highlight */
175
+ --axiom-primary-text: #09090b;
176
+ --axiom-primary-text-muted: #d97706;
177
+ --axiom-button-active: #f3f4f6;
178
+ --axiom-button-active-text: #0f172a;
70
179
  }
71
180
  ```
72
181
 
182
+ ### Full Token References
183
+
184
+ | CSS Variable | Description | Default Dark Theme Value |
185
+ | :--- | :--- | :--- |
186
+ | `--axiom-bg` | Main editor viewport background | `#0f0f10` (Obsidian black) |
187
+ | `--axiom-bg-card` | Menus, popups, and modal background | `#18181b` (Charcoal zinc) |
188
+ | `--axiom-text` | Body and header text | `#fafafa` (Bone white) |
189
+ | `--axiom-text-muted` | Secondary indicators, placeholders | `#71717a` (Steel gray) |
190
+ | `--axiom-border` | Component borders and wrappers | `rgba(250, 250, 250, 0.1)` |
191
+ | `--axiom-border-separator` | Internal toolbar separator vertical rules | `rgba(250, 250, 250, 0.06)` |
192
+ | `--axiom-primary` | Accent highlight color | `#ffbf00` (Amber gold) |
193
+ | `--axiom-primary-text` | Text color on active primary buttons | `#0f0f10` |
194
+ | `--axiom-primary-text-muted`| Colored highlights, word count save states | `#ffbf00` |
195
+ | `--axiom-button-active` | Active formatting state buttons background | `rgba(250, 250, 250, 0.08)` |
196
+ | `--axiom-button-active-text`| Active state icon/font color | `#ffbf00` |
197
+
73
198
  ---
74
199
 
75
- ## Modular UI Composition
200
+ ## Rendering Content Outside the Editor
76
201
 
77
- If you do not want the standard top-toolbar layout, you can arrange the modular components inside the `AxiomEditorProvider` block:
202
+ When saving content from the editor, you should store the **JSON AST** output. To render this JSON back on your website or article page with correct narrative styling, use `<AxiomJSONRenderer />`:
78
203
 
79
204
  ```tsx
80
- import {
81
- AxiomEditorProvider,
82
- AxiomToolbar,
83
- AxiomContent,
84
- MediaMenu
85
- } from 'axiom-editor';
86
-
87
- function CustomEditor() {
205
+ import React from 'react';
206
+ import { AxiomJSONRenderer } from 'axiom-editor';
207
+
208
+ const savedArticleJson = {
209
+ type: "doc",
210
+ content: [
211
+ {
212
+ type: "heading",
213
+ attrs: { level: 1 },
214
+ content: [{ type: "text", text: "Stunning Block Architectures" }]
215
+ },
216
+ {
217
+ type: "paragraph",
218
+ content: [{ type: "text", text: "This content was rendered directly from JSON AST." }]
219
+ }
220
+ ]
221
+ };
222
+
223
+ function ArticlePage() {
88
224
  return (
89
- <AxiomEditorProvider initialContent="...">
90
- <div className="my-custom-layout">
91
- {/* Render editor canvas first, then toolbar on bottom */}
92
- <AxiomContent />
93
- <AxiomToolbar />
94
- <MediaMenu />
95
- </div>
96
- </AxiomEditorProvider>
225
+ <article className="max-w-3xl mx-auto p-6 bg-zinc-950 text-white">
226
+ {/* Renders Tiptap nodes natively using React elements */}
227
+ <AxiomJSONRenderer content={savedArticleJson} />
228
+ </article>
97
229
  );
98
230
  }
99
231
  ```
@@ -102,26 +234,28 @@ function CustomEditor() {
102
234
 
103
235
  ## API Reference
104
236
 
105
- ### `<AxiomEditor />`
106
- Out-of-the-box wrapper for ease-of-use.
107
- - `initialContent`: `string | JSONContent` - Initial document value.
108
- - `onChange`: `(json: JSONContent, html: string) => void` - Triggers when text changes.
109
- - `uploadImage`: `(file: File) => Promise<string>` - Async hook for uploading images.
110
-
111
- ### `<AxiomEditorProvider />`
112
- Manages Tiptap instances and state. Essential for modular composition.
237
+ ### Props: `<AxiomEditor />` & `<AxiomEditorProvider />`
113
238
 
114
- ### `<AxiomContent />`
115
- The text editing canvas. Automatically handles text scrolling and caps at 650px.
239
+ | Prop | Type | Description |
240
+ | :--- | :--- | :--- |
241
+ | `initialContent` | `string \| JSONContent` | Initial markdown, HTML string, or parsed JSON AST document content. |
242
+ | `onChange` | `(json: JSONContent, html: string) => void` | Event fires on text/formatting changes, returning the AST and HTML string. |
243
+ | `uploadImage` | `(file: File) => Promise<string>` | Async file uploading function returning a public url path. |
244
+ | `minHeightClass` | `string` | Optional CSS height class for canvas height configuration. |
245
+ | `maxHeightClass` | `string` | Optional CSS height class for max constraints configuration. |
116
246
 
117
- ### `<AxiomToolbar />`
118
- The responsive text formatting and media-insertion toolbar.
247
+ ### Component Exports
119
248
 
120
- ### `<AxiomJSONRenderer />`
121
- A fast React component to render serialized Tiptap JSON AST directly to elements.
249
+ * **`<AxiomEditor />`**: Easy-to-use monolithic component with built-in toolbar, canvas, and insertion routing.
250
+ * **`<AxiomEditorProvider />`**: Context wrapper mapping editor instances. Required for composing custom layouts.
251
+ * **`<AxiomContent />`**: Editor editor content layer with scroll constraints and styling namespaces.
252
+ * **`<AxiomToolbar />`**: Text layout modifiers, formatting utilities, headers, and video hooks.
253
+ * **`<MediaMenu />`**: Absolute-overlay modal triggers handling links, tweets, YouTube, and image attachments.
254
+ * **`<AxiomJSONRenderer />`**: High performance rendering agent mapping saved JSON schemas back to React nodes.
255
+ * **`useAxiomEditor()`**: Custom hook retrieving current `{ editor }` instance variables and status.
122
256
 
123
257
  ---
124
258
 
125
259
  ## License
126
260
 
127
- MIT © Axiom Editor Team
261
+ This project is licensed under the [MIT License](./LICENSE).