@editora/core 1.0.21 → 1.0.23
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 +247 -243
- package/dist/{CodePlugin.native-AoJ_idGz.mjs → CodePlugin.native-CAHk9ecG.mjs} +211 -93
- package/dist/{CodePlugin.native-CEgR1DWC.mjs → CodePlugin.native-DZgIez08.mjs} +371 -253
- package/dist/editora.min.js +1 -1
- package/dist/editora.umd.js +1 -1
- package/dist/{index-Ct3Aik7_.js → index-C1sO7DAC.js} +2 -2
- package/dist/{index-6i4_TH66.mjs → index-DGMYWPLx.mjs} +3 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +2 -2
- package/dist/webcomponent-core.js +3 -1
- package/dist/webcomponent-core.min.css +1 -1
- package/dist/webcomponent-core.min.js +16 -15
- package/dist/webcomponent.cjs.js +1 -1
- package/dist/webcomponent.esm.js +1 -1
- package/dist/webcomponent.js +3 -1
- package/dist/webcomponent.min.css +1 -1
- package/dist/webcomponent.min.js +64 -63
- package/index.d.ts +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,287 +1,291 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
<
|
|
18
|
-
<
|
|
19
|
-
<
|
|
20
|
-
</
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
<h1 align="center">@editora/core</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
A rich text editor as a web component. Put <code><editora-editor></code> in plain HTML, Vue, Angular, Svelte or
|
|
5
|
+
any other page, name the plugins you want, and only those load. Using React? See
|
|
6
|
+
<a href="https://www.npmjs.com/package/@editora/react"><code>@editora/react</code></a>.
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/@editora/core"><img src="https://img.shields.io/npm/v/@editora/core.svg" alt="npm version"></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@editora/core"><img src="https://img.shields.io/npm/dm/@editora/core.svg" alt="npm downloads"></a>
|
|
12
|
+
<a href="https://github.com/ajaykr089/Editora/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/@editora/core.svg" alt="license"></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@editora/core"><img src="https://img.shields.io/npm/types/@editora/core.svg" alt="TypeScript types included"></a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
<p align="center">
|
|
17
|
+
<a href="https://editora-ecosystem.netlify.app/">Website</a> ·
|
|
18
|
+
<a href="https://editora-ecosystem-storybook.netlify.app/">Storybook</a> ·
|
|
19
|
+
<a href="https://github.com/ajaykr089/Editora">GitHub</a>
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
<p align="center">
|
|
23
|
+
<img src="https://raw.githubusercontent.com/ajaykr089/Editora/main/packages/core/docs/images/web-component.png" alt="The editor in a page: a toolbar with undo, redo, headings, bold, italic, underline, colours, lists, quote, link and table, above a heading, a paragraph, a list and a table" width="900">
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
- **One element, any framework.** `<editora-editor>` is a standard custom element, so it works wherever HTML does.
|
|
29
|
+
- **Load only what you use.** List the plugins you want in the `plugins` attribute and only their code is fetched. The
|
|
30
|
+
editor in the quick start below is about 64 KB gzipped, stylesheet included.
|
|
31
|
+
- **A real toolbar from a string.** `toolbar="undo redo | bold italic | link"`, or hide it altogether.
|
|
32
|
+
- **Plugins for the rest.** Tables, lists and checklists, colours, links, code, math, comments, track changes and more:
|
|
33
|
+
see [`@editora/plugins`](https://www.npmjs.com/package/@editora/plugins).
|
|
34
|
+
- **Light and dark themes**, a read-only mode, an optional status bar, and an accessible name for the editing area.
|
|
35
|
+
- **Safe by default.** Content you set from JavaScript, and anything typed or pasted, is sanitised before it is
|
|
36
|
+
kept (see [Security](#security)).
|
|
37
|
+
- Written in TypeScript; the typings ship with the package.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
From a CDN, with no build step (pin a version in production: replace `@editora/core` with `@editora/core@1` in the
|
|
42
|
+
URLs below):
|
|
43
|
+
|
|
44
|
+
```html
|
|
45
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@editora/core/dist/webcomponent.min.css" />
|
|
46
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@editora/core/dist/webcomponent.js"></script>
|
|
47
|
+
```
|
|
23
48
|
|
|
24
|
-
|
|
49
|
+
Or from npm, for a bundler such as Vite, webpack or esbuild:
|
|
25
50
|
|
|
26
51
|
```bash
|
|
27
|
-
npm install @editora/core
|
|
52
|
+
npm install @editora/core
|
|
28
53
|
```
|
|
29
54
|
|
|
30
|
-
##
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
### Basic Usage
|
|
46
|
-
|
|
47
|
-
```typescript
|
|
48
|
-
import { createEditor, EditorConfig } from '@editora/core';
|
|
49
|
-
|
|
50
|
-
import "@editora/themes/themes/default.css";
|
|
51
|
-
// Create editor configuration
|
|
52
|
-
const config: EditorConfig = {
|
|
53
|
-
content: '<p>Hello World!</p>',
|
|
54
|
-
placeholder: 'Start typing...',
|
|
55
|
-
onChange: (html) => {
|
|
56
|
-
console.log('Content changed:', html);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// Create editor instance
|
|
61
|
-
const editor = createEditor(config);
|
|
62
|
-
|
|
63
|
-
// Mount to DOM element
|
|
64
|
-
const container = document.getElementById('editor');
|
|
65
|
-
editor.mount(container);
|
|
55
|
+
## Quick start
|
|
56
|
+
|
|
57
|
+
```html
|
|
58
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@editora/core/dist/webcomponent.min.css" />
|
|
59
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@editora/core/dist/webcomponent.js"></script>
|
|
60
|
+
|
|
61
|
+
<editora-editor
|
|
62
|
+
height="320"
|
|
63
|
+
plugins="heading bold italic underline list link history"
|
|
64
|
+
toolbar="undo redo | heading | bold italic underline | bullist numlist | link"
|
|
65
|
+
placeholder="Start writing..."
|
|
66
|
+
>
|
|
67
|
+
<h2>Hello, Editora</h2>
|
|
68
|
+
<p>This is a <strong>web component</strong>. Select some text and use the toolbar.</p>
|
|
69
|
+
</editora-editor>
|
|
66
70
|
```
|
|
67
71
|
|
|
68
|
-
|
|
72
|
+
<p align="center">
|
|
73
|
+
<img src="https://raw.githubusercontent.com/ajaykr089/Editora/main/packages/core/docs/images/quick-start.png" alt="The editor from the quick start: a toolbar with undo, redo, a paragraph menu, bold, italic, underline, lists and a link button, above a heading and a paragraph" width="900">
|
|
74
|
+
</p>
|
|
69
75
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
import { BoldPlugin, ItalicPlugin, HeadingPlugin } from '@editora/plugins';
|
|
76
|
+
The content between the tags is the starting content. Put only HTML you trust there (see [Security](#security)); to load
|
|
77
|
+
anything else, call `setContent()`.
|
|
73
78
|
|
|
74
|
-
|
|
79
|
+
## Use it with a bundler
|
|
75
80
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
ItalicPlugin(),
|
|
80
|
-
HeadingPlugin()
|
|
81
|
-
],
|
|
82
|
-
content: '<h1>Welcome</h1><p>Start writing...</p>'
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
editor.mount(document.getElementById('editor'));
|
|
81
|
+
```ts
|
|
82
|
+
import '@editora/core/webcomponent'; // registers <editora-editor>
|
|
83
|
+
import '@editora/core/webcomponent.css';
|
|
86
84
|
```
|
|
87
85
|
|
|
88
|
-
|
|
86
|
+
Then use the element in your templates, in any framework:
|
|
89
87
|
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
import "@editora/themes/themes/dark.css";
|
|
93
|
-
import "@editora/themes/themes/acme.css";
|
|
88
|
+
```html
|
|
89
|
+
<editora-editor plugins="bold italic link history" toolbar="undo redo | bold italic | link"></editora-editor>
|
|
94
90
|
```
|
|
95
91
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
editor
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
editor
|
|
92
|
+
## Configure it
|
|
93
|
+
|
|
94
|
+
Set options as attributes:
|
|
95
|
+
|
|
96
|
+
| Attribute | |
|
|
97
|
+
| --- | --- |
|
|
98
|
+
| `plugins` | The plugins to load, separated by spaces (see [the plugin list](https://www.npmjs.com/package/@editora/plugins#plugin-catalog), column *Name*). |
|
|
99
|
+
| `toolbar` | The toolbar items, with `\|` between groups: `"undo redo \| bold italic"`. `"false"` hides the toolbar. |
|
|
100
|
+
| `height` | The height in pixels. Default `400`. |
|
|
101
|
+
| `width` | The width in pixels. By default the editor fills its parent. |
|
|
102
|
+
| `placeholder` | Text shown while the editor is empty. |
|
|
103
|
+
| `readonly` | `"true"` makes the content read-only. You can change it at any time. |
|
|
104
|
+
| `theme` | `light` (the default) or `dark`. Set the attribute again to switch. |
|
|
105
|
+
| `statusbar` | `"true"` shows a status bar. |
|
|
106
|
+
| `autofocus` | Focuses the editor when it loads. |
|
|
107
|
+
| `aria-label` | The accessible name of the editing area. |
|
|
108
|
+
|
|
109
|
+
The element has more attributes for autosave (`autosave-*`), spell check (`spellcheck-*`), pasting (`paste-*`),
|
|
110
|
+
language (`language-*`), accessibility (`accessibility-*`) and performance (`performance-*`). They are listed in the
|
|
111
|
+
element's `observedAttributes`, and they match the option groups of [`@editora/react`](https://www.npmjs.com/package/@editora/react#props).
|
|
112
|
+
|
|
113
|
+
```html
|
|
114
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@editora/core/dist/webcomponent.min.css" />
|
|
115
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@editora/core/dist/webcomponent.js"></script>
|
|
116
|
+
|
|
117
|
+
<!-- A short toolbar, the dark theme and a shorter editor -->
|
|
118
|
+
<editora-editor
|
|
119
|
+
height="220"
|
|
120
|
+
theme="dark"
|
|
121
|
+
plugins="bold italic underline list link history"
|
|
122
|
+
toolbar="undo redo | bold italic underline | bullist numlist | link"
|
|
123
|
+
placeholder="Write a note..."
|
|
124
|
+
>
|
|
125
|
+
<p>A compact editor for comments and notes.</p>
|
|
126
|
+
</editora-editor>
|
|
127
|
+
|
|
128
|
+
<!-- Read-only: formatted content that cannot be edited -->
|
|
129
|
+
<editora-editor height="140" readonly="true" plugins="bold italic" toolbar="false">
|
|
130
|
+
<p>This content is <strong>read-only</strong>.</p>
|
|
131
|
+
</editora-editor>
|
|
131
132
|
```
|
|
132
133
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
<p align="center">
|
|
135
|
+
<img src="https://raw.githubusercontent.com/ajaykr089/Editora/main/packages/core/docs/images/themes.png" alt="A compact dark editor with a short toolbar, above a read-only editor with no toolbar" width="900">
|
|
136
|
+
</p>
|
|
137
|
+
|
|
138
|
+
The editor in the picture at the top of this page is configured like this:
|
|
139
|
+
|
|
140
|
+
```html
|
|
141
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@editora/core/dist/webcomponent.min.css" />
|
|
142
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@editora/core/dist/webcomponent.js"></script>
|
|
143
|
+
|
|
144
|
+
<editora-editor
|
|
145
|
+
height="440"
|
|
146
|
+
plugins="heading bold italic underline blockquote list textColor backgroundColor link table history"
|
|
147
|
+
toolbar="undo redo | heading | bold italic underline | textColor backgroundColor | bullist numlist | blockquote link table"
|
|
148
|
+
>
|
|
149
|
+
<h2>Release notes</h2>
|
|
150
|
+
<p>
|
|
151
|
+
Editora is a <strong>web component</strong>, so it works the same in plain HTML, Vue, Angular and Svelte.
|
|
152
|
+
Select some text to try the <em>toolbar</em>.
|
|
153
|
+
</p>
|
|
154
|
+
<ul>
|
|
155
|
+
<li>Formatting, lists and links</li>
|
|
156
|
+
<li>Tables you can edit in place</li>
|
|
157
|
+
</ul>
|
|
158
|
+
<table>
|
|
159
|
+
<tr><th>Plan</th><th>Seats</th><th>Price</th></tr>
|
|
160
|
+
<tr><td>Team</td><td>10</td><td>$49</td></tr>
|
|
161
|
+
<tr><td>Business</td><td>50</td><td>$199</td></tr>
|
|
162
|
+
</table>
|
|
163
|
+
</editora-editor>
|
|
139
164
|
```
|
|
140
165
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
Sets the editor content from HTML.
|
|
166
|
+
You can also configure an editor from JavaScript with `editor.setConfig({ toolbar: 'bold italic', height: 300 })`.
|
|
167
|
+
To switch the theme at run time, set the attribute: `editor.setAttribute('theme', 'dark')`.
|
|
144
168
|
|
|
145
|
-
|
|
146
|
-
editor.setHTML('<p>New content</p>');
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
#### `getJSON(): object`
|
|
169
|
+
### Toolbar items
|
|
150
170
|
|
|
151
|
-
|
|
171
|
+
`toolbar` takes names separated by spaces, with `|` between groups. The names are camelCase and case-sensitive
|
|
172
|
+
(`textColor`, not `textcolor`), and each one needs its plugin in `plugins`:
|
|
152
173
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
174
|
+
| Name | Plugin |
|
|
175
|
+
| --- | --- |
|
|
176
|
+
| `undo`, `redo` | `history` |
|
|
177
|
+
| `bold`, `italic`, `underline`, `strikethrough` | the plugin of the same name |
|
|
178
|
+
| `heading` | `heading`: a menu for paragraph and the heading levels |
|
|
179
|
+
| `bullist`, `numlist`, `checklist` | `list`, `checklist` |
|
|
180
|
+
| `link`, `table`, `blockquote`, `math`, `emojis`, `fullscreen`, `preview` | the plugin of the same name |
|
|
181
|
+
| `textColor`, `backgroundColor`, `fontSize` | `textColor`, `backgroundColor`, `fontSize` |
|
|
182
|
+
| `direction` | `direction`: left-to-right and right-to-left buttons |
|
|
183
|
+
| `trackChanges`, `comments`, `a11yChecker` | the plugin of the same name |
|
|
184
|
+
| `mergeTags` | `mergeTag` |
|
|
156
185
|
|
|
157
|
-
|
|
186
|
+
A plugin's own command name works too, for example `insertMergeTag`. The full list of plugins, and the name each one is
|
|
187
|
+
loaded by, is in [`@editora/plugins`](https://www.npmjs.com/package/@editora/plugins#plugin-catalog).
|
|
158
188
|
|
|
159
|
-
|
|
189
|
+
## Read and write content
|
|
160
190
|
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
|
|
191
|
+
```html
|
|
192
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@editora/core/dist/webcomponent.min.css" />
|
|
193
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@editora/core/dist/webcomponent.js"></script>
|
|
164
194
|
|
|
165
|
-
|
|
195
|
+
<editora-editor id="editor" height="240" plugins="bold italic underline list history" toolbar="undo redo | bold italic underline | bullist numlist">
|
|
196
|
+
<p>Edit me, then use the buttons.</p>
|
|
197
|
+
</editora-editor>
|
|
166
198
|
|
|
167
|
-
|
|
199
|
+
<button id="read">Read HTML</button>
|
|
200
|
+
<button id="replace">Replace</button>
|
|
201
|
+
<button id="bold">Bold</button>
|
|
202
|
+
<pre id="out"></pre>
|
|
168
203
|
|
|
169
|
-
|
|
170
|
-
editor.
|
|
171
|
-
|
|
204
|
+
<script type="module">
|
|
205
|
+
const editor = document.getElementById('editor');
|
|
206
|
+
const out = document.getElementById('out');
|
|
172
207
|
|
|
173
|
-
|
|
208
|
+
// Fired when the toolbar and plugins are ready.
|
|
209
|
+
editor.addEventListener('editor-ready', () => console.log('ready'));
|
|
174
210
|
|
|
175
|
-
|
|
211
|
+
// Fired as the content changes (debounced). The HTML is in event.detail.html.
|
|
212
|
+
editor.addEventListener('content-change', (event) => {
|
|
213
|
+
out.textContent = event.detail.html;
|
|
214
|
+
});
|
|
176
215
|
|
|
177
|
-
|
|
178
|
-
editor.
|
|
216
|
+
document.getElementById('read').onclick = () => (out.textContent = editor.getContent());
|
|
217
|
+
document.getElementById('replace').onclick = () => editor.setContent('<h2>Replaced</h2><p>From outside.</p>');
|
|
218
|
+
document.getElementById('bold').onclick = () => editor.execCommand('toggleBold');
|
|
219
|
+
</script>
|
|
179
220
|
```
|
|
180
221
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
222
|
+
<p align="center">
|
|
223
|
+
<img src="https://raw.githubusercontent.com/ajaykr089/Editora/main/packages/core/docs/images/api.png" alt="An editor with the text Replaced and From outside, three buttons under it, and the HTML of the content printed below" width="900">
|
|
224
|
+
</p>
|
|
225
|
+
|
|
226
|
+
| Method | |
|
|
227
|
+
| --- | --- |
|
|
228
|
+
| `getContent()` | The content as clean HTML. |
|
|
229
|
+
| `setContent(html)` | Replaces the content. The HTML is sanitised first. |
|
|
230
|
+
| `execCommand(name)` | Runs a command, as the toolbar does: `toggleBold`, `toggleItalic`, `toggleBulletList`, `insertTable`, `undo`, and so on. Returns `true` if the command ran. |
|
|
231
|
+
| `focus()` / `blur()` | Moves the focus into or out of the editor. |
|
|
232
|
+
| `setConfig(options)` | Changes options at run time, such as `toolbar` or `height`. |
|
|
233
|
+
| `getAPI()` | The same methods as an object, plus `on(event, handler)`, `getConfig()` and `setReadonly(boolean)`. |
|
|
234
|
+
|
|
235
|
+
| Event | `event.detail` | |
|
|
236
|
+
| --- | --- | --- |
|
|
237
|
+
| `editor-ready` | | The editor has been built. It fires again if the editor is rebuilt, for example after you change `plugins` or `toolbar`. |
|
|
238
|
+
| `content-change` | `{ html }` | The content changed. It can fire more than once for the same HTML, so compare before you save. |
|
|
239
|
+
| `editor-focus` / `editor-blur` | | The editor gained or lost the focus. |
|
|
240
|
+
| `editor-destroy` | | The editor was torn down. |
|
|
241
|
+
|
|
242
|
+
## Choose a bundle
|
|
243
|
+
|
|
244
|
+
| File | Contains |
|
|
245
|
+
| --- | --- |
|
|
246
|
+
| `dist/webcomponent.js` | Every plugin. Each one is loaded only when you name it in `plugins`. |
|
|
247
|
+
| `dist/webcomponent-core.js` | Ten essentials: `bold`, `italic`, `underline`, `strikethrough`, `clearFormatting`, `heading`, `blockquote`, `code`, `list` and `history`. |
|
|
248
|
+
|
|
249
|
+
Each has its own stylesheet (`webcomponent.min.css`, `webcomponent-core.min.css`).
|
|
250
|
+
|
|
251
|
+
```html
|
|
252
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@editora/core/dist/webcomponent-core.min.css" />
|
|
253
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@editora/core/dist/webcomponent-core.js"></script>
|
|
254
|
+
|
|
255
|
+
<editora-editor plugins="bold italic list history" toolbar="undo redo | bold italic | bullist numlist">
|
|
256
|
+
<p>Only the essential plugins are available in this bundle.</p>
|
|
257
|
+
</editora-editor>
|
|
187
258
|
```
|
|
188
259
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
260
|
+
> [!WARNING]
|
|
261
|
+
> Always list the plugins you want. If you leave `plugins` out, **every** plugin in the bundle is loaded, including ones
|
|
262
|
+
> that need setup. The `collaboration` plugin, for example, syncs the document through a public Yjs demo server unless
|
|
263
|
+
> you give it your own server, so never leave it loaded by accident. See
|
|
264
|
+
> [`@editora/plugins`](https://www.npmjs.com/package/@editora/plugins#collaboration).
|
|
192
265
|
|
|
193
|
-
|
|
194
|
-
editor.destroy();
|
|
195
|
-
```
|
|
266
|
+
## Security
|
|
196
267
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
// Placeholder text
|
|
205
|
-
placeholder?: string;
|
|
206
|
-
|
|
207
|
-
// Change handler
|
|
208
|
-
onChange?: (html: string, json: object) => void;
|
|
209
|
-
|
|
210
|
-
// Focus handlers
|
|
211
|
-
onFocus?: () => void;
|
|
212
|
-
onBlur?: () => void;
|
|
213
|
-
|
|
214
|
-
// Plugins
|
|
215
|
-
plugins?: Plugin[];
|
|
216
|
-
|
|
217
|
-
// Editor state
|
|
218
|
-
readonly?: boolean;
|
|
219
|
-
autofocus?: boolean;
|
|
220
|
-
|
|
221
|
-
// Content validation
|
|
222
|
-
sanitize?: boolean;
|
|
223
|
-
maxLength?: number;
|
|
224
|
-
|
|
225
|
-
// Performance
|
|
226
|
-
debounceDelay?: number;
|
|
227
|
-
}
|
|
228
|
-
```
|
|
268
|
+
- `setContent()`, typing and pasting go through a sanitiser by default. Scripts, event-handler attributes such as
|
|
269
|
+
`onerror`, and `javascript:` links are removed.
|
|
270
|
+
- **HTML written between the `<editora-editor>` tags is parsed by the browser before Editora sees it,** so a script or
|
|
271
|
+
an `onerror` handler in it can run. Only put trusted HTML there, and load anything else with `setContent()`.
|
|
272
|
+
- The sanitisers are exported if you need them elsewhere: `sanitizeHTML`, `sanitizeInputHTML` and
|
|
273
|
+
`sanitizePastedHTML`.
|
|
229
274
|
|
|
230
|
-
|
|
275
|
+
## TypeScript
|
|
231
276
|
|
|
232
|
-
|
|
277
|
+
The package ships its typings. The element is `RichTextEditorElement`; `EditorAPI` describes what `getAPI()` returns.
|
|
233
278
|
|
|
234
|
-
|
|
235
|
-
accessibility?: {
|
|
236
|
-
enableARIA?: boolean;
|
|
237
|
-
keyboardNavigation?: boolean;
|
|
238
|
-
checker?: boolean;
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
performance?: {
|
|
242
|
-
debounceInputMs?: number;
|
|
243
|
-
viewportOnlyScan?: boolean;
|
|
244
|
-
};
|
|
245
|
-
```
|
|
279
|
+
## The rest of the family
|
|
246
280
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
Create custom plugins by extending the base Plugin class:
|
|
256
|
-
|
|
257
|
-
```typescript
|
|
258
|
-
import { Plugin, Editor } from '@editora/core';
|
|
259
|
-
|
|
260
|
-
import "@editora/themes/themes/default.css";
|
|
261
|
-
class CustomPlugin extends Plugin {
|
|
262
|
-
name = 'custom';
|
|
263
|
-
|
|
264
|
-
install(editor: Editor) {
|
|
265
|
-
// Plugin initialization
|
|
266
|
-
console.log('Plugin installed');
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
execute(command: string, ...args: any[]) {
|
|
270
|
-
// Handle commands
|
|
271
|
-
if (command === 'doSomething') {
|
|
272
|
-
// Custom logic
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
```
|
|
281
|
+
| Package | |
|
|
282
|
+
| --- | --- |
|
|
283
|
+
| [`@editora/react`](https://www.npmjs.com/package/@editora/react) | The editor as a React component. |
|
|
284
|
+
| [`@editora/plugins`](https://www.npmjs.com/package/@editora/plugins) | More than fifty plugins. |
|
|
285
|
+
| [`@editora/themes`](https://www.npmjs.com/package/@editora/themes) | Light, dark and acme themes. |
|
|
286
|
+
| [`@editora/light-code-editor`](https://www.npmjs.com/package/@editora/light-code-editor) | A small code editor. |
|
|
287
|
+
| [`@editora/markdown-editor`](https://www.npmjs.com/package/@editora/markdown-editor) | A markdown editor with a live preview. |
|
|
277
288
|
|
|
278
|
-
##
|
|
289
|
+
## License
|
|
279
290
|
|
|
280
291
|
MIT © [Ajay Kumar](https://github.com/ajaykr089)
|
|
281
|
-
|
|
282
|
-
## 🔗 Links
|
|
283
|
-
|
|
284
|
-
- [Documentation](https://editora-ecosystem.netlify.app/)
|
|
285
|
-
- [GitHub Repository](https://github.com/ajaykr089/Editora)
|
|
286
|
-
- [Issue Tracker](https://github.com/ajaykr089/Editora/issues)
|
|
287
|
-
- [npm Package](https://www.npmjs.com/package/@editora/core)
|