@pubwave/editor 0.3.0 → 0.5.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
@@ -17,14 +17,17 @@ A Notion-level block editor built with React and Tiptap.
17
17
  - 🎨 **Text & Background Colors** - Rich color picker with recently used colors
18
18
  - 🔄 **Turn Into** - Convert blocks between different types (paragraph, headings, lists, etc.)
19
19
  - 📋 **Rich Formatting** - Bold, italic, underline, strikethrough, code, and links
20
- - 📝 **Multiple Block Types** - Paragraphs, headings, lists, quotes, code blocks, and more
20
+ - 📝 **Multiple Block Types** - Paragraphs, headings, lists, quotes, code blocks, charts, and more
21
21
  - 🖼️ **Image Support** - Upload images via file picker or paste from clipboard, with base64 or custom upload service
22
+ - 📊 **Chart Support** - Interactive charts powered by Chart.js with editable data
22
23
  - 🌐 **Internationalization** - Multi-language support with English as default
23
24
 
24
25
  ---
25
26
 
26
27
  ## 📦 Installation
27
28
 
29
+ ### Basic Installation (without Chart support)
30
+
28
31
  ```bash
29
32
  npm install @pubwave/editor
30
33
  # or
@@ -33,6 +36,20 @@ yarn add @pubwave/editor
33
36
  pnpm add @pubwave/editor
34
37
  ```
35
38
 
39
+ ### With Chart Support
40
+
41
+ If you want to use Chart blocks, also install Chart.js:
42
+
43
+ ```bash
44
+ npm install @pubwave/editor chart.js
45
+ # or
46
+ yarn add @pubwave/editor chart.js
47
+ # or
48
+ pnpm add @pubwave/editor chart.js
49
+ ```
50
+
51
+ **Note:** `chart.js` is an optional peer dependency. Only install it if you plan to use Chart block functionality.
52
+
36
53
  ---
37
54
 
38
55
  ## 🚀 Quick Start
@@ -72,6 +89,12 @@ function MyEditor() {
72
89
  | 18.x | ✅ Tested, Recommended |
73
90
  | 19.x | ✅ Supported |
74
91
 
92
+ ### Peer Dependencies
93
+
94
+ - `react`: ^18.0.0 || ^19.0.0 (required)
95
+ - `react-dom`: ^18.0.0 || ^19.0.0 (required)
96
+ - `chart.js`: ^4.0.0 || ^5.0.0 (optional, required only for Chart block support)
97
+
75
98
  ### Browser Support
76
99
 
77
100
  - Chrome (latest)
@@ -442,6 +465,7 @@ The editor supports the following block types:
442
465
  - **Numbered List** - Ordered list with numbers
443
466
  - **Task List** - Checklist with checkboxes
444
467
  - **Image** - Image block (supports base64 or URL)
468
+ - **Chart** - Interactive chart powered by Chart.js (bar, line, pie, doughnut, radar, polar area)
445
469
  - **Blockquote** - Quote block
446
470
  - **Code Block** - Code snippet with syntax highlighting
447
471
  - **Horizontal Rule** - Divider line
@@ -631,6 +655,123 @@ const customCommands: SlashCommand[] = [
631
655
 
632
656
  ---
633
657
 
658
+ ## 📊 Chart Support
659
+
660
+ The editor includes support for interactive charts powered by Chart.js. Charts are fully editable and support multiple chart types.
661
+
662
+ ### Chart Types
663
+
664
+ Supported chart types:
665
+ - **Bar Chart** - Vertical/horizontal bars for comparisons
666
+ - **Line Chart** - Data trends over time
667
+ - **Pie Chart** - Proportional data representation
668
+ - **Doughnut Chart** - Variation of pie chart with hollow center
669
+ - **Radar Chart** - Multi-dimensional data comparison
670
+ - **Polar Area Chart** - Circular data visualization
671
+
672
+ ### Adding Charts Programmatically
673
+
674
+ ```tsx
675
+ import { PubwaveEditor } from '@pubwave/editor';
676
+ import type { JSONContent } from '@tiptap/core';
677
+
678
+ const contentWithChart: JSONContent = {
679
+ type: 'doc',
680
+ content: [
681
+ {
682
+ type: 'chart',
683
+ attrs: {
684
+ data: {
685
+ type: 'bar',
686
+ data: {
687
+ labels: ['January', 'February', 'March', 'April'],
688
+ datasets: [{
689
+ label: 'Sales',
690
+ data: [65, 59, 80, 81],
691
+ backgroundColor: 'rgba(59, 130, 246, 0.7)',
692
+ borderColor: 'rgba(59, 130, 246, 1)',
693
+ borderWidth: 2,
694
+ }],
695
+ },
696
+ options: {
697
+ responsive: true,
698
+ maintainAspectRatio: false,
699
+ plugins: {
700
+ title: {
701
+ display: true,
702
+ text: 'Monthly Sales',
703
+ color: 'var(--pubwave-text, #37352f)',
704
+ },
705
+ legend: {
706
+ display: true,
707
+ position: 'bottom',
708
+ },
709
+ },
710
+ },
711
+ },
712
+ },
713
+ },
714
+ ],
715
+ };
716
+
717
+ <PubwaveEditor content={contentWithChart} />
718
+ ```
719
+
720
+ ### Chart Features
721
+
722
+ - **Interactive Editing** - Click edit button on hover to modify chart data
723
+ - **Drag & Drop** - Charts can be reordered like other blocks
724
+ - **Theme Support** - Charts use CSS variables for colors that adapt to theme changes
725
+ - **Responsive** - Charts automatically adjust to container size
726
+ - **Multiple Datasets** - Support for comparing multiple data series
727
+ - **Customizable** - Edit title, labels, colors, and chart options
728
+
729
+ ### Chart Data Structure
730
+
731
+ The chart node uses the following data structure:
732
+
733
+ ```typescript
734
+ interface ChartNodeData {
735
+ type: 'bar' | 'line' | 'pie' | 'doughnut' | 'radar' | 'polarArea';
736
+ data: {
737
+ labels: string[];
738
+ datasets: Array<{
739
+ label?: string;
740
+ data: number[];
741
+ backgroundColor?: string | string[];
742
+ borderColor?: string | string[];
743
+ borderWidth?: number;
744
+ }>;
745
+ };
746
+ options?: {
747
+ responsive?: boolean;
748
+ maintainAspectRatio?: boolean;
749
+ plugins?: {
750
+ title?: {
751
+ display?: boolean;
752
+ text?: string;
753
+ color?: string;
754
+ font?: { size?: number; weight?: string };
755
+ };
756
+ legend?: {
757
+ display?: boolean;
758
+ position?: 'top' | 'bottom' | 'left' | 'right';
759
+ };
760
+ };
761
+ };
762
+ }
763
+ ```
764
+
765
+ ### Chart Editing
766
+
767
+ When in editable mode:
768
+ 1. Hover over a chart to reveal the edit button
769
+ 2. Click the edit button to open the chart editor modal
770
+ 3. Modify chart type, title, labels, datasets, and appearance options
771
+ 4. Save changes to update the chart
772
+
773
+ ---
774
+
634
775
 
635
776
 
636
777
 
@@ -662,6 +803,17 @@ const customCommands: SlashCommand[] = [
662
803
  - Check browser console for error messages
663
804
  - If custom upload fails, editor will automatically fall back to base64
664
805
 
806
+ **Q: Charts don't render**
807
+ - Ensure `chart.js` is installed: `npm install chart.js` (optional peer dependency)
808
+ - Check that Chart.js is compatible (v4.x or v5.x)
809
+ - Verify chart data structure is correct
810
+ - Check browser console for errors
811
+
812
+ **Q: Chart colors don't match theme**
813
+ - Charts use CSS variables for colors that adapt to theme changes
814
+ - Ensure CSS custom properties are defined: `--pubwave-text`, `--pubwave-text-muted`, `--pubwave-border`
815
+ - Chart colors will automatically update when theme changes
816
+
665
817
  ---
666
818
 
667
819