@noseberry/nbd-editor 1.0.1 → 1.1.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/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # @noseberry/nbd-editor
1
+ # NBD Editor
2
2
 
3
3
  > We'd love to hear from you! If you run into any bugs, have feature requests, or just want to share how you're using NBD Editor, please [open an issue](https://github.com/Noseberry-Private-Limited/NBD-editor/issues). Your feedback helps us make NBD Editor better for everyone.
4
4
 
5
- A powerful, framework-agnostic block editor built by **Noseberry Private Limited**. Inspired by WordPress Gutenberg, NBD Editor gives you a clean, modern content editing experience with drag-and-drop blocks, rich text formatting, media uploads, and a slash command menu — all in a single lightweight package with **zero production dependencies**.
5
+ A powerful, framework-agnostic block editor. NBD Editor gives you a clean, modern content editing experience with drag-and-drop blocks, rich text formatting, media uploads, and a slash command menu — all in a single lightweight package with **zero production dependencies**.
6
6
 
7
7
  Works seamlessly with **vanilla JavaScript**, **React**, and **Next.js**.
8
8
 
@@ -11,7 +11,7 @@ Works seamlessly with **vanilla JavaScript**, **React**, and **Next.js**.
11
11
  - **Drop-in ready** — one import, one line of code, and you have a full block editor
12
12
  - **Framework agnostic** — works with any frontend stack; optional React wrapper included
13
13
  - **20+ block types** — paragraphs, headings, images, video, audio, tables, columns, code, embeds, and more
14
- - **Rich editing** — inline formatting toolbar, slash commands (`/`), drag-and-drop reordering, undo/redo
14
+ - **Rich editing** — inline formatting toolbar (draggable), slash commands (`/`), drag-and-drop reordering, undo/redo
15
15
  - **Media support** — upload images, video, audio, and files with drag-and-drop or file picker
16
16
  - **Simple data model** — `getData()` returns `{ content: '<p>...</p>' }` — just store one HTML string
17
17
  - **TypeScript support** — full type definitions included for autocomplete and type safety
@@ -77,6 +77,7 @@ The editor manages its own state internally. You interact with it through callba
77
77
  - [Data Contract](#data-contract)
78
78
  - [Block Types](#block-types)
79
79
  - [Media Handling](#media-handling)
80
+ - [Theming](#theming)
80
81
  - [Keyboard Shortcuts](#keyboard-shortcuts)
81
82
  - [Events](#events)
82
83
  - [Build from Source](#build-from-source)
@@ -253,21 +254,40 @@ export default function EditorPage() {
253
254
  | `redo(opts?)` | Redo last undone action |
254
255
  | `destroy()` | Destroys the editor instance and cleans up |
255
256
 
256
- ### Important: Avoid Re-controlling Content
257
+ ### Controlled Mode (like React Quill)
257
258
 
258
- The `content` prop is treated as an **initial/external value**. Do NOT bind it to state that updates on every keystroke:
259
+ NBD Editor supports the controlled component pattern bind `content` to state and update it via `onChange`:
259
260
 
260
261
  ```jsx
261
- // BAD causes infinite re-render loop
262
- const [content, setContent] = useState('<p>Hello</p>');
263
- <ReactNBDEditor content={content} onChange={(d) => setContent(d.content)} />
262
+ import React, { useState } from 'react';
263
+ import { ReactNBDEditor } from '@noseberry/nbd-editor';
264
+ import '@noseberry/nbd-editor/style.css';
265
+
266
+ export default function EditorPage() {
267
+ const [content, setContent] = useState('<p>Hello World</p>');
264
268
 
265
- // GOOD — use content only for initial value or external resets
266
- const [initialContent] = useState('<p>Hello</p>');
267
- <ReactNBDEditor content={initialContent} onChange={(d) => console.log(d)} />
269
+ return (
270
+ <ReactNBDEditor
271
+ content={content}
272
+ onChange={(data) => setContent(data.content)}
273
+ siteName="My App"
274
+ authorName="Harshit"
275
+ />
276
+ );
277
+ }
268
278
  ```
269
279
 
270
- If you need to update the editor's content programmatically from the parent, use the ref:
280
+ For heavy content or frequent updates, use `debounceMs` to limit how often `onChange` fires:
281
+
282
+ ```jsx
283
+ <ReactNBDEditor
284
+ content={content}
285
+ onChange={(data) => setContent(data.content)}
286
+ debounceMs={300} // fires onChange at most every 300ms
287
+ />
288
+ ```
289
+
290
+ You can also use `content` as a one-time initial value and use the ref for everything else:
271
291
 
272
292
  ```jsx
273
293
  editorRef.current?.setData({ content: '<p>New content from server</p>' });
@@ -410,6 +430,7 @@ Pass these as the second argument to `new NBDEditor(selector, options)` or as pr
410
430
  | `className` | `string` | CSS class for the wrapper `div` |
411
431
  | `style` | `object` | Inline styles for the wrapper `div` |
412
432
  | `onReady` | `(editor) => void` | Called once the editor instance is initialized |
433
+ | `debounceMs` | `number` | Debounce delay (ms) for `onChange` — reduces re-renders in controlled mode |
413
434
 
414
435
  ---
415
436
 
@@ -520,6 +541,47 @@ Files exceeding `maxFileSize` are blocked from uploading. Users can also drag an
520
541
 
521
542
  ---
522
543
 
544
+ ## Theming
545
+
546
+ NBD Editor exposes a set of CSS custom properties on `.fe-root` that you can override to match your brand. Set them on `.fe-root` or any ancestor element:
547
+
548
+ ```css
549
+ .fe-root {
550
+ --fe-blue: #8b5cf6; /* accent / primary colour */
551
+ --fe-blue-hover: #7c3aed;
552
+ --fe-bg: #fafafa; /* editor shell background */
553
+ --fe-canvas-bg: #f9fafb; /* writing canvas background */
554
+ --fe-text: #111827; /* primary text colour */
555
+ --fe-font: 'Inter', sans-serif;
556
+ --fe-radius: 8px; /* border radius */
557
+ --fe-content-font-size: 16px; /* body text size inside blocks */
558
+ --fe-content-line-height: 1.7;
559
+ }
560
+ ```
561
+
562
+ All available tokens:
563
+
564
+ | Variable | Default | Description |
565
+ |---|---|---|
566
+ | `--fe-blue` | `#3b82f6` | Accent / primary colour |
567
+ | `--fe-blue-hover` | `#2563eb` | Accent hover state |
568
+ | `--fe-text` | `#1e1e1e` | Primary text colour |
569
+ | `--fe-light-text` | `#6b7280` | Secondary / muted text |
570
+ | `--fe-bg` | `#f8f9fb` | Editor shell background |
571
+ | `--fe-canvas-bg` | `#ffffff` | Writing canvas background |
572
+ | `--fe-hover-bg` | `#f3f4f6` | Hover / subtle highlight |
573
+ | `--fe-border` | `#e2e4e9` | Border colour |
574
+ | `--fe-success` | `#10b981` | Success state colour |
575
+ | `--fe-danger` | `#ef4444` | Destructive / error colour |
576
+ | `--fe-radius` | `6px` | Border radius |
577
+ | `--fe-font` | system-ui stack | Font family |
578
+ | `--fe-header-height` | `60px` | Height of the sticky header bar |
579
+ | `--fe-status-bar-height` | `32px` | Height of the bottom status bar |
580
+ | `--fe-content-font-size` | `15px` | Body text size inside blocks |
581
+ | `--fe-content-line-height` | `1.65` | Body line height inside blocks |
582
+
583
+ ---
584
+
523
585
  ## Keyboard Shortcuts
524
586
 
525
587
  | Shortcut | Action |
@@ -557,8 +619,6 @@ editor.on('input', (block) => { }); // Block content input
557
619
  ## Build from Source
558
620
 
559
621
  ```bash
560
- git clone git@github.com:Noseberry-Private-Limited/NBD-editor.git
561
- cd NBD-editor
562
622
  npm install
563
623
  npm run build
564
624
  ```