ep_spellcheck 0.0.98 → 0.0.99

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/ep.json CHANGED
@@ -2,12 +2,15 @@
2
2
  "parts": [
3
3
  {
4
4
  "name": "ep_spellcheck",
5
- "client_hooks": {
6
- "postAceInit": "ep_spellcheck/static/js/spellcheck:postAceInit"
7
- },
8
5
  "hooks": {
6
+ "loadSettings": "ep_spellcheck/spellcheck",
7
+ "clientVars": "ep_spellcheck/spellcheck",
9
8
  "eejsBlock_mySettings": "ep_spellcheck/spellcheck",
10
- "eejsBlock_dd_view" : "ep_spellcheck/spellcheck"
9
+ "eejsBlock_padSettings": "ep_spellcheck/spellcheck"
10
+ },
11
+ "client_hooks": {
12
+ "postAceInit": "ep_spellcheck/static/js/spellcheck:postAceInit",
13
+ "handleClientMessage_CLIENT_MESSAGE": "ep_spellcheck/static/js/spellcheck:handleClientMessage_CLIENT_MESSAGE"
11
14
  }
12
15
  }
13
16
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ep_spellcheck",
3
- "version": "0.0.98",
3
+ "version": "0.0.99",
4
4
  "keywords": [
5
5
  "spell",
6
6
  "check",
@@ -21,6 +21,9 @@
21
21
  "type": "individual",
22
22
  "url": "https://etherpad.org/"
23
23
  },
24
+ "dependencies": {
25
+ "ep_plugin_helpers": "^0.5.2"
26
+ },
24
27
  "devDependencies": {
25
28
  "eslint": "^8.57.1",
26
29
  "eslint-config-etherpad": "^4.0.5",
package/spellcheck.js CHANGED
@@ -1,21 +1,29 @@
1
1
  'use strict';
2
2
 
3
- const eejs = require('ep_etherpad-lite/node/eejs/');
4
- const settings = require('ep_etherpad-lite/node/utils/Settings');
3
+ const {padToggle} = require('ep_plugin_helpers/pad-toggle-server');
5
4
 
6
- exports.eejsBlock_mySettings = (hookName, args, cb) => {
7
- let checkedState = 'checked';
8
- if (settings.ep_spellcheck) {
9
- if (settings.ep_spellcheck.disabledByDefault === true) {
10
- checkedState = '';
11
- }
5
+ // Parallel User Settings + Pad Wide Settings checkboxes for "Spell Check".
6
+ // Helper owns markup, storage, broadcast, enforce, and i18n wiring.
7
+ const spellcheckToggle = padToggle({
8
+ pluginName: 'ep_spellcheck',
9
+ settingId: 'spellcheck',
10
+ l10nId: 'ep_spellcheck.spellcheck',
11
+ defaultLabel: 'Spell Check',
12
+ defaultEnabled: true,
13
+ });
14
+
15
+ // Older settings.json used `ep_spellcheck.disabledByDefault: true` to flip
16
+ // the checkbox off. Translate to the helper's `defaultEnabled` so existing
17
+ // installs keep their current behavior after the conversion.
18
+ exports.loadSettings = async (hookName, args) => {
19
+ const ps = args && args.settings && args.settings.ep_spellcheck;
20
+ if (ps && typeof ps.defaultEnabled !== 'boolean' &&
21
+ typeof ps.disabledByDefault === 'boolean') {
22
+ ps.defaultEnabled = !ps.disabledByDefault;
12
23
  }
13
- const ejsPath = 'ep_spellcheck/templates/spellcheck_entry.ejs';
14
- args.content += eejs.require(ejsPath, {checked: checkedState});
15
- return cb();
24
+ return spellcheckToggle.loadSettings(hookName, args);
16
25
  };
17
26
 
18
- exports.eejsBlock_dd_view = (hookName, args, cb) => {
19
- const li = "<li><a href='#' onClick='$(\"#options-spellcheck\").click();'>Spell Check</a></li>";
20
- args.content += li;
21
- };
27
+ exports.clientVars = spellcheckToggle.clientVars;
28
+ exports.eejsBlock_mySettings = spellcheckToggle.eejsBlock_mySettings;
29
+ exports.eejsBlock_padSettings = spellcheckToggle.eejsBlock_padSettings;
@@ -1,51 +1,35 @@
1
1
  'use strict';
2
2
 
3
- const padcookie = require('ep_etherpad-lite/static/js/pad_cookie').padcookie;
3
+ // Sub-path import keeps the client bundle clean — the top-level
4
+ // `ep_plugin_helpers` index pulls in server-only modules (eejs, Settings).
5
+ const {padToggle} = require('ep_plugin_helpers/pad-toggle');
4
6
 
5
- const postAceInit = (hook, context) => {
6
- const $outer = $('iframe[name="ace_outer"]').contents().find('iframe');
7
- const $inner = $outer.contents().find('#innerdocbody');
8
- // The `spellcheck` attribute is inherited from the nearest ancestor that
9
- // sets it, so we only need to toggle it on #innerdocbody. The previous
10
- // implementation walked every <div>/<span> descendant on every toggle,
11
- // which is O(n) in line count and multiplied the browser's already-slow
12
- // per-keystroke spellchecking work — observable as typing lag on pads
13
- // with more than a few hundred lines (#26). Setting the attribute once
14
- // on the contenteditable root is equivalent for the browser's checker.
15
- const spellcheck = {
16
- enable: () => { $inner.attr('spellcheck', 'true'); },
17
- disable: () => { $inner.attr('spellcheck', 'false'); },
18
- };
19
- /* init */
20
- if (padcookie.getPref('spellcheck') === false) {
21
- $('#options-spellcheck').val();
22
- $('#options-spellcheck').attr('checked', 'unchecked');
23
- $('#options-spellcheck').attr('checked', false);
24
- } else {
25
- $('#options-spellcheck').attr('checked', 'checked');
26
- }
7
+ // Same config as the server-side instance — must agree on pluginName,
8
+ // settingId, l10nId, and defaultLabel so checkbox ids and clientVars line up.
9
+ const spellcheckToggle = padToggle({
10
+ pluginName: 'ep_spellcheck',
11
+ settingId: 'spellcheck',
12
+ l10nId: 'ep_spellcheck.spellcheck',
13
+ defaultLabel: 'Spell Check',
14
+ defaultEnabled: true,
15
+ });
16
+
17
+ // Re-export so the helper sees pad-wide broadcasts and refreshes our state
18
+ // when another user toggles the pad-wide checkbox.
19
+ exports.handleClientMessage_CLIENT_MESSAGE = spellcheckToggle.handleClientMessage_CLIENT_MESSAGE;
27
20
 
28
- if ($('#options-spellcheck').is(':checked')) {
29
- spellcheck.enable();
30
- } else {
31
- spellcheck.disable();
32
- }
21
+ exports.postAceInit = () => {
22
+ // The `spellcheck` attribute is inherited from the nearest ancestor that
23
+ // sets it, so we only need to toggle it on #innerdocbody. Walking every
24
+ // <div>/<span> descendant (the previous behavior) is O(n) in line count
25
+ // and multiplied the browser's already-slow per-keystroke spellchecking
26
+ // work — observable as typing lag on pads with > a few hundred lines (#26).
27
+ const $inner = $('iframe[name="ace_outer"]').contents().find('iframe')
28
+ .contents().find('#innerdocbody');
33
29
 
34
- /* on click */
35
- $('#options-spellcheck').on('click', () => {
36
- if ($('#options-spellcheck').is(':checked')) {
37
- padcookie.setPref('spellcheck', true);
38
- spellcheck.enable();
39
- } else {
40
- padcookie.setPref('spellcheck', false);
41
- spellcheck.disable();
42
- }
43
- // The previous code force-reloaded the page on Chrome via
44
- // `window.browser.chrome`. That check was always a no-op on Chrome
45
- // (Chrome has no `window.browser` object — it's the Firefox
46
- // WebExtension API) and would have thrown a TypeError on Firefox.
47
- // Toggling the spellcheck attribute takes effect in every current
48
- // browser without a reload, so just drop the reload.
30
+ spellcheckToggle.init({
31
+ onChange: (enabled) => {
32
+ $inner.attr('spellcheck', enabled ? 'true' : 'false');
33
+ },
49
34
  });
50
35
  };
51
- exports.postAceInit = postAceInit;
@@ -1,4 +0,0 @@
1
- <p>
2
- <input type="checkbox" id="options-spellcheck" <%= checked %>></input>
3
- <label for="options-spellcheck" data-l10n-id="ep_spellcheck.spellcheck">Spell Check</label>
4
- </p>