@witty-works/editor 2.1.0 → 2.2.1

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 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@2.1.0/dist/witty-editor.js"></script>
11
+ <script src="https://cdn.jsdelivr.net/npm/@witty-works/editor@2.2.1/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/',
@@ -32,13 +32,13 @@ Pin an exact version, as above, rather than a range: the script runs with access
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 settings button |
35
+ | `toolbar` | `true` | Formatting toolbar with the Witty menu (see below) |
36
36
  | `llmAlternatives` | `false` | Offer AI sentence rewrites in the popover |
37
37
  | `llmTimeoutMs` | `3000` | How long to wait for them; raise it for a local model |
38
38
  | `delay` | `500` | Debounce after the last edit, in ms |
39
39
  | `maxRequestLength` | `1000` | Characters per check request; set it to the API's `TEXT_MAX_LENGTH` if that differs (see Long texts) |
40
40
  | `maxTextLength` | `20000` | Characters of the text checked at all |
41
- | `onStatus` | none | `{state: 'idle', alerts, limitReached}`, `{state: 'unauthorized'}` or `{state: 'error', message}` |
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
42
  | `onSettingsChange` | none | Called with the settings when the user changes one, e.g. to store them |
43
43
 
44
44
  It returns a handle:
@@ -47,9 +47,35 @@ It returns a handle:
47
47
  - `setConfig(config)`: replace the whole check config (no merging) and check again; `{}` sends none.
48
48
  - `getSettings()`: the current settings, `{config, llmAlternatives, orthography}`, as a copy; the same object `onSettingsChange` receives.
49
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), `forced` (the account forces another format, given as `applied`; nothing is changed), `unsupported` (the API has no bulk alerts) or `unavailable` (the Inklusivum).
50
51
  - `editor`: the underlying [TipTap](https://tiptap.dev) editor.
51
52
  - `destroy()`: remove the editor and everything it added to the page.
52
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
+ An organisation or user config can also force the gender format. The API then converts towards the forced format, whatever the request asks for, so the editor compares the check response's `gender_separator` with the chosen format first. If they differ, it changes nothing, keeps the previous setting, and says which format the organisation sets (outcome `forced`).
67
+
68
+ ### The `bulk` contract
69
+
70
+ The editor decides what to apply by `bulk` alone, never by subcategory:
71
+
72
+ - 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.
73
+ - `bulk` is absent (or `null`) on every other result. Unknown `bulk` values are ignored.
74
+ - Every check response lists the groups the request can return in `bulk_actions`, whether or not a result does: `["gender_format"]` for German with a separator format, inclusive roles and the gender-format alerts on, `[]` otherwise. After the switch's check, a list without `"gender_format"` means the account keeps the switch off.
75
+ - `gender_separator` in the check response is the format the API applied; for German it is a `german_gender_ending` value.
76
+
77
+ Switching needs an NLP API that sends `bulk_actions`; releases up to 2.4.8 do not. With those, the editor falls back to guessing from the results: gender-format results without `bulk` mean the server doesn't support switching yet, and the menu entry says so.
78
+
53
79
  ## Long texts
54
80
 
55
81
  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.