@witty-works/editor 2.0.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/LICENSE +21 -0
- package/README.md +56 -0
- package/dist/witty-editor.js +201 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Witty Works <contact@witty.works> (https://witty.works)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# @witty-works/editor
|
|
2
|
+
|
|
3
|
+
[Witty](https://witty.works)'s inclusive-language checker as an embeddable rich-text editor. It checks as you type, underlines what Witty flags, and offers alternatives in the same popover as the Witty browser extension. It includes a formatting toolbar and Witty's settings (categories, gender formats, spelling, AI suggestions).
|
|
4
|
+
|
|
5
|
+
One self-contained script: no framework, no stylesheet to include.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<div id="editor"></div>
|
|
11
|
+
<script src="https://cdn.jsdelivr.net/npm/@witty-works/editor@0.1.0/dist/witty-editor.js"></script>
|
|
12
|
+
<script>
|
|
13
|
+
const editor = WittyEditor.mount(document.getElementById('editor'), {
|
|
14
|
+
endpoint: 'https://your-nlp-api.example/',
|
|
15
|
+
onStatus: (status) => console.log(status),
|
|
16
|
+
});
|
|
17
|
+
// The key stays in memory and is sent only as the x-key header.
|
|
18
|
+
editor.setApiKey(keyFromYourBackend);
|
|
19
|
+
</script>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or `npm install @witty-works/editor` and serve `node_modules/@witty-works/editor/dist/witty-editor.js` yourself.
|
|
23
|
+
|
|
24
|
+
## `WittyEditor.mount(element, options)`
|
|
25
|
+
|
|
26
|
+
| Option | Default | |
|
|
27
|
+
|---|---|---|
|
|
28
|
+
| `endpoint` | page origin | NLP API base URL, with trailing slash |
|
|
29
|
+
| `apiKey` | none | Sent as `x-key`; prefer `setApiKey` |
|
|
30
|
+
| `lang` | `'auto'` | Text language: `auto`, `en`, `de`, `fr` or a variant such as `de-CH` |
|
|
31
|
+
| `config` | none | Check config (gender formats, disabled categories, …); only fields you set are sent |
|
|
32
|
+
| `content` | empty | Initial content as HTML |
|
|
33
|
+
| `label` | `'Text to check'` | Accessible name of the editable area |
|
|
34
|
+
| `toolbar` | `true` | Formatting toolbar with the Witty settings button |
|
|
35
|
+
| `llmAlternatives` | `false` | Offer AI sentence rewrites in the popover |
|
|
36
|
+
| `llmTimeoutMs` | `3000` | How long to wait for them; raise it for a local model |
|
|
37
|
+
| `delay` | `500` | Debounce after the last edit, in ms |
|
|
38
|
+
| `onStatus` | none | `{state: 'idle', alerts}`, `{state: 'unauthorized'}` or `{state: 'error', message}` |
|
|
39
|
+
| `onSettingsChange` | none | Called when the user changes a setting, e.g. to store it |
|
|
40
|
+
|
|
41
|
+
It returns a handle:
|
|
42
|
+
|
|
43
|
+
- `setApiKey(key)`: replace the API key and check again.
|
|
44
|
+
- `setConfig(config)`: replace the whole check config (no merging) and check again; `{}` sends none.
|
|
45
|
+
- `getText()`: the document as plain text.
|
|
46
|
+
- `editor`: the underlying [TipTap](https://tiptap.dev) editor.
|
|
47
|
+
- `destroy()`: remove the editor and everything it added to the page.
|
|
48
|
+
|
|
49
|
+
## Requirements
|
|
50
|
+
|
|
51
|
+
- The page's Content-Security-Policy must allow the script and inline styles: the editor injects its own `<style>`.
|
|
52
|
+
- The NLP API must allow the page's origin (CORS).
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
MIT
|