Skip to content

Commit

Permalink
Separated code into and modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsharman committed Feb 9, 2024
1 parent 06c67e1 commit 2380ced
Show file tree
Hide file tree
Showing 31 changed files with 169 additions and 79 deletions.
58 changes: 49 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# LT - Learnosity Toolkit

This is a utility library of helper modules useful if you're developing with Learnosity APIs.
This is a utility library of helper modules and extensions that may be useful if you're developing with Learnosity APIs.

Modules are separated between Assessment (when using Items API) and Authoring (when using Author API).
Modules and extensions are separated between Assessment (when using Items API) and Authoring (when using Author API).

See [documentation here](https://michaelsharman.github.io/LT/).

Expand All @@ -23,6 +23,39 @@ Everything is open source under the MIT license. Feel free to use as you see fit
npm install @caspingus/lt
```

## Usage

You can import `core` or `index` into your project, from either the `src` or `dist` directories.

### core vs index

**Recommendation** - use `core` in all production settings.

The `core` module contains the LT toolkit only, no extensions. This is the smallest file size (around 3.5k gzipped) and may be all you need.

If you want 1 or 2 extensions, you can import them manually to keep the overall file size down.

```
import { LT } from '@caspingus/lt/src/assessment/core';
import * as columnResizer from '@caspingus/lt/src/assessment/extensions/accessibility/ux/columnResizer';
```

The `index` module contains everything in `core` along with _all_ extensions. This is the largest file size (~400k) This is useful in development if you want to browse the extensions, but also if you happen to use all the extensions in your project.

```
import { LT } from '@caspingus/lt/src/assessment/index';
```

^^ Importing `index` puts all extensions in `LT.extensions`.

### src vs dist

**Recommendation** - use `src` and have your local build process bundle LT along with your application.

As this library will be imported into existing projects, it's recommended to use the `src` folder and include LT as a part of your build process.

In which case, import from the `src` folder and you're good to go. Another option is to import from `dist` which has been prod bundled by Webpack, but then you need to exclude this from your build process.

## Initialize

Everything is written using ES6 modules. By default we use `LT` as a variable for
Expand All @@ -39,22 +72,29 @@ const itemsApp = LearnosityItems.init(signedConfigObject);
// Pass that app instance to the Toolkit constructor
import { LT } from '@caspingus/lt/src/assessment/index';
LT.init(itemsApp);
import { LT } from '@caspingus/lt/src/assessment/core';
import * as renderPDF from '@caspingus/lt/src/assessment/extensions/ui/renderPDF/index';
LT.init(itemsApp);
// Optionally call any extensions you might want
LT.extensions.keyboardShortcuts.run();
renderPDF.run();
// Put individual extensions in the LT object if that makes your life easier
LT.extensions = {
renderPDF,
};
LT.extensions.renderPDF.run();
// Optionally add to the global scope (for development)
// Optionally add to the global scope (handy for development)
window.LT = LT;
```

## Usage examples

```
import { LT } from '@caspingus/lt/src/assessment/index';
import { LT } from '@caspingus/lt/src/assessment/core';
// See if the item was _fully_ attempted
LT.isItemFullyAttempted();
Expand All @@ -74,7 +114,7 @@ const authorApp = LearnosityAuthor.init(signedConfigObject);
// Pass that app instance to the Toolkit constructor
import { LT } from '@caspingus/lt/src/authoring/index';
import { LT } from '@caspingus/lt/src/authoring/core';
LT.init(authorApp);
Expand All @@ -85,7 +125,7 @@ window.LT = LT;
## Usage examples

```
import { LT } from '@caspingus/lt/src/authoring/index';
import { LT } from '@caspingus/lt/src/authoring/core';
// Injects a route hash to the URI so SPAs can load to a deep view from a full page refresh.
LT.routingHash();
Expand Down
42 changes: 33 additions & 9 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ <h2><a href="index.html">Home</a></h2><h2><a href="https://github.com/michaelsha

<section class="readme usertext">
<article><h1 id="lt---learnosity-toolkit">LT - Learnosity Toolkit</h1>
<p>This is a utility library of helper modules useful if you're developing with Learnosity APIs.</p>
<p>Modules are separated between Assessment (when using Items API) and Authoring (when using Author API).</p>
<p>This is a utility library of helper modules and extensions that may be useful if you're developing with Learnosity APIs.</p>
<p>Modules and extensions are separated between Assessment (when using Items API) and Authoring (when using Author API).</p>
<p>See <a href="https://michaelsharman.github.io/LT/">documentation here</a>.</p>
<h2 id="important">Important</h2>
<p>This package is unofficial and wasn't created by Learnosity.</p>
Expand All @@ -80,6 +80,23 @@ <h2 id="important">Important</h2>
<h2 id="installation">Installation</h2>
<pre class="prettyprint source"><code>npm install @caspingus/lt
</code></pre>
<h2 id="usage">Usage</h2>
<p>You can import <code>core</code> or <code>index</code> into your project, from either the <code>src</code> or <code>dist</code> directories.</p>
<h3 id="core-vs-index">core vs index</h3>
<p><strong>Recommendation</strong> - use <code>core</code> in all production settings.</p>
<p>The <code>core</code> module contains the LT toolkit only, no extensions. This is the smallest file size (around 3.5k gzipped) and may be all you need.</p>
<p>If you want 1 or 2 extensions, you can import them manually to keep the overall file size down.</p>
<pre class="prettyprint source"><code>import { LT } from '@caspingus/lt/src/assessment/core';
import * as columnResizer from '@caspingus/lt/src/assessment/extensions/accessibility/ux/columnResizer';
</code></pre>
<p>The <code>index</code> module contains everything in <code>core</code> along with <em>all</em> extensions. This is the largest file size (~400k) This is useful in development if you want to browse the extensions, but also if you happen to use all the extensions in your project.</p>
<pre class="prettyprint source"><code>import { LT } from '@caspingus/lt/src/assessment/index';
</code></pre>
<p>^^ Importing <code>index</code> puts all extensions in <code>LT.extensions</code>.</p>
<h3 id="src-vs-dist">src vs dist</h3>
<p><strong>Recommendation</strong> - use <code>src</code> and have your local build process bundle LT along with your application.</p>
<p>As this library will be imported into existing projects, it's recommended to use the <code>src</code> folder and include LT as a part of your build process.</p>
<p>In which case, import from the <code>src</code> folder and you're good to go. Another option is to import from <code>dist</code> which has been prod bundled by Webpack, but then you need to exclude this from your build process.</p>
<h2 id="initialize">Initialize</h2>
<p>Everything is written using ES6 modules. By default we use <code>LT</code> as a variable for
the toolkit. If you want to change this, use named imports.</p>
Expand All @@ -91,19 +108,26 @@ <h2 id="items-api">Items API</h2>


// Pass that app instance to the Toolkit constructor
import { LT } from '@caspingus/lt/src/assessment/index';
LT.init(itemsApp);
import { LT } from '@caspingus/lt/src/assessment/core';
import * as renderPDF from '@caspingus/lt/src/assessment/extensions/ui/renderPDF/index';

LT.init(itemsApp);

// Optionally call any extensions you might want
LT.extensions.keyboardShortcuts.run();
renderPDF.run();

// Put individual extensions in the LT object if that makes your life easier
LT.extensions = {
renderPDF,
};
LT.extensions.renderPDF.run();

// Optionally add to the global scope (for development)

// Optionally add to the global scope (handy for development)
window.LT = LT;
</code></pre>
<h2 id="usage-examples">Usage examples</h2>
<pre class="prettyprint source"><code>import { LT } from '@caspingus/lt/src/assessment/index';
<pre class="prettyprint source"><code>import { LT } from '@caspingus/lt/src/assessment/core';

// See if the item was _fully_ attempted
LT.isItemFullyAttempted();
Expand All @@ -120,15 +144,15 @@ <h2 id="author-api">Author API</h2>


// Pass that app instance to the Toolkit constructor
import { LT } from '@caspingus/lt/src/authoring/index';
import { LT } from '@caspingus/lt/src/authoring/core';
LT.init(authorApp);


// Optionally add to the global scope (for development)
window.LT = LT;
</code></pre>
<h2 id="usage-examples-1">Usage examples</h2>
<pre class="prettyprint source"><code>import { LT } from '@caspingus/lt/src/authoring/index';
<pre class="prettyprint source"><code>import { LT } from '@caspingus/lt/src/authoring/core';

// Injects a route hash to the URI so SPAs can load to a deep view from a full page refresh.
LT.routingHash();
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@caspingus/lt",
"version": "2.2.1",
"version": "2.3.0",
"description": "A utility library of helpers and tools for working with Learnosity APIs.",
"main": "src/index.js",
"author": "michael@learnosity.com",
Expand Down
16 changes: 16 additions & 0 deletions src/assessment/core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as app from './core/app';
import * as activity from './core/activity';
import * as diagnostics from './core/diagnostics';
import * as items from './core/items';
import * as player from './core/player';
import * as questions from './core/questions';
import * as sections from './core/sections';
import logger from '../utils/logger';

const utils = {
utils: {
logger,
},
};

export const LT = { ...app, ...items, ...activity, ...player, ...questions, ...sections, ...diagnostics, ...utils };
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as app from './app';
import * as sections from './sections';
import logger from '../utils/logger';
import logger from '../../utils/logger';

/**
* Everything relating to the activity currently
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as app from './app';
import * as activity from './activity';
import logger from '../utils/logger';
import logger from '../../utils/logger';

/**
* Diagnostic/metadata information for Items API.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/assessment/player.js → src/assessment/core/player.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as app from './app';
import * as items from './items';
import logger from '../utils/logger';
import logger from '../../utils/logger';

/**
* Everything relating to the assessment player.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as app from './app';
import * as items from './items';
import logger from '../utils/logger';
import logger from '../../utils/logger';

/**
* Everything relating to questions currently
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as app from '../../../app';
import * as activity from '../../../activity';
import * as app from '../../../core/app';
import * as activity from '../../../core/activity';

/**
* Extensions add specific functionality to Items API.
Expand Down
4 changes: 2 additions & 2 deletions src/assessment/extensions/accessibility/ux/columnResizer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as app from '../../../app';
import * as item from '../../../items';
import * as app from '../../../core/app';
import * as item from '../../../core/items';

/**
* Extensions add specific functionality to Items API.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as app from '../../../app';
import * as questions from '../../../questions';
import * as app from '../../../core/app';
import * as questions from '../../../core/questions';
import * as shuffleSeed from 'shuffle-seed';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as app from '../../../app';
import * as items from '../../../items';
import * as questions from '../../../questions';
import * as app from '../../../core/app';
import * as items from '../../../core/items';
import * as questions from '../../../core/questions';
import * as platform from 'platform-detect';
import * as Mousetrap from 'mousetrap';

Expand Down
4 changes: 2 additions & 2 deletions src/assessment/extensions/accessibility/ux/magnifier.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as app from '../../../app';
import * as items from '../../../items';
import * as app from '../../../core/app';
import * as items from '../../../core/items';

/**
* Extensions add specific functionality to Items API.
Expand Down
4 changes: 2 additions & 2 deletions src/assessment/extensions/accessibility/ux/mcqLabelPrefix.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as app from '../../../app';
import * as app from '../../../core/app';
import logger from '../../../../utils/logger';
import * as question from '../../../questions';
import * as question from '../../../core/questions';

/**
* Extensions add specific functionality to Items API.
Expand Down
4 changes: 2 additions & 2 deletions src/assessment/extensions/accessibility/ux/resetResponse.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as app from '../../../app';
import * as app from '../../../core/app';
import logger from '../../../../utils/logger';
import * as question from '../../../questions';
import * as question from '../../../core/questions';

/**
* Extensions add specific functionality to Items API.
Expand Down
4 changes: 2 additions & 2 deletions src/assessment/extensions/ui/renderPDF/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as app from '../../../app';
import * as items from '../../../items';
import * as app from '../../../core/app';
import * as items from '../../../core/items';
import * as pdfjs from '../../../../vendor/pdfjs-dist/build/pdf.mjs';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/assessment/extensions/validation/blockGrammarChecks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as app from '../../app';
import * as app from '../../core/app';

/**
* Extensions add specific functionality to Items API.
Expand Down
10 changes: 5 additions & 5 deletions src/assessment/extensions/validation/essayLimitByCharacter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as app from '../../app';
import * as app from '../../core/app';
import logger from '../../../utils/logger';
import * as activity from '../../activity';
import * as player from '../../player';
import * as items from '../../items';
import * as questions from '../../questions';
import * as activity from '../../core/activity';
import * as player from '../../core/player';
import * as items from '../../core/items';
import * as questions from '../../core/questions';

/**
* Extensions add specific functionality to Items API.
Expand Down
24 changes: 9 additions & 15 deletions src/assessment/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as app from './app';
import * as activity from './activity';
import * as diagnostics from './diagnostics';
import * as items from './items';
import * as player from './player';
import * as questions from './questions';
import * as sections from './sections';
import logger from '../utils/logger';
/**
* index.js is a "kitchen sink" file that will load everything when imported. The
* core LT library, plus all extensions. Probably only use this for development
* because of the size. In production, try importing core.js and any extensions
* you might want separately.
*/

import { LT as core } from './core';

import * as ariaCountOnNav from './extensions/accessibility/aria/ariaCountOnNav';
import * as blockGrammarChecks from './extensions/validation/blockGrammarChecks';
Expand All @@ -19,12 +19,6 @@ import * as pageOverlay from './extensions/accessibility/ux/pageOverlay';
import * as renderPDF from './extensions/ui/renderPDF/index';
import * as resetResponse from './extensions/accessibility/ux/resetResponse';

const utils = {
utils: {
logger,
},
};

const extensions = {
extensions: {
ariaCountOnNav: { ...ariaCountOnNav },
Expand All @@ -41,4 +35,4 @@ const extensions = {
},
};

export const LT = { ...app, ...items, ...activity, ...player, ...questions, ...sections, ...diagnostics, ...utils, ...extensions };
export const LT = { ...core, ...extensions };
Loading

0 comments on commit 2380ced

Please sign in to comment.