@witty-works/editor 2.4.0 → 2.6.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 +62 -9
- package/dist/witty-editor.d.ts +217 -0
- package/dist/witty-editor.js +51 -51
- package/dist/witty-editor.mjs +34345 -0
- package/dist/witty-editor.mjs.LICENSE.txt +1643 -0
- package/package.json +29 -4
package/README.md
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
|
|
3
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
4
|
|
|
5
|
-
One self-contained script: no framework, no stylesheet to include.
|
|
5
|
+
One self-contained script: no framework, no stylesheet to include. As a script tag or as an ES module for bundlers, with TypeScript types.
|
|
6
6
|
|
|
7
7
|
## Usage
|
|
8
8
|
|
|
9
|
+
### Script tag
|
|
10
|
+
|
|
9
11
|
```html
|
|
10
12
|
<div id="editor"></div>
|
|
11
|
-
<script src="https://cdn.jsdelivr.net/npm/@witty-works/editor@2.
|
|
13
|
+
<script src="https://cdn.jsdelivr.net/npm/@witty-works/editor@2.6.0/dist/witty-editor.js"></script>
|
|
12
14
|
<script>
|
|
13
15
|
const editor = WittyEditor.mount(document.getElementById('editor'), {
|
|
14
16
|
endpoint: 'https://your-nlp-api.example/',
|
|
@@ -21,6 +23,28 @@ One self-contained script: no framework, no stylesheet to include.
|
|
|
21
23
|
|
|
22
24
|
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
25
|
|
|
26
|
+
### With a bundler
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @witty-works/editor
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import {mount, type EditorStatus} from '@witty-works/editor';
|
|
34
|
+
|
|
35
|
+
const editor = mount(document.getElementById('editor')!, {
|
|
36
|
+
endpoint: 'https://your-nlp-api.example/',
|
|
37
|
+
onStatus: (status: EditorStatus) => console.log(status),
|
|
38
|
+
});
|
|
39
|
+
editor.setApiKey(keyFromYourBackend);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The package's main entry is an ES module (`dist/witty-editor.mjs`) exporting `mount`, with types (`dist/witty-editor.d.ts`) for the options, the handle, `onStatus` and the settings: `MountOptions`, `WittyEditorHandle`, `EditorStatus`, `EditorSettings`, `CheckConfig`, `CheckLang`, `GenderFormatSwitchResult` and the rest. It works like the script: the same editor, React, TipTap and styles included (injected when the module is imported), nothing to configure in the bundler. It is not minified; your bundler does that. It does not share your page's React, so a React app loads a second copy for the editor.
|
|
43
|
+
|
|
44
|
+
The type of the handle's `editor` property comes from TipTap: install `@tiptap/core` (version 3, an optional peer dependency) if you use it from TypeScript. Nothing else needs it.
|
|
45
|
+
|
|
46
|
+
For the script tag in a TypeScript project, the same types describe the global: `declare const WittyEditor: typeof import('@witty-works/editor');`.
|
|
47
|
+
|
|
24
48
|
## `WittyEditor.mount(element, options)`
|
|
25
49
|
|
|
26
50
|
| Option | Default | |
|
|
@@ -46,9 +70,10 @@ It returns a handle:
|
|
|
46
70
|
|
|
47
71
|
- `setApiKey(key)`: replace the API key and check again.
|
|
48
72
|
- `setConfig(config)`: replace the whole check config (no merging) and check again; `{}` sends none.
|
|
73
|
+
- `updateSettings(settings)`: change settings from the host, e.g. its own form, as the settings panel does (the panel follows). The fields given replace the current ones and the rest stay: `updateSettings({llmAlternatives: true})`, `updateSettings({orthography: false})`. `config`, when given, is replaced whole, as with `setConfig`; to change one field of it, start from `getSettings().config`. Calls `onSettingsChange` once if anything changed, and nothing happens if nothing did. A changed `config` checks the text again; popovers opened afterwards follow `llmAlternatives`, an open one keeps what it shows. A value of the wrong type (`llmAlternatives: 'false'`, a `config` that is not an object) throws a `TypeError` and changes nothing. Unlike `setConfig`, which is for the host's own changes, this reports to `onSettingsChange`, so a host that stores the settings there sees changes from its form and from the panel alike.
|
|
49
74
|
- `getSettings()`: the current settings, `{config, llmAlternatives, orthography}`, as a copy; the same object `onSettingsChange` receives.
|
|
50
75
|
- `getText()`: the document as plain text.
|
|
51
|
-
- `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
|
|
76
|
+
- `switchGenderFormat(target)`: rewrite the text into a German or French gender format, as the menu does (see below); `target` is a `german_gender_ending` or `french_gender_separator` value. Resolves with `{outcome, target, count, limitReached}`; `outcome` is `switched`, `nothing`, `fromInklusivum` (nothing switched, and the text was in the Inklusivum, which the API cannot convert out of yet), `disabled` (the account keeps these alerts off), `forced` (the account forces another format, given as `applied`; nothing is changed), `unsupported` (the API cannot switch to this target yet) or `unavailable` (not a gender format).
|
|
52
77
|
- `editor`: the underlying [TipTap](https://tiptap.dev) editor.
|
|
53
78
|
- `destroy()`: remove the editor and everything it added to the page.
|
|
54
79
|
|
|
@@ -71,27 +96,48 @@ The W icon and the live region say the same to the user. Checks send `client: "w
|
|
|
71
96
|
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):
|
|
72
97
|
|
|
73
98
|
- **Settings…**: Witty's categories and preferences, as in the browser extension.
|
|
74
|
-
- **Switch gender format…**: rewrites every gendered form in the text into
|
|
99
|
+
- **Switch gender format…**: rewrites every gendered form in the text into another format, labelled as in the settings (see [Switching the gender format](#switching-the-gender-format)).
|
|
75
100
|
- **Help** and **About**: the Witty Works help on the editor and the website, in a new tab.
|
|
76
101
|
|
|
102
|
+
### Switching the gender format
|
|
103
|
+
|
|
104
|
+
The formats offered depend on the text's language:
|
|
105
|
+
|
|
106
|
+
- **German:** the eight separator formats (`/in`, `/-in`, `_in`, `*in`, `:in`, `(-)`, `()`, `In`) and the Inklusivum (`de-e`).
|
|
107
|
+
- **French:** the six separator formats `·` (`enseignant·es`), `·s` (`enseignant·e·s`), `.`, `.s`, `/` and `/s`.
|
|
108
|
+
|
|
109
|
+
The language is the one the host fixed with `lang`, or else what the API detected. A text with both German and French gets both groups, headed "German" and "French", the language of most of the text first; a text in neither (or not checked yet) gets both too. The API detects one language per request, and a short text goes in one request, so a short text mixing both languages is taken as the language of most of it; only longer texts, checked in several requests, show both groups.
|
|
110
|
+
|
|
111
|
+
A switch sets the target in its language's field (`german_gender_ending` or `french_gender_separator`) and leaves the other language's alone. It rewrites, as far as the API marks them:
|
|
112
|
+
|
|
113
|
+
- forms in another format: `Lehrer*innen` → `Lehrer:innen`, `enseignant.e.s` → `enseignant·es`, and the articles and short endings that go with them (`die*der`, `jede/-r`, `la·le`, `un·e`);
|
|
114
|
+
- roles in the generic masculine: `Der Lehrer` → `Die:der Lehrer:in`, `le directeur` → `la·le responsable`;
|
|
115
|
+
- pair formulas and doublets, as a whole: `Schüler und Schülerinnen` → `Schüler:innen`, `les enseignantes et les enseignants` → `les enseignant·es`.
|
|
116
|
+
|
|
117
|
+
In a mixed text, a switch applies only alerts in its own language (the result's `language`, or its request's), so switching the French format never touches the German text.
|
|
118
|
+
|
|
119
|
+
**The Inklusivum.** Switching into it declines nouns for number and case (`Lehrer*innen` → `Lehrerne`, `den Schüler:innen` → `den Schülernen`) and converts articles (`die*der` → `de`, `jede/-r` → `jedey`). It leaves as written what the API cannot convert: compounds (`Mitarbeiter*innenbefragung`), nouns missing from its lexicon, and nouns whose case it cannot tell. So a switch into the Inklusivum can be partial even when the whole text was checked. Switching out of the Inklusivum is not supported by the API yet: a switch from a text in the Inklusivum finds nothing, and the editor says so (outcome `fromInklusivum`) rather than "nothing to switch".
|
|
120
|
+
|
|
121
|
+
**API versions.** French and the Inklusivum need API versions that support them (NLP API PR #1247 for French, the Inklusivum branch stacked on it). Before those are deployed, the API answers a French or Inklusivum switch with `bulk_actions: []`; the editor then reports the target as not supported by the server yet and marks it so in the panel for the rest of the session. It reads this from the API rather than hard-coding which targets work.
|
|
122
|
+
|
|
77
123
|
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 once, in the editor's live region, and passed to `onStatus` as `genderFormatSwitch`; `count` includes the gendered masculines. If only part of the text was checked (`limitReached`), what was checked is switched and the message says so.
|
|
78
124
|
|
|
79
|
-
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".
|
|
125
|
+
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". For French and the Inklusivum it cannot tell that case from an API that does not support the target yet (both answer `bulk_actions: []`), and says the latter.
|
|
80
126
|
|
|
81
|
-
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`).
|
|
127
|
+
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, for the requests in the switched language. If they differ, it changes nothing, keeps the previous setting, and says which format the organisation sets (outcome `forced`).
|
|
82
128
|
|
|
83
129
|
### The `bulk` contract
|
|
84
130
|
|
|
85
131
|
The editor decides what to apply by `bulk` alone, never by subcategory:
|
|
86
132
|
|
|
87
|
-
- A check result with `bulk: "gender_format"` belongs to the switch to the configured `german_gender_ending
|
|
133
|
+
- A check result with `bulk: "gender_format"` belongs to the switch to the configured format of its language (`german_gender_ending` or `french_gender_separator`): a form in another format, a role in the generic masculine, or a pair formula or doublet the API recognises.
|
|
88
134
|
- `bulk_alternative` is the index into its `alternatives` of the one the switch applies. The editor applies `alternatives[bulk_alternative]` when the index is an integer within range and that alternative has a `text`, and skips the result otherwise.
|
|
89
135
|
- Without `bulk_alternative` (API versions before it), a result is applied only if it has exactly one alternative, which is then the form in the target format.
|
|
90
136
|
- Such results never overlap, and applying all of them in any order gives the same text.
|
|
91
137
|
- Feminine forms, address forms, pronouns and pair formulas the API didn't recognise are left out by the API on purpose; the editor applies nothing it isn't marked for.
|
|
92
138
|
- `bulk` is absent (or `null`) on every other result. Unknown `bulk` values are ignored.
|
|
93
|
-
- Every check response lists the groups the request can return in `bulk_actions`, whether or not a result does: `["gender_format"]` for German with
|
|
94
|
-
- `gender_separator` in the check response is the format the API applied
|
|
139
|
+
- Every check response lists the groups the request can return in `bulk_actions`, whether or not a result does: `["gender_format"]` for German (with any format, the Inklusivum included) and for French, with inclusive roles and the gender-format alerts on; `[]` otherwise, and for French and the Inklusivum on API versions that cannot switch there. After the switch's check, a list without `"gender_format"` means the account keeps the switch off, or, for French and the Inklusivum, that the API cannot switch there yet.
|
|
140
|
+
- `gender_separator` in the check response is the format the API applied in the request's language: a `german_gender_ending` value for German, a `french_gender_separator` value for French.
|
|
95
141
|
|
|
96
142
|
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.
|
|
97
143
|
|
|
@@ -110,6 +156,13 @@ Part of a text can stay unchecked: anything past `maxTextLength`, or a single se
|
|
|
110
156
|
- `connect-src` for the API endpoint's origin, when it differs from the page's.
|
|
111
157
|
- **CORS:** the NLP API must allow the page's origin.
|
|
112
158
|
|
|
159
|
+
## Settings from the host: what to keep in mind
|
|
160
|
+
|
|
161
|
+
- **The switches are not access control.** Anything running in the page can call the handle, and a user can from the browser console. So `llmAlternatives: false` is a default, not a limit. Who may use the LLM at all is the NLP API's decision (`LLM_ACCESS` and its allow list, and whether clients may ask for it, `CLIENT_CONFIG_ENABLED`); how many requests they make is not limited by the API, so a deployment that has to ration them needs a rate limit in front of it. The same goes for everything in `config`: an organisation's forced settings are applied by the API, whatever the editor sends.
|
|
162
|
+
- **Keep the handle to yourself.** Don't put it on `window`; any script on the page could then change settings or read the text. The API key can only be set through it, never read back.
|
|
163
|
+
- **Settings hold no secrets.** `getSettings()` and `onSettingsChange` never include the API key, so hosts can store the settings, e.g. per user.
|
|
164
|
+
- **Spelling and the browser.** `orthography: false` lets the browser's own spellcheck underline the text again. Some browsers' enhanced spellcheck (Chrome, Edge) sends the text to the vendor's service; with `orthography: true` (the default) the editor turns the browser's spellcheck off.
|
|
165
|
+
|
|
113
166
|
## Storage
|
|
114
167
|
|
|
115
168
|
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"]`.
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import type { Editor } from '@tiptap/core';
|
|
2
|
+
/**
|
|
3
|
+
* The editor's public API types: what `dist/witty-editor.d.ts` declares for
|
|
4
|
+
* the package (`npm run build:types`). The only source of these types; the
|
|
5
|
+
* modules that use them import them from here. Keep this module free of
|
|
6
|
+
* imports other than types from @tiptap/core, so the declarations stand on
|
|
7
|
+
* their own.
|
|
8
|
+
*/
|
|
9
|
+
/** Languages `POST /v2.4/check` accepts; `auto` detects. */
|
|
10
|
+
export type CheckLang = 'auto' | 'en' | 'de' | 'fr' | 'de-DE' | 'de-CH' | 'de-AT' | 'en-US' | 'en-GB' | 'fr-FR';
|
|
11
|
+
/** Regional variants, for `primary_language` and `preferred_variants`. */
|
|
12
|
+
export type CheckVariant = 'de-DE' | 'de-CH' | 'de-AT' | 'en-US' | 'en-GB' | 'fr-FR';
|
|
13
|
+
/**
|
|
14
|
+
* Per-request `config` for `POST /v2.4/check`.
|
|
15
|
+
*
|
|
16
|
+
* Every field is optional, and only the ones a caller actually set are sent:
|
|
17
|
+
* a field in the request overrides the user's stored config where that config
|
|
18
|
+
* marks it `suggestion`, an omitted field keeps the stored value or the server
|
|
19
|
+
* default, and a stored `force` wins either way. Filling in defaults here would
|
|
20
|
+
* silently override the account's own settings.
|
|
21
|
+
*
|
|
22
|
+
* `alternatives_max_count` is deliberately absent — the server overwrites it.
|
|
23
|
+
*/
|
|
24
|
+
export interface CheckConfig {
|
|
25
|
+
/** Gender ending, as offered by `GET /v2.0/config-options`. `de-e` is Inklusivum. */
|
|
26
|
+
german_gender_ending?: '/in' | '/-in' | '_in' | '*in' | ':in' | '(-)' | '()' | 'In' | 'de-e';
|
|
27
|
+
french_gender_separator?: '·' | '·s' | '.' | '.s' | '/' | '/s';
|
|
28
|
+
gendered_roles_format?: 'none' | 'both' | 'inclusive_gender' | 'binary_gender';
|
|
29
|
+
/**
|
|
30
|
+
* Category keys from `GET /v2.0/categories`. A category and its
|
|
31
|
+
* `advanced_key` have to be disabled together.
|
|
32
|
+
*/
|
|
33
|
+
disabled_categories?: string[];
|
|
34
|
+
show_inspiration_alternatives?: boolean;
|
|
35
|
+
primary_language?: CheckVariant;
|
|
36
|
+
preferred_languages?: ('en' | 'de' | 'fr')[];
|
|
37
|
+
preferred_variants?: CheckVariant[];
|
|
38
|
+
addons?: string[];
|
|
39
|
+
/** Ignored unless the deployment sets `CLIENT_CONFIG_ENABLED`. */
|
|
40
|
+
store_context?: boolean;
|
|
41
|
+
/** Same, and the operator's `LLM_ACCESS` policy can still turn it off. */
|
|
42
|
+
llm_alternatives?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* What the user can change in the editor's settings panel, and what the host
|
|
46
|
+
* can set through the handle. One store, so the panel, `setConfig` and the
|
|
47
|
+
* checker never disagree.
|
|
48
|
+
*/
|
|
49
|
+
export interface EditorSettings {
|
|
50
|
+
/** Sent with every check; only fields that were set. */
|
|
51
|
+
config: CheckConfig;
|
|
52
|
+
/** Offer the LLM's sentence rewrites in the popover. */
|
|
53
|
+
llmAlternatives: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Witty checks spelling, so the browser's own spellcheck is off. Off here,
|
|
56
|
+
* the browser underlines misspellings as well.
|
|
57
|
+
*/
|
|
58
|
+
orthography: boolean;
|
|
59
|
+
}
|
|
60
|
+
export type SwitchOutcome =
|
|
61
|
+
/** Forms were rewritten. */
|
|
62
|
+
'switched'
|
|
63
|
+
/** Nothing in the text needed rewriting. */
|
|
64
|
+
| 'nothing'
|
|
65
|
+
/** The account's configuration keeps these alerts off (a stored force). */
|
|
66
|
+
| 'disabled'
|
|
67
|
+
/** The API predates bulk alerts. */
|
|
68
|
+
| 'unsupported'
|
|
69
|
+
/** The account forces another format; nothing was changed. */
|
|
70
|
+
| 'forced'
|
|
71
|
+
/**
|
|
72
|
+
* Nothing to switch, and the text was in the Inklusivum: the API does not
|
|
73
|
+
* convert out of it yet, so nothing may well have been possible.
|
|
74
|
+
*/
|
|
75
|
+
| 'fromInklusivum'
|
|
76
|
+
/** Not a gender format of German or French. */
|
|
77
|
+
| 'unavailable';
|
|
78
|
+
export interface GenderFormatSwitchResult {
|
|
79
|
+
outcome: SwitchOutcome;
|
|
80
|
+
target: string;
|
|
81
|
+
/** Forms rewritten. */
|
|
82
|
+
count: number;
|
|
83
|
+
/** Part of the text was not checked, so it may hold unswitched forms. */
|
|
84
|
+
limitReached: boolean;
|
|
85
|
+
/** With `forced`: the format the account enforces. */
|
|
86
|
+
applied?: string;
|
|
87
|
+
}
|
|
88
|
+
export type EditorStatus =
|
|
89
|
+
/**
|
|
90
|
+
* `limitReached`: part of the text was not checked, because it is longer
|
|
91
|
+
* than `maxTextLength` or a sentence exceeds what the API checks at once.
|
|
92
|
+
*/
|
|
93
|
+
{
|
|
94
|
+
state: 'idle';
|
|
95
|
+
alerts: number;
|
|
96
|
+
limitReached: boolean;
|
|
97
|
+
/** Set once, on the status right after a gender format switch. */
|
|
98
|
+
genderFormatSwitch?: GenderFormatSwitchResult;
|
|
99
|
+
}
|
|
100
|
+
/** The API refused the key (401), or the token behind it (403). */
|
|
101
|
+
| {
|
|
102
|
+
state: 'unauthorized';
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The API no longer supports this version of the editor (400): the host
|
|
106
|
+
* page needs to load a newer one. `message` is the API's explanation.
|
|
107
|
+
*/
|
|
108
|
+
| {
|
|
109
|
+
state: 'outdated';
|
|
110
|
+
message: string;
|
|
111
|
+
}
|
|
112
|
+
/** The API could not tell the text's language (422). */
|
|
113
|
+
| {
|
|
114
|
+
state: 'unsupportedLanguage';
|
|
115
|
+
}
|
|
116
|
+
/** Anything else, e.g. the API is unreachable; the last alerts stay. */
|
|
117
|
+
| {
|
|
118
|
+
state: 'error';
|
|
119
|
+
message: string;
|
|
120
|
+
};
|
|
121
|
+
export interface MountOptions {
|
|
122
|
+
/** NLP API base URL with trailing slash; defaults to the page's origin. */
|
|
123
|
+
endpoint?: string;
|
|
124
|
+
/** Sent as `x-key`. Set later with `setApiKey`; never read from the DOM. */
|
|
125
|
+
apiKey?: string;
|
|
126
|
+
/** Language of the text, or `auto` (the default) to let the API detect it. */
|
|
127
|
+
lang?: CheckLang;
|
|
128
|
+
/**
|
|
129
|
+
* Per-request check config. Only the fields set here are sent, so the user's
|
|
130
|
+
* stored settings keep deciding the rest. Replace it later with `setConfig`.
|
|
131
|
+
*/
|
|
132
|
+
config?: CheckConfig;
|
|
133
|
+
/** Initial content (HTML). */
|
|
134
|
+
content?: string;
|
|
135
|
+
/**
|
|
136
|
+
* The formatting bar with the Witty settings button (categories, gender
|
|
137
|
+
* formats, spelling, AI suggestions). On by default.
|
|
138
|
+
*/
|
|
139
|
+
toolbar?: boolean;
|
|
140
|
+
/** Called when the user changes a setting in the settings panel. */
|
|
141
|
+
onSettingsChange?: (settings: EditorSettings) => void;
|
|
142
|
+
/** Accessible name of the editable area. */
|
|
143
|
+
label?: string;
|
|
144
|
+
/**
|
|
145
|
+
* Ids of elements that further describe the editable area, separated by
|
|
146
|
+
* spaces; added to its `aria-describedby` after the component's own hint.
|
|
147
|
+
*/
|
|
148
|
+
describedBy?: string;
|
|
149
|
+
/**
|
|
150
|
+
* Characters per check request; longer texts are checked sentence by
|
|
151
|
+
* sentence over several requests. Match the API's TEXT_MAX_LENGTH (1000 by
|
|
152
|
+
* default); a lower limit is detected and batches shrink.
|
|
153
|
+
*/
|
|
154
|
+
maxRequestLength?: number;
|
|
155
|
+
/** Characters of the text checked at all (default 20000). */
|
|
156
|
+
maxTextLength?: number;
|
|
157
|
+
/** Debounce after the last edit, in ms. */
|
|
158
|
+
delay?: number;
|
|
159
|
+
/**
|
|
160
|
+
* Opaque id sent with each check (`id`), as the extension sends its
|
|
161
|
+
* installation id; it only ends up in the API's request logs. Defaults to
|
|
162
|
+
* a random id per editor, kept in memory. Pass a stable one, never personal
|
|
163
|
+
* data, to tell installations apart across page loads.
|
|
164
|
+
*/
|
|
165
|
+
installationId?: string;
|
|
166
|
+
/**
|
|
167
|
+
* Offer the LLM's sentence rewrites in the popover (`/v1.0/rephrase`). The
|
|
168
|
+
* extension takes this from the organisation config.
|
|
169
|
+
*/
|
|
170
|
+
llmAlternatives?: boolean;
|
|
171
|
+
/**
|
|
172
|
+
* How long to wait for the rewrites, in ms. The extension's 3s suits a
|
|
173
|
+
* hosted model; a local one (Ollama) needs longer.
|
|
174
|
+
*/
|
|
175
|
+
llmTimeoutMs?: number;
|
|
176
|
+
onStatus?: (status: EditorStatus) => void;
|
|
177
|
+
}
|
|
178
|
+
export interface WittyEditorHandle {
|
|
179
|
+
editor: Editor;
|
|
180
|
+
/** Replace the API key (empty string clears it) and check again. */
|
|
181
|
+
setApiKey(key: string): void;
|
|
182
|
+
/**
|
|
183
|
+
* Replace the whole check config — this does not merge — and check again.
|
|
184
|
+
* `{}` goes back to sending no `config`, i.e. the account's own settings.
|
|
185
|
+
*/
|
|
186
|
+
setConfig(config: CheckConfig): void;
|
|
187
|
+
/**
|
|
188
|
+
* Change settings as the settings panel does, e.g. from the host's own form
|
|
189
|
+
* (the panel follows): the fields given replace the current ones, the rest
|
|
190
|
+
* stay. `config`, when given, is replaced whole, as with `setConfig`; start
|
|
191
|
+
* from a copy of `getSettings().config` to change one field of it. Calls
|
|
192
|
+
* `onSettingsChange` once if anything changed. A changed `config` checks
|
|
193
|
+
* again; popovers opened afterwards follow `llmAlternatives`, an open one
|
|
194
|
+
* keeps what it shows.
|
|
195
|
+
*/
|
|
196
|
+
updateSettings(settings: Partial<EditorSettings>): void;
|
|
197
|
+
/** Plain text of the document. */
|
|
198
|
+
getText(): string;
|
|
199
|
+
/**
|
|
200
|
+
* The current settings: what `onSettingsChange` receives, as a copy. For a
|
|
201
|
+
* host that sends the same `config` with its own API calls.
|
|
202
|
+
*/
|
|
203
|
+
getSettings(): EditorSettings;
|
|
204
|
+
/**
|
|
205
|
+
* Rewrite every gendered form in the text into `target` (a German gender
|
|
206
|
+
* ending such as ':in'), in one undoable step, and make it the configured
|
|
207
|
+
* format. Resolves once the text has been checked and switched. Needs an NLP
|
|
208
|
+
* API with bulk alerts; see the README.
|
|
209
|
+
*/
|
|
210
|
+
switchGenderFormat(target: string): Promise<GenderFormatSwitchResult>;
|
|
211
|
+
destroy(): void;
|
|
212
|
+
}
|
|
213
|
+
/** `WittyEditor.mount` / the module's `mount`. */
|
|
214
|
+
export type Mount = (element: HTMLElement, options?: MountOptions) => WittyEditorHandle;
|
|
215
|
+
|
|
216
|
+
/** Mount the editor into `element`; see the README. */
|
|
217
|
+
export declare const mount: Mount;
|