Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to `@webspellchecker/wproofreader-learnosity`.

The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [2.1.0]

### Changed

- Default export only.
- The `appType` partner tag sent to WProofreader is `wpr_learnosity`.

## [2.0.2]

### Changed
Expand Down Expand Up @@ -81,6 +88,7 @@ Initial public release.
- **Configurable WProofreader bundle URL** via `bundleUrl`, for customers running WProofreader from a non-default CDN host.
- **Apache-2.0 licensed.**

[2.1.0]: https://github.com/WebSpellChecker/wproofreader-learnosity/releases/tag/v2.1.0
[2.0.2]: https://github.com/WebSpellChecker/wproofreader-learnosity/releases/tag/v2.0.2
[2.0.0]: https://github.com/WebSpellChecker/wproofreader-learnosity/releases/tag/v2.0.0
[1.2.1]: https://github.com/WebSpellChecker/wproofreader-learnosity/releases/tag/v1.2.1
Expand Down
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,19 @@ npm install @webspellchecker/wproofreader-learnosity
```

```js
import { LearnosityWProofreader } from '@webspellchecker/wproofreader-learnosity';
import LearnosityWProofreader from '@webspellchecker/wproofreader-learnosity';

LearnosityWProofreader.init({
wproofreader: { serviceId: 'YOUR_WPROOFREADER_SERVICE_ID' }
});
```

The plugin is available as both a named and a default export, so a default import works too:

```js
import LearnosityWProofreader from '@webspellchecker/wproofreader-learnosity';
```

### Via `<script>` tag (non-Node host apps)

For host apps where adding a bundler is overkill (classic HTML, PHP, Python, Java, ASP.NET, Ruby), load the plugin from jsDelivr:

```html
<script src="https://cdn.jsdelivr.net/npm/@webspellchecker/wproofreader-learnosity@2.0.2/dist/wproofreader-learnosity.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@webspellchecker/wproofreader-learnosity@latest/dist/wproofreader-learnosity.min.js"></script>
<script>
LearnosityWProofreader.init({
wproofreader: { serviceId: 'YOUR_WPROOFREADER_SERVICE_ID' }
Expand All @@ -42,7 +36,7 @@ For host apps where adding a bundler is overkill (classic HTML, PHP, Python, Jav
## Quickstart

```js
import { LearnosityWProofreader } from '@webspellchecker/wproofreader-learnosity';
import LearnosityWProofreader from '@webspellchecker/wproofreader-learnosity';

// Before Learnosity widgets render.
LearnosityWProofreader.init({
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webspellchecker/wproofreader-learnosity",
"version": "2.0.2",
"version": "2.1.0",
"description": "WProofreader for Learnosity. Spelling, grammar and style assistance inside Learnosity rich-text widgets.",
"type": "module",
"main": "src/index.js",
Expand All @@ -18,7 +18,7 @@
"scripts": {
"test": "node --test --import ./tests/register-stubs.mjs tests/*.test.js",
"build": "rm -rf dist && npm run build:iife && npm run build:esm",
"build:iife": "esbuild src/index.js --bundle --format=iife --global-name=LearnosityWProofreader '--footer:js=LearnosityWProofreader=LearnosityWProofreader.LearnosityWProofreader;' --minify --outfile=dist/wproofreader-learnosity.min.js",
"build:iife": "esbuild src/index.js --bundle --format=iife --global-name=LearnosityWProofreader '--footer:js=LearnosityWProofreader=LearnosityWProofreader.default;' --minify --outfile=dist/wproofreader-learnosity.min.js",
"build:esm": "esbuild src/index.js --bundle --format=esm --minify --outfile=dist/wproofreader-learnosity.esm.js",
"prepack": "npm run build"
},
Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const SURFACE_GLOBALS = {
// explicitly with `surfaces: ['questions', 'items', 'author']`.
export const DEFAULT_SURFACES = ['author'];

export const APP_TYPE = 'learnosity_extension';
export const APP_TYPE = 'wpr_learnosity';

/*
* Split options into the WProofreader block (forwarded to the SDK's init()
Expand Down
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface InitOptions {
customSelectors?: ReadonlyArray<string>;
}

export declare class LearnosityWProofreader {
declare class LearnosityWProofreader {
static init(options?: InitOptions): void;
}

Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* creation are delegated to the WProofreader SDK; this class only decides which
* editors to attach to and cleans them up when they leave the DOM.
*
* import { LearnosityWProofreader } from '@webspellchecker/wproofreader-learnosity';
* import LearnosityWProofreader from '@webspellchecker/wproofreader-learnosity';
* LearnosityWProofreader.init({ wproofreader: { serviceId: '...' } });
*/

Expand Down Expand Up @@ -227,5 +227,6 @@ class LearnosityWProofreader {
}
}

export { LearnosityWProofreader };
// Default export:
// import LearnosityWProofreader from '@webspellchecker/wproofreader-learnosity';
export default LearnosityWProofreader;
6 changes: 3 additions & 3 deletions tests/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('serviceId path: Cloud config with grammar/autocorrect/appType defaults', (
assert.equal(config.wproofreader.serviceId, 'svc-123');
assert.equal(config.wproofreader.enableGrammar, true);
assert.equal(config.wproofreader.autocorrect, true);
assert.equal(config.wproofreader.appType, 'learnosity_extension');
assert.equal(config.wproofreader.appType, 'wpr_learnosity');
});

test('self-hosted service options pass through unchanged', () => {
Expand Down Expand Up @@ -50,12 +50,12 @@ test('enableGrammar and autocorrect can be turned off explicitly', () => {
test('appType is set to the fixed partner tag', () => {
const config = buildConfig({ wproofreader: { serviceId: 'svc' } });
assert.equal(config.wproofreader.appType, APP_TYPE);
assert.equal(APP_TYPE, 'learnosity_extension');
assert.equal(APP_TYPE, 'wpr_learnosity');
});

test('appType is not caller-configurable: a supplied value is ignored', () => {
const config = buildConfig({ wproofreader: { serviceId: 'svc', appType: 'custom_partner' } });
assert.equal(config.wproofreader.appType, 'learnosity_extension');
assert.equal(config.wproofreader.appType, 'wpr_learnosity');
});

test('explicit wproofreader.lang overrides defaultLang', (t) => {
Expand Down
10 changes: 5 additions & 5 deletions tests/connector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import assert from 'node:assert/strict';
// Cache-bust each import so the connector's static state doesn't leak between tests.
async function freshConnector() {
const mod = await import('../src/index.js?bust=' + Math.random());
return mod.LearnosityWProofreader;
return mod.default;
}

test('exposes the API as both a named and a default export of the same object', async () => {
test('exposes the API as a default export only (no named export)', async () => {
const mod = await import('../src/index.js?bust=' + Math.random());
assert.equal(typeof mod.LearnosityWProofreader.init, 'function');
assert.equal(mod.default, mod.LearnosityWProofreader);
assert.equal(typeof mod.default.init, 'function');
assert.equal(mod.LearnosityWProofreader, undefined);
});

// Minimal fake element. classList is a plain array (the connector only reads
Expand Down Expand Up @@ -95,7 +95,7 @@ test('attaches via the SDK with the built wproofreader options incl. appType', a
assert.equal(globalThis.__sdkInitCalls.length, 1);
const { options } = globalThis.__sdkInitCalls[0];
assert.equal(options.serviceId, 'svc-123');
assert.equal(options.appType, 'learnosity_extension');
assert.equal(options.appType, 'wpr_learnosity');
assert.equal(options.enableGrammar, true);
assert.equal(options.container, container);
});
Expand Down
Loading