Skip to content

Commit

Permalink
Merge branch 'main' into correct_response
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcelh1983 committed Feb 11, 2025
2 parents 795e5c7 + 52fee82 commit 351e6f8
Show file tree
Hide file tree
Showing 19 changed files with 1,817 additions and 1,522 deletions.
3 changes: 2 additions & 1 deletion .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": ["stylelint-config-standard"],
"rules": {
"selector-type-no-unknown": null
"selector-type-no-unknown": null,
"at-rule-no-deprecated": null
}
}
2,932 changes: 1,623 additions & 1,309 deletions package-lock.json

Large diffs are not rendered by default.

90 changes: 45 additions & 45 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,60 +79,60 @@
"stampino": "^0.8.3"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.1",
"@chromatic-com/storybook": "^3.2.3",
"@commitlint/cli": "^19.6.0",
"@commitlint/config-conventional": "^19.6.0",
"@custom-elements-manifest/analyzer": "^0.10.3",
"@eslint/js": "^9.16.0",
"@arethetypeswrong/cli": "^0.17.3",
"@chromatic-com/storybook": "^3.2.4",
"@commitlint/cli": "^19.7.1",
"@commitlint/config-conventional": "^19.7.1",
"@custom-elements-manifest/analyzer": "^0.10.4",
"@eslint/js": "^9.20.0",
"@lit/context": "^1.1.3",
"@open-wc/lit-helpers": "^0.7.0",
"@storybook/addon-a11y": "^8.5.0",
"@storybook/addon-actions": "^8.5.0",
"@storybook/addon-essentials": "^8.5.0",
"@storybook/addon-interactions": "^8.5.0",
"@storybook/addon-links": "^8.5.0",
"@storybook/addon-storysource": "^8.5.0",
"@storybook/blocks": "^8.5.0",
"@storybook/preview-api": "^8.5.0",
"@storybook/test": "^8.5.0",
"@storybook/addon-a11y": "^8.5.3",
"@storybook/addon-actions": "^8.5.3",
"@storybook/addon-essentials": "^8.5.3",
"@storybook/addon-interactions": "^8.5.3",
"@storybook/addon-links": "^8.5.3",
"@storybook/addon-storysource": "^8.5.3",
"@storybook/blocks": "^8.5.3",
"@storybook/preview-api": "^8.5.3",
"@storybook/test": "^8.5.3",
"@storybook/test-runner": "^0.21.0",
"@storybook/web-components": "^8.5.0",
"@storybook/web-components-vite": "^8.5.0",
"@swc/core": "^1.10.1",
"@storybook/web-components": "^8.5.3",
"@storybook/web-components-vite": "^8.5.3",
"@swc/core": "^1.10.15",
"@testing-library/dom": "^10.4.0",
"@types/dom-view-transitions": "^1.0.5",
"@types/node": "^22.10.1",
"@typescript-eslint/eslint-plugin": "^8.17.0",
"@typescript-eslint/parser": "^8.17.0",
"@types/node": "^22.13.1",
"@typescript-eslint/eslint-plugin": "^8.23.0",
"@typescript-eslint/parser": "^8.23.0",
"@vitest/browser": "^2.1.8",
"autoprefixer": "^10.4.20",
"cem-plugin-expanded-types": "^1.3.3",
"chromatic": "^11.20.0",
"custom-element-eslint-rule-generator": "^1.0.1",
"custom-element-jsx-integration": "^1.5.4",
"custom-element-react-wrappers": "^1.6.8",
"custom-element-vs-code-integration": "^1.4.1",
"cem-plugin-expanded-types": "^1.4.0",
"chromatic": "^11.25.2",
"custom-element-eslint-rule-generator": "^1.1.0",
"custom-element-jsx-integration": "^1.6.0",
"custom-element-react-wrappers": "^1.7.0",
"custom-element-vs-code-integration": "^1.5.0",
"dotenv": "^16.4.7",
"eslint": "^9.16.0",
"eslint": "^9.20.0",
"eslint-import-resolver-typescript": "^3.7.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-lit": "^1.15.0",
"eslint-plugin-lit-a11y": "^4.1.4",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react": "^7.37.4",
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
"eslint-plugin-storybook": "^0.11.2",
"eslint-plugin-wc": "^2.2.0",
"fast-xml-parser": "^4.5.0",
"globals": "^15.13.0",
"globby": "^14.0.2",
"fast-xml-parser": "^4.5.1",
"globals": "^15.14.0",
"globby": "^14.1.0",
"husky": "^9.1.7",
"lit": "^3.2.1",
"np": "^10.1.0",
"np": "^10.2.0",
"path-browserify": "^1.0.1",
"pkg-pr-new": "^0.0.37",
"playwright": "^1.49.0",
"postcss": "^8.4.49",
"pkg-pr-new": "^0.0.39",
"playwright": "^1.50.1",
"postcss": "^8.5.1",
"postcss-class-apply": "^4.0.1",
"postcss-cli": "^11.0.0",
"postcss-import": "^16.1.0",
Expand All @@ -141,19 +141,19 @@
"remark-gfm": "^4.0.0",
"shadow-dom-testing-library": "^1.11.3",
"stampino": "^0.8.3",
"storybook": "^8.5.0",
"storybook": "^8.5.3",
"storybook-addon-tag-badges": "^1.4.0",
"stylelint": "^16.11.0",
"stylelint-config-standard": "^36.0.1",
"stylelint-prettier": "^5.0.2",
"tsup": "^8.3.5",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.0",
"vite": "^6.0.3",
"stylelint": "^16.14.1",
"stylelint-config-standard": "^37.0.0",
"stylelint-prettier": "^5.0.3",
"tsup": "^8.3.6",
"typescript": "^5.7.3",
"typescript-eslint": "^8.23.0",
"vite": "^6.1.0",
"vite-tsconfig-paths": "^5.1.4",
"vitest": "^2.1.8",
"wc-storybook-helpers": "^2.0.4",
"wireit": "^0.14.9"
"wireit": "^0.14.11"
},
"optionalDependencies": {
"@rollup/rollup-linux-x64-gnu": "^4.28.1"
Expand Down
44 changes: 22 additions & 22 deletions src/lib/qti-components/qti-assessment-item/qti-assessment-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ export class QtiAssessmentItem extends LitElement {
}
});

get _context(): ItemContext {
get context(): ItemContext {
return this._contextProxy;
}

set _context(value: ItemContext) {
set context(value: ItemContext) {
Object.assign(this._contextProxy, value);
}

public get variables(): VariableValue<string | string[] | null>[] {
return this._context.variables.map(v => ({
return this.context.variables.map(v => ({
identifier: v.identifier,
value: v.value,
type: v.type,
Expand All @@ -88,17 +88,17 @@ export class QtiAssessmentItem extends LitElement {
console.warn('variables property should be an array of VariableDeclaration');
return;
}
this._context = {
...this._context,
variables: this._context.variables.map(variable => {
this.context = {
...this.context,
variables: this.context.variables.map(variable => {
const matchingValue = value.find(v => v.identifier === variable.identifier);
if (matchingValue) {
return { ...variable, ...matchingValue };
}
return variable;
})
};
this._context.variables.forEach(variable => {
this.context.variables.forEach(variable => {
if (variable.type === 'response') {
const interactionElement = this._interactionElements.find(
(el: Interaction) => el.responseIdentifier === variable.identifier
Expand All @@ -110,7 +110,7 @@ export class QtiAssessmentItem extends LitElement {
});
}

private _initialContext: Readonly<ItemContext> = { ...this._context, variables: this._context.variables };
private _initialContext: Readonly<ItemContext> = { ...this.context, variables: this.context.variables };
private _feedbackElements: QtiFeedback[] = [];
private _interactionElements: Interaction[] = [];

Expand Down Expand Up @@ -146,15 +146,15 @@ export class QtiAssessmentItem extends LitElement {
constructor() {
super();
this.addEventListener('qti-register-variable', (e: QtiRegisterVariable) => {
this._context = { ...this._context, variables: [...this._context.variables, e.detail.variable] };
this._initialContext = this._context;
this.context = { ...this.context, variables: [...this.context.variables, e.detail.variable] };
this._initialContext = this.context;
e.stopPropagation();
});
this.addEventListener('qti-register-feedback', (e: CustomEvent<QtiFeedback>) => {
e.stopPropagation();
const feedbackElement = e.detail;
this._feedbackElements.push(feedbackElement);
const numAttempts = Number(this._context.variables.find(v => v.identifier === 'numAttempts')?.value) || 0;
const numAttempts = Number(this.context.variables.find(v => v.identifier === 'numAttempts')?.value) || 0;
if (numAttempts > 0) {
feedbackElement.checkShowFeedback(feedbackElement.outcomeIdentifier);
}
Expand Down Expand Up @@ -194,7 +194,7 @@ export class QtiAssessmentItem extends LitElement {
public showCorrectResponse(show: boolean): void {
// Process response variables with correct responses.
// Update interactions with the correct responses or clear them.
for (const responseVariable of this._context.variables.filter(v => v.type === 'response') as ResponseVariable[]) {
for (const responseVariable of this.context.variables.filter(v => v.type === 'response') as ResponseVariable[]) {
const interaction = this._interactionElements.find(
element => element.getAttribute('response-identifier') === responseVariable.identifier
);
Expand Down Expand Up @@ -228,7 +228,7 @@ export class QtiAssessmentItem extends LitElement {
if (countNumAttempts) {
this.updateOutcomeVariable(
'numAttempts',
(+this._context.variables.find(v => v.identifier === 'numAttempts')?.value + 1).toString()
(+this.context.variables.find(v => v.identifier === 'numAttempts')?.value + 1).toString()
);
}

Expand All @@ -237,7 +237,7 @@ export class QtiAssessmentItem extends LitElement {
}

public resetResponses() {
this._context = this._initialContext;
this.context = this._initialContext;
}

public getResponse(identifier: string): Readonly<ResponseVariable> {
Expand All @@ -249,7 +249,7 @@ export class QtiAssessmentItem extends LitElement {
}

public getVariable(identifier: string): Readonly<VariableDeclaration<string | string[] | null>> {
return this._context.variables.find(v => v.identifier === identifier) || null;
return this.context.variables.find(v => v.identifier === identifier) || null;
}

// saving privates here: ------------------------------------------------------------------------------
Expand All @@ -260,9 +260,9 @@ export class QtiAssessmentItem extends LitElement {
}

public updateResponseVariable(identifier: string, value: string | string[] | undefined) {
this._context = {
...this._context,
variables: this._context.variables.map(v => (v.identifier !== identifier ? v : { ...v, value: value }))
this.context = {
...this.context,
variables: this.context.variables.map(v => (v.identifier !== identifier ? v : { ...v, value: value }))
};

this._emit<InteractionChangedDetails>('qti-interaction-changed', {
Expand All @@ -285,9 +285,9 @@ export class QtiAssessmentItem extends LitElement {
return;
}

this._context = {
...this._context,
variables: this._context.variables.map(v => {
this.context = {
...this.context,
variables: this.context.variables.map(v => {
if (v.identifier !== identifier) {
return v;
}
Expand All @@ -302,7 +302,7 @@ export class QtiAssessmentItem extends LitElement {
this._emit<OutcomeChangedDetails>('qti-outcome-changed', {
item: this.identifier,
outcomeIdentifier: identifier,
value: this._context.variables.find(v => v.identifier === identifier)?.value
value: this.context.variables.find(v => v.identifier === identifier)?.value
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class QtiSelectPointInteraction extends Interaction {
`No area mapping found for the response variable. Using the correct responses to display the correct response but it probably won't score correct.`
);
// Create a new area mapping object with the correct responses
areaMapEntries = correctResponses.map((r, i) => {
areaMapEntries = correctResponses.map(r => {
const coords = r.split(' ').join(',').concat(',10'); // Add a radius of 10 pixels to the coordinates
return { shape: 'circle', coords, defaultValue: 1, mappedValue: 1 };
});
Expand Down Expand Up @@ -191,7 +191,6 @@ export class QtiSelectPointInteraction extends Interaction {
aria-label="Remove point at ${point}"
@click=${(e: Event) => {
e.stopPropagation();
console.log('click');
this._points = this._points.filter((_, i) => i !== index);
this.saveResponse(this._points);
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type QtiAreaMapping = {
defaultValue: number;
lowerBound: number;
upperBound: number;
lowerBound?: number;
upperBound?: number;
areaMapEntries: QtiAreaMapEntry[];
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class QtiMapResponsePoint extends QtiExpression<number> {
const mappedAreas = new Set<string>();

for (const candidateResponse of candidateResponses) {
for (const entry of areaMapping.mapEntries) {
for (const entry of areaMapping.areaMapEntries) {
if (mappedAreas.has(entry.coords)) {
continue; // Skip areas that have already been mapped
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,19 @@ export class QtiMapResponse extends QtiExpression<number> {
});
// now find the mapped value with the highest value (if there are multiple)
const mappedValue = mappedValues.reduce(
(prev, current) => {
return prev.mappedValue > current.mappedValue ? prev : current;
},
{ mapKey: null, mappedValue: null }
(prev, current) => (prev.mappedValue > current.mappedValue ? prev : current),
mappedValues.length > 0 ? mappedValues[0] : { mapKey: null, mappedValue: null } // Use the first element instead of a manual initial value
);
if (!(mappedValue == null || mappedValue.mappedValue == undefined)) {
if (!(mappedValue === null || mappedValue.mappedValue == undefined)) {
result += mappedValue.mappedValue;
} else {
result += mapping.defaultValue;
}
}
if (mapping.lowerBound != null) {
if (mapping?.lowerBound !== null && mapping?.lowerBound !== undefined) {
result = Math.max(mapping.lowerBound, result);
}
if (mapping.upperBound != null) {
if (mapping?.upperBound !== null && mapping?.upperBound !== undefined) {
result = Math.min(mapping.upperBound, result);
}
return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type QtiMapping = {
defaultValue: number;
lowerBound: number;
upperBound: number;
lowerBound?: number;
upperBound?: number;
mapEntries: QtiMapEntry[];
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import '../../qti-response-processing/qti-response-processing';
import './../../qti-rule/qti-set-outcome-value/qti-set-outcome-value';
import './../qti-basevalue/qti-basevalue';
import './index';
import type { ItemContext } from '../../../../exports/item.context';
import type { QtiAssessmentItem } from '../../../qti-assessment-item/qti-assessment-item';
import type { ItemContext } from '../../../../exports/qti-assessment-item.context';

describe('QtiComponent qti-subtract', () => {
it('should calculate the difference of two values', () => {
Expand All @@ -32,7 +32,7 @@ describe('QtiComponent qti-subtract', () => {
render(template(), document.body);
const qtiAssessmentItem = document.body.querySelector('qti-assessment-item') as QtiAssessmentItem;
qtiAssessmentItem.processResponse();
const itemContext = (qtiAssessmentItem as any)._context as ItemContext;
const itemContext = qtiAssessmentItem.context as ItemContext;
const scoreVariable = itemContext.variables.find(v => v.identifier === 'SCORE');
expect(scoreVariable?.value).toEqual('7');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import '../../qti-response-processing/qti-response-processing';
import './../../qti-rule/qti-set-outcome-value/qti-set-outcome-value';
import './../qti-basevalue/qti-basevalue';
import './qti-sum';
import type { ItemContext } from '../../../../exports/item.context';
import type { QtiSum } from './qti-sum';
import type { QtiAssessmentItem } from '../../../qti-assessment-item/qti-assessment-item';
import type { ItemContext } from '../../../../exports/qti-assessment-item.context';

describe('QtiComponent qti-sum', () => {
it('all true', () => {
Expand All @@ -35,7 +35,7 @@ describe('QtiComponent qti-sum', () => {

const qtiAssessmentItem = document.body.querySelector('qti-assessment-item') as QtiAssessmentItem;
qtiAssessmentItem.processResponse();
const itemContext = (qtiAssessmentItem as any)._context as ItemContext;
const itemContext = qtiAssessmentItem.context as ItemContext;
const scoreVariable = itemContext.variables.find(v => v.identifier === 'SCORE');
expect(scoreVariable?.value).toEqual('3');
});
Expand Down
Loading

0 comments on commit 351e6f8

Please sign in to comment.