@witty-works/editor 2.0.1 → 2.2.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 +48 -7
- package/dist/witty-editor.js +91 -43
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ One self-contained script: no framework, no stylesheet to include.
|
|
|
8
8
|
|
|
9
9
|
```html
|
|
10
10
|
<div id="editor"></div>
|
|
11
|
-
<script src="https://cdn.jsdelivr.net/npm/@witty-works/editor@
|
|
11
|
+
<script src="https://cdn.jsdelivr.net/npm/@witty-works/editor@2.2.0/dist/witty-editor.js"></script>
|
|
12
12
|
<script>
|
|
13
13
|
const editor = WittyEditor.mount(document.getElementById('editor'), {
|
|
14
14
|
endpoint: 'https://your-nlp-api.example/',
|
|
@@ -19,7 +19,7 @@ One self-contained script: no framework, no stylesheet to include.
|
|
|
19
19
|
</script>
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
Or `npm install @witty-works/editor` and serve `node_modules/@witty-works/editor/dist/witty-editor.js` yourself.
|
|
22
|
+
Pin an exact version, as above, rather than a range: the script runs with access to the page. Or `npm install @witty-works/editor` and serve `node_modules/@witty-works/editor/dist/witty-editor.js` yourself. Releases are published from CI with npm provenance.
|
|
23
23
|
|
|
24
24
|
## `WittyEditor.mount(element, options)`
|
|
25
25
|
|
|
@@ -31,25 +31,66 @@ Or `npm install @witty-works/editor` and serve `node_modules/@witty-works/editor
|
|
|
31
31
|
| `config` | none | Check config (gender formats, disabled categories, …); only fields you set are sent |
|
|
32
32
|
| `content` | empty | Initial content as HTML |
|
|
33
33
|
| `label` | `'Text to check'` | Accessible name of the editable area |
|
|
34
|
-
| `
|
|
34
|
+
| `describedBy` | none | Ids of elements that further describe the editable area, separated by spaces; added to its `aria-describedby` after the editor's own hint |
|
|
35
|
+
| `toolbar` | `true` | Formatting toolbar with the Witty menu (see below) |
|
|
35
36
|
| `llmAlternatives` | `false` | Offer AI sentence rewrites in the popover |
|
|
36
37
|
| `llmTimeoutMs` | `3000` | How long to wait for them; raise it for a local model |
|
|
37
38
|
| `delay` | `500` | Debounce after the last edit, in ms |
|
|
38
|
-
| `
|
|
39
|
-
| `
|
|
39
|
+
| `maxRequestLength` | `1000` | Characters per check request; set it to the API's `TEXT_MAX_LENGTH` if that differs (see Long texts) |
|
|
40
|
+
| `maxTextLength` | `20000` | Characters of the text checked at all |
|
|
41
|
+
| `onStatus` | none | `{state: 'idle', alerts, limitReached}`, `{state: 'unauthorized'}` or `{state: 'error', message}`; after a gender format switch, the idle status also has `genderFormatSwitch` |
|
|
42
|
+
| `onSettingsChange` | none | Called with the settings when the user changes one, e.g. to store them |
|
|
40
43
|
|
|
41
44
|
It returns a handle:
|
|
42
45
|
|
|
43
46
|
- `setApiKey(key)`: replace the API key and check again.
|
|
44
47
|
- `setConfig(config)`: replace the whole check config (no merging) and check again; `{}` sends none.
|
|
48
|
+
- `getSettings()`: the current settings, `{config, llmAlternatives, orthography}`, as a copy; the same object `onSettingsChange` receives.
|
|
45
49
|
- `getText()`: the document as plain text.
|
|
50
|
+
- `switchGenderFormat(target)`: rewrite the text into a German gender format, as the menu does (see below). Resolves with `{outcome, target, count, limitReached}`; `outcome` is `switched`, `nothing`, `disabled` (the account keeps these alerts off), `unsupported` (the API has no bulk alerts) or `unavailable` (the Inklusivum).
|
|
46
51
|
- `editor`: the underlying [TipTap](https://tiptap.dev) editor.
|
|
47
52
|
- `destroy()`: remove the editor and everything it added to the page.
|
|
48
53
|
|
|
54
|
+
## The Witty menu
|
|
55
|
+
|
|
56
|
+
The W icon at the end of the toolbar shows whether Witty is checking, and opens a menu (a keyboard-operable ARIA menu: arrow keys, Home and End move, Escape closes and returns focus to the icon):
|
|
57
|
+
|
|
58
|
+
- **Settings…**: Witty's categories and preferences, as in the browser extension.
|
|
59
|
+
- **Switch gender format…**: rewrites every gendered form in the text into one of the eight German separator formats (`/in`, `/-in`, `_in`, `*in`, `:in`, `(-)`, `()`, `In`), labelled as in the settings. The Inklusivum (`de-e`) is listed but not available yet.
|
|
60
|
+
- **Help** and **About**: the Witty Works help on the editor and the website, in a new tab.
|
|
61
|
+
|
|
62
|
+
A switch makes the chosen format the configured one, waits until the whole text has been checked (every batch of a long text), and then applies all alerts the API marked with `bulk: "gender_format"` in one transaction, so a single undo restores the text. The result is announced in the live region and passed to `onStatus` as `genderFormatSwitch`. If only part of the text was checked (`limitReached`), what was checked is switched and the message says so.
|
|
63
|
+
|
|
64
|
+
The switch's checks ask for the gender-format alerts even where the account turned them off: `gendered_denominations_ending_advanced` is taken out of `disabled_categories` and `gendered_roles_format` is `inclusive_gender`, for those requests only; the user's settings stay as they are. If the API still sends none, because the account's stored configuration forces them off, the editor says "Switching the gender format is turned off for this account".
|
|
65
|
+
|
|
66
|
+
### The `bulk` contract
|
|
67
|
+
|
|
68
|
+
The editor decides what to apply by `bulk` alone, never by subcategory:
|
|
69
|
+
|
|
70
|
+
- A check result with `bulk: "gender_format"` belongs to the switch to the configured `german_gender_ending`. It has exactly one alternative, the form in that format, and such results never overlap.
|
|
71
|
+
- `bulk` is absent (or `null`) on every other result. Unknown `bulk` values are ignored.
|
|
72
|
+
- An API without bulk alerts sends gender-format results without `bulk`; the editor then reports that the server doesn't support switching yet, and marks the menu entry so.
|
|
73
|
+
|
|
74
|
+
Switching needs an NLP API that sets `bulk` on `POST /v2.4/check` results; releases up to 2.4.8 do not.
|
|
75
|
+
|
|
76
|
+
## Long texts
|
|
77
|
+
|
|
78
|
+
The NLP API checks at most `TEXT_MAX_LENGTH` characters per request (1000 by default). The editor checks longer texts sentence by sentence, as the browser extension does: it sends the sentences it has not checked yet, in requests of up to `maxRequestLength` characters, and caches the results, so after an edit only the changed sentence is sent again. If the API cuts a request short anyway, that batch is sent again in smaller pieces.
|
|
79
|
+
|
|
80
|
+
Part of a text can stay unchecked: anything past `maxTextLength`, or a single sentence longer than the API checks at once. `onStatus` then reports `limitReached: true`, and the editor shows "Only part of this text was checked." under the text.
|
|
81
|
+
|
|
49
82
|
## Requirements
|
|
50
83
|
|
|
51
|
-
-
|
|
52
|
-
-
|
|
84
|
+
- **Content-Security-Policy:**
|
|
85
|
+
- `script-src` must allow the script, and `style-src` inline styles: the editor injects its own `<style>`.
|
|
86
|
+
- `img-src data:` for the popover's logo, which is inline.
|
|
87
|
+
- `img-src https://www.witty.works` for the pictures in the explanations ("learning bites").
|
|
88
|
+
- `connect-src` for the API endpoint's origin, when it differs from the page's.
|
|
89
|
+
- **CORS:** the NLP API must allow the page's origin.
|
|
90
|
+
|
|
91
|
+
## Storage
|
|
92
|
+
|
|
93
|
+
The API key is kept in memory only; it is never written to the page, to cookies or to storage. The only thing the editor stores is i18next's language cache, `localStorage["i18nextLng"]`.
|
|
53
94
|
|
|
54
95
|
## License
|
|
55
96
|
|