@particle-academy/react-fancy 4.13.0 → 4.14.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 +1 -1
- package/dist/index.cjs +129 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +67 -10
- package/dist/index.d.ts +67 -10
- package/dist/index.js +129 -38
- package/dist/index.js.map +1 -1
- package/docs/Editor.md +55 -1
- package/package.json +1 -1
package/docs/Editor.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Editor
|
|
2
2
|
|
|
3
|
-
A rich text editor built on `contentEditable` with a configurable toolbar, HTML or Markdown output, and support for render extensions.
|
|
3
|
+
A rich text editor built on `contentEditable` with a configurable toolbar, HTML or Markdown output, a **Source** toggle for editing the raw markup, and support for render extensions.
|
|
4
4
|
|
|
5
5
|
## Import
|
|
6
6
|
|
|
@@ -30,6 +30,9 @@ import { Editor } from "@particle-academy/react-fancy";
|
|
|
30
30
|
| lineSpacing | `number` | `1.6` | Line height for content area |
|
|
31
31
|
| placeholder | `string` | - | Placeholder text |
|
|
32
32
|
| extensions | `RenderExtension[]` | - | Per-instance render extensions (merged with global) |
|
|
33
|
+
| showSource | `boolean` | - | Controlled source-view flag. When `true`, the content area shows the raw `value` (in `outputFormat`) in an editable `<textarea>` |
|
|
34
|
+
| defaultShowSource | `boolean` | `false` | Initial source-view flag when uncontrolled |
|
|
35
|
+
| onShowSourceChange | `(showSource: boolean) => void` | - | Fired when the Source toggle (or an agent) flips source view on/off |
|
|
33
36
|
| className | `string` | - | Additional CSS classes |
|
|
34
37
|
|
|
35
38
|
### Editor.Toolbar
|
|
@@ -39,6 +42,7 @@ import { Editor } from "@particle-academy/react-fancy";
|
|
|
39
42
|
| actions | `EditorAction[]` | - | Custom toolbar actions |
|
|
40
43
|
| onAction | `(command: string) => void` | - | Custom action handler |
|
|
41
44
|
| children | `ReactNode` | - | Custom toolbar content |
|
|
45
|
+
| showSourceToggle | `boolean` | `true` | Append a Source toggle to the default toolbar. Ignored when `children` are supplied — custom toolbars compose their own `<Editor.SourceToggle />` |
|
|
42
46
|
| className | `string` | - | Additional CSS classes |
|
|
43
47
|
|
|
44
48
|
#### EditorAction
|
|
@@ -55,12 +59,24 @@ import { Editor } from "@particle-academy/react-fancy";
|
|
|
55
59
|
|
|
56
60
|
A visual separator between toolbar groups. No props.
|
|
57
61
|
|
|
62
|
+
### Editor.SourceToggle
|
|
63
|
+
|
|
64
|
+
A toolbar button that reveals the raw HTML/Markdown behind the editor. It is appended to the default toolbar automatically; add it to a **custom** toolbar wherever you like. Reads `showSource` / `setShowSource` from context.
|
|
65
|
+
|
|
66
|
+
| Prop | Type | Default | Description |
|
|
67
|
+
|------|------|---------|-------------|
|
|
68
|
+
| icon | `ReactNode` | `</>` | Toggle glyph/label |
|
|
69
|
+
| title | `string` | `"Source"` | Accessible title in rich-text mode (click → source) |
|
|
70
|
+
| activeTitle | `string` | `"Rich text"` | Accessible title in source mode (click → rich text) |
|
|
71
|
+
| className | `string` | - | Additional CSS classes |
|
|
72
|
+
|
|
58
73
|
### Editor.Content
|
|
59
74
|
|
|
60
75
|
| Prop | Type | Default | Description |
|
|
61
76
|
|------|------|---------|-------------|
|
|
62
77
|
| className | `string` | - | Additional CSS classes |
|
|
63
78
|
| maxHeight | `number` | - | Max height in px before scrolling. When set, the content area becomes scrollable. |
|
|
79
|
+
| sourceClassName | `string` | - | Classes applied to the raw-source `<textarea>` shown while source mode is on |
|
|
64
80
|
|
|
65
81
|
## Markdown Output
|
|
66
82
|
|
|
@@ -71,6 +87,42 @@ A visual separator between toolbar groups. No props.
|
|
|
71
87
|
</Editor>
|
|
72
88
|
```
|
|
73
89
|
|
|
90
|
+
## Source View
|
|
91
|
+
|
|
92
|
+
The default toolbar includes a **Source** toggle (`</>`) on the right. Clicking it
|
|
93
|
+
swaps the rich-text surface for a `<textarea>` showing the raw markup — HTML when
|
|
94
|
+
`outputFormat="html"`, Markdown when `outputFormat="markdown"`. Edits made in the
|
|
95
|
+
textarea flow straight to `value`; toggling back re-renders the rich-text surface
|
|
96
|
+
from the edited source. Formatting buttons in the default toolbar are disabled
|
|
97
|
+
while source view is open.
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
// Source toggle is on by default — nothing to wire up.
|
|
101
|
+
<Editor defaultValue="<p>Hello world</p>" outputFormat="html">
|
|
102
|
+
<Editor.Toolbar />
|
|
103
|
+
<Editor.Content />
|
|
104
|
+
</Editor>
|
|
105
|
+
|
|
106
|
+
// Opt out of the default toggle:
|
|
107
|
+
<Editor.Toolbar showSourceToggle={false} />
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Drive it yourself (controlled), or drop the toggle into a custom toolbar:
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
<Editor
|
|
114
|
+
showSource={showSource}
|
|
115
|
+
onShowSourceChange={setShowSource}
|
|
116
|
+
defaultValue="<p>Hello</p>"
|
|
117
|
+
>
|
|
118
|
+
<Editor.Toolbar>
|
|
119
|
+
<CustomToolbarButtons />
|
|
120
|
+
<Editor.SourceToggle className="ml-auto" />
|
|
121
|
+
</Editor.Toolbar>
|
|
122
|
+
<Editor.Content />
|
|
123
|
+
</Editor>
|
|
124
|
+
```
|
|
125
|
+
|
|
74
126
|
## Scrollable Editor
|
|
75
127
|
|
|
76
128
|
Constrain the editor's height and let it scroll instead of growing the page:
|
|
@@ -113,6 +165,8 @@ function CustomToolbarButtons() {
|
|
|
113
165
|
| lineSpacing | `number` | Current line spacing |
|
|
114
166
|
| placeholder | `string` | Current placeholder text |
|
|
115
167
|
| extensions | `RenderExtension[]` | Merged render extensions (global + instance) |
|
|
168
|
+
| showSource | `boolean` | Whether the raw-source view is showing instead of the rich-text surface |
|
|
169
|
+
| setShowSource | `(showSource: boolean) => void` | Toggle/set the raw-source view |
|
|
116
170
|
|
|
117
171
|
## Render Extensions
|
|
118
172
|
|