@witty-works/editor 2.0.1 → 2.1.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 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@0.1.0/dist/witty-editor.js"></script>
11
+ <script src="https://cdn.jsdelivr.net/npm/@witty-works/editor@2.1.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,43 @@ 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
+ | `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 |
34
35
  | `toolbar` | `true` | Formatting toolbar with the Witty settings button |
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
- | `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 |
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}` |
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.
46
50
  - `editor`: the underlying [TipTap](https://tiptap.dev) editor.
47
51
  - `destroy()`: remove the editor and everything it added to the page.
48
52
 
53
+ ## Long texts
54
+
55
+ 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.
56
+
57
+ 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.
58
+
49
59
  ## Requirements
50
60
 
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).
61
+ - **Content-Security-Policy:**
62
+ - `script-src` must allow the script, and `style-src` inline styles: the editor injects its own `<style>`.
63
+ - `img-src data:` for the popover's logo, which is inline.
64
+ - `img-src https://www.witty.works` for the pictures in the explanations ("learning bites").
65
+ - `connect-src` for the API endpoint's origin, when it differs from the page's.
66
+ - **CORS:** the NLP API must allow the page's origin.
67
+
68
+ ## Storage
69
+
70
+ 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
71
 
54
72
  ## License
55
73