@citolab/tspci 2.5.30-beta.6 → 2.5.30-beta.7

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/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.5.30-beta.7](/compare/v2.5.30-beta.6...v2.5.30-beta.7) (2025-02-04)
7
+
8
+
9
+ ### Features
10
+
11
+ * dispatch qti-interaction-changed event 5c81bab
12
+
13
+
14
+
15
+
16
+
6
17
  ## [2.5.30-beta.6](/compare/v2.5.30-beta.5...v2.5.30-beta.6) (2025-02-03)
7
18
 
8
19
  **Note:** Version bump only for package @citolab/tspci
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@citolab/tspci",
3
- "version": "2.5.30-beta.6",
3
+ "version": "2.5.30-beta.7",
4
4
  "description": "an opiniated typescript ims-pci builder with tao integration",
5
5
  "author": "patrick <patrick.deklein@cito.nl>",
6
6
  "repository": "@citolab/tspci",
@@ -51,5 +51,5 @@
51
51
  "resolutions": {
52
52
  "chokidar": "^4.0.0"
53
53
  },
54
- "gitHead": "72c387c7c038445173cd72471bf8ff66896121a7"
54
+ "gitHead": "dee27b54f3790bef797b70f8a1058ffc3ca385ba"
55
55
  }
@@ -54,10 +54,25 @@ class Pci {
54
54
  this.shadowdom.dispatchEvent(interactionChangedEvent);
55
55
  };
56
56
 
57
+ interactionChanged = () => {
58
+ const event = {
59
+ interaction: this,
60
+ responseIdentifier: this.config.responseIdentifier,
61
+ valid: true,
62
+ value: this.getResponse(),
63
+ };
64
+ // dispatch a custom event to notify the Delivery System that the interaction has changed
65
+ const interactionChangedEvent = new CustomEvent("qti-interaction-changed", {
66
+ detail: event,
67
+ });
68
+ this.dom.dispatchEvent(interactionChangedEvent);
69
+ };
70
+
57
71
  render = () => {
58
72
  this.shadowdom.addEventListener("change", (e) => {
59
73
  const value = e.target.value;
60
74
  this.state = value;
75
+ this.interactionChanged();
61
76
  });
62
77
  this.shadowdom.innerHTML = `<div class="pci-container">
63
78
  <h1>${this.config.properties.title}</h1>
@@ -4,7 +4,7 @@ import { IStore } from "@citolab/preact-store";
4
4
  import * as ctx from "qtiCustomInteractionContext";
5
5
  import Interaction from "./interaction";
6
6
  import style from "./styles.css";
7
- import { Configuration, IMSpci, QtiVariableJSON } from "@citolab/tspci";
7
+ import { Configuration, IMSpci, QtiInteractionChangedDetail, QtiVariableJSON } from "@citolab/tspci";
8
8
  import configProps from "./config.json";
9
9
  import { StateModel, initStore } from "./store";
10
10
 
@@ -28,7 +28,9 @@ class App implements IMSpci<PropTypes> {
28
28
  getInstance = (dom: HTMLElement, config: Configuration<PropTypes>, stateString: string) => {
29
29
  config.properties = { ...configProps, ...config.properties }; // merge current props with incoming
30
30
  this.config = config;
31
-
31
+ if (!dom) {
32
+ throw new Error("No DOM Element provided");
33
+ }
32
34
  this.logActions = stateString ? JSON.parse(stateString).log : [];
33
35
  this.store = initStore(this.initialState);
34
36
  try {
@@ -41,6 +43,21 @@ class App implements IMSpci<PropTypes> {
41
43
  }
42
44
 
43
45
  this.shadowdom = dom.attachShadow({ mode: "closed" });
46
+
47
+ this.store.subscribe(() => {
48
+ const event: QtiInteractionChangedDetail = {
49
+ interaction: this,
50
+ responseIdentifier: this.config.responseIdentifier,
51
+ valid: true,
52
+ value: this.getResponse(),
53
+ };
54
+ // dispatch a custom event to notify the Delivery System that the interaction has changed
55
+ const interactionChangedEvent = new CustomEvent("qti-interaction-changed", {
56
+ detail: event,
57
+ });
58
+ dom.dispatchEvent(interactionChangedEvent);
59
+ });
60
+
44
61
  this.render();
45
62
 
46
63
  if (this.config.onready) {
@@ -1,4 +1,4 @@
1
- import { Configuration, IMSpci, QtiVariableJSON } from "@citolab/tspci";
1
+ import { Configuration, IMSpci, QtiInteractionChangedDetail, QtiVariableJSON } from "@citolab/tspci";
2
2
  import * as ctx from "qtiCustomInteractionContext";
3
3
  import configProps from "./config.json";
4
4
  import Interaction from "./interaction"; // import and bundle this interaction file
@@ -13,6 +13,7 @@ class Pci implements IMSpci<PropTypes> {
13
13
  config: Configuration<PropTypes>; // reference to the interface of the config object which you get when getInstance is called by the player
14
14
  state: string; // keep a reference to the state
15
15
  shadowdom: ShadowRoot | Element; // Not mandatory, but its wise to create a shadowroot
16
+ dom: HTMLElement;
16
17
 
17
18
  constructor() {
18
19
  if (ctx) {
@@ -22,21 +23,40 @@ class Pci implements IMSpci<PropTypes> {
22
23
 
23
24
  // First in the lifecycle of a PCI, this method is called with the domElement ( usually qti-interaction-markup ) where we can add our dom tree.
24
25
  // config is the configuration object which has an onready
25
- getInstance = (dom: HTMLElement, config: Configuration<any>, state: string) => {
26
+ getInstance = (dom: HTMLElement, config: Configuration<PropTypes>, state: string) => {
26
27
  config.properties = { ...configProps, ...config.properties }; // merge current props with incoming
27
28
  this.config = config;
28
29
  this.state = state ? state : "";
29
-
30
+ if (!dom) {
31
+ throw new Error("No DOM Element provided");
32
+ }
30
33
  this.shadowdom = dom.attachShadow({ mode: "closed" });
34
+ this.dom = dom;
35
+
31
36
  this.render();
32
37
 
33
38
  config.onready(this);
34
39
  };
35
40
 
41
+ private interactionChanged = () => {
42
+ const event: QtiInteractionChangedDetail = {
43
+ interaction: this,
44
+ responseIdentifier: this.config.responseIdentifier,
45
+ valid: true,
46
+ value: this.getResponse(),
47
+ };
48
+ // dispatch a custom event to notify the Delivery System that the interaction has changed
49
+ const interactionChangedEvent = new CustomEvent("qti-interaction-changed", {
50
+ detail: event,
51
+ });
52
+ this.dom.dispatchEvent(interactionChangedEvent);
53
+ };
54
+
36
55
  private render = () => {
37
56
  this.shadowdom.addEventListener("change", (e: Event) => {
38
57
  const value = (e.target as HTMLInputElement)?.value || "";
39
58
  this.state = value;
59
+ this.interactionChanged();
40
60
  });
41
61
  this.shadowdom.innerHTML = `<div class="pci-container">
42
62
  <h1>${this.config.properties.title}</h1>