@fvc/richtext 1.6.8 → 1.6.9-next-ec65dfb844e6183b3d7f417eee613cfe5ecfd997
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 +172 -0
- package/package.json +16 -3
package/README.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# @fvc/richtext
|
|
2
|
+
|
|
3
|
+
`@fvc/richtext` provides a WYSIWYG rich text editor built on top of `@cyber-wysiwyg/richtexteditor`. It extends the base editor with HTML sanitization, a template dropdown, a custom link modal, and design-system integration for FE-VIS applications. The `variant` prop switches between a full toolbar editor and a compact input appearance.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @fvc/richtext
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Peer Dependencies
|
|
12
|
+
|
|
13
|
+
The package expects these dependencies to be available in the consuming application:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
bun add react antd @fvc/button @fvc/icons @cyber-wysiwyg/richtexteditor
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Import
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { Richtext } from '@fvc/richtext';
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { Richtext } from '@fvc/richtext';
|
|
29
|
+
import { useState } from 'react';
|
|
30
|
+
|
|
31
|
+
export function NoteEditor() {
|
|
32
|
+
const [value, setValue] = useState('');
|
|
33
|
+
|
|
34
|
+
return <Richtext value={value} onChange={setValue} />;
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Common Usage
|
|
39
|
+
|
|
40
|
+
### Basic Editor
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
<Richtext value={content} onChange={setContent} />
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Input Variant
|
|
47
|
+
|
|
48
|
+
The `input` variant renders a compact single-line editor suitable for short text fields.
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
<Richtext variant="input" value={value} onChange={setValue} />
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Error State
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
<Richtext error value={value} onChange={setValue} />
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Auto Sanitization
|
|
61
|
+
|
|
62
|
+
HTML from untrusted sources is sanitized automatically when `autoSanitize` is enabled.
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
<Richtext autoSanitize value={untrustedHtml} onChange={setValue} />
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Template Dropdown
|
|
69
|
+
|
|
70
|
+
Inject predefined text snippets from a map of label→value pairs.
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
<Richtext
|
|
74
|
+
enableTemplateDropdown
|
|
75
|
+
templateDropdownLabel="Templates"
|
|
76
|
+
templateMap={{
|
|
77
|
+
Greeting: 'Dear {{name}},',
|
|
78
|
+
Signature: 'Kind regards,\n{{sender}}',
|
|
79
|
+
}}
|
|
80
|
+
value={value}
|
|
81
|
+
onChange={setValue}
|
|
82
|
+
/>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Custom Toolbar
|
|
86
|
+
|
|
87
|
+
Pass a function to extend the default toolbar settings.
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
<Richtext
|
|
91
|
+
toolbarSettings={(defaults) => ({
|
|
92
|
+
...defaults,
|
|
93
|
+
items: [...defaults.items, 'SourceCode'],
|
|
94
|
+
})}
|
|
95
|
+
value={value}
|
|
96
|
+
onChange={setValue}
|
|
97
|
+
/>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Props
|
|
101
|
+
|
|
102
|
+
Extends all [`RichTextEditor` props](https://github.com/cyber-wysiwyg/richtexteditor) except `toolbarSettings` (see the custom toolbar example above).
|
|
103
|
+
|
|
104
|
+
| Prop | Type | Default | Description |
|
|
105
|
+
| ------------------------ | ----------------------------------------------------------------------------- | ---------- | -------------------------------------------------------------- |
|
|
106
|
+
| `variant` | `'editor' \| 'input'` | `'editor'` | Switches between full toolbar editor and compact input mode. |
|
|
107
|
+
| `error` | `boolean` | — | Applies error styling to the editor border. |
|
|
108
|
+
| `autoSanitize` | `boolean` | — | Sanitizes HTML via DOMPurify on every value change. |
|
|
109
|
+
| `enableTemplateDropdown` | `boolean` | — | Shows the template insertion dropdown in the toolbar. |
|
|
110
|
+
| `templateMap` | `Record<string, string>` | — | Map of display label → template string to inject. |
|
|
111
|
+
| `templateDropdownLabel` | `string` | — | Label shown on the template dropdown button. |
|
|
112
|
+
| `toolbarSettings` | `ToolbarSettings \| ((defaults: ToolbarSettings) => ToolbarSettings)` | — | Toolbar config or function that receives and mutates defaults. |
|
|
113
|
+
| `className` | `string` | — | Additional CSS class names on the wrapper element. |
|
|
114
|
+
| `testId` | `string` | — | Maps to `data-testid` on the root element. |
|
|
115
|
+
|
|
116
|
+
## TypeScript
|
|
117
|
+
|
|
118
|
+
The package ships with type definitions. No `@types/` install needed.
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
import type { RichTextProps, TemplateMap, LinkModalProps } from '@fvc/richtext/types';
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Consumer Example
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
import { Richtext } from '@fvc/richtext';
|
|
128
|
+
import { useState } from 'react';
|
|
129
|
+
|
|
130
|
+
export function ArticleEditor({ onSave }) {
|
|
131
|
+
const [body, setBody] = useState('');
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<Richtext
|
|
135
|
+
autoSanitize
|
|
136
|
+
enableTemplateDropdown
|
|
137
|
+
templateDropdownLabel="Insert snippet"
|
|
138
|
+
templateMap={{
|
|
139
|
+
Opening: '<p>Dear reader,</p>',
|
|
140
|
+
Closing: '<p>Thank you for reading.</p>',
|
|
141
|
+
}}
|
|
142
|
+
toolbarSettings={(defaults) => ({
|
|
143
|
+
...defaults,
|
|
144
|
+
items: defaults.items.filter((i) => i !== 'SourceCode'),
|
|
145
|
+
})}
|
|
146
|
+
value={body}
|
|
147
|
+
onChange={setBody}
|
|
148
|
+
/>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Testing
|
|
154
|
+
|
|
155
|
+
Use `testId` to target the editor root in tests.
|
|
156
|
+
|
|
157
|
+
```tsx
|
|
158
|
+
<Richtext testId="article-editor" value={value} onChange={setValue} />
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
screen.getByTestId('article-editor');
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Development
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
bun run lint
|
|
169
|
+
bun run type-check
|
|
170
|
+
bun run test
|
|
171
|
+
bun run build
|
|
172
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fvc/richtext",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.9-next-ec65dfb844e6183b3d7f417eee613cfe5ecfd997",
|
|
4
4
|
"main": "./dist/lib/index.js",
|
|
5
5
|
"types": "./dist/lib/richtext/src/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -26,13 +26,26 @@
|
|
|
26
26
|
"type-check": "tsc --noEmit",
|
|
27
27
|
"test": "find src -name '*.test.*' -o -name '*.spec.*' | grep -q . && bun test || echo 'No tests found - skipping'"
|
|
28
28
|
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"react",
|
|
31
|
+
"react-component",
|
|
32
|
+
"fvc",
|
|
33
|
+
"fe-vis-core",
|
|
34
|
+
"ui",
|
|
35
|
+
"richtext",
|
|
36
|
+
"rich-text",
|
|
37
|
+
"wysiwyg",
|
|
38
|
+
"editor",
|
|
39
|
+
"design-system",
|
|
40
|
+
"antd"
|
|
41
|
+
],
|
|
29
42
|
"dependencies": {
|
|
30
43
|
"@cyber-wysiwyg/richtexteditor": "^1.0.15",
|
|
31
44
|
"dompurify": "^3.2.6"
|
|
32
45
|
},
|
|
33
46
|
"peerDependencies": {
|
|
34
|
-
"@fvc/button": "
|
|
35
|
-
"@fvc/icons": "
|
|
47
|
+
"@fvc/button": "1.2.6-next-ec65dfb844e6183b3d7f417eee613cfe5ecfd997",
|
|
48
|
+
"@fvc/icons": "1.1.4-next-ec65dfb844e6183b3d7f417eee613cfe5ecfd997",
|
|
36
49
|
"antd": "^5.0.0",
|
|
37
50
|
"react": "^18.0.0",
|
|
38
51
|
"@cyber-wysiwyg/richtexteditor": "^1.0.15"
|