@graffiticode/learnosity-cqt
v0.1.2
Published
Language-agnostic Learnosity custom question type runtime for Graffiticode languages
Downloads
514
Readme
@graffiticode/learnosity-cqt
The Learnosity custom question type runtime shared by Graffiticode languages.
Learnosity loads two bundles per question type — a browser question.js and a
scorer.js that also runs server-side — and instantiates new Question(init, lrnUtils)
and new Scorer(question, responseValue). This package supplies both classes; a language
supplies only its renderer and its scoring functions.
Usage
import { createQuestion, createScorer } from "@graffiticode/learnosity-cqt";
import { Form, scoreCells, getCellsValidation } from "@graffiticode/l0166";
const defaultData = {
validation: { points: 0, ranges: {}, cells: {} },
interaction: { type: "table", v: "0.0.1", cells: {}, columns: {} },
};
export const Question = createQuestion({ Form, scoreCells, getCellsValidation, defaultData });
export const Scorer = createScorer({ scoreCells, defaultData });defaultData is a parameter rather than a constant because the fallback envelope is
language-specific — the shape above is the spreadsheet one.
Ship the stylesheet and the authoring layout alongside the bundles:
import "@graffiticode/learnosity-cqt/styles.css";@graffiticode/learnosity-cqt/authoring-layout.html is the Question Editor layout: a
348-line postMessage bridge that opens the Graffiticode editor in a popup and writes the
authored item back through editor.getJson() / setJson(). It is generic apart from a
single __GC_LANG__ placeholder, which the consuming build substitutes with the four-digit
language id.
Scoring contract
This package implements the cell-scoring contract: scoreCells({ cells, validation })
returns the cells with a score attached, and the question's total is the sum of
score.points across cells. That yields partial credit.
Languages that predate scoreCells — l0152, l0153, l0154, l0155, l0157 — use an
all-or-nothing contract instead, comparing the response against
question.valid_response.value. That path is not implemented here yet. Adding it means
a sibling pair of factories (createSimpleQuestion / createSimpleScorer) rather than
branching inside these: the two differ in their state reducer, their suggested-answer
derivation, and their scoring, so a shared implementation would be mostly if.
Notes
- Built with Babel, not the repo's
tsconfig.base.json— this is browser JSX, and that config targets Node (lib: ["ES2022"], no DOM, nojsx). Output is ESM so consumers can keep the usualexclude: /node_modules/on their ownbabel-loader. reactandreact-domare peer dependencies.
