@citolab/tspci 2.5.30-beta.6 → 2.5.30-beta.8
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 +19 -0
- package/package.json +2 -2
- package/preset/javascript/src/index.js +15 -0
- package/preset/preact/src/index.tsx +21 -4
- package/preset/typescript/src/index.ts +24 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
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.8](/compare/v2.5.30-beta.7...v2.5.30-beta.8) (2025-02-04)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @citolab/tspci
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [2.5.30-beta.7](/compare/v2.5.30-beta.6...v2.5.30-beta.7) (2025-02-04)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* dispatch qti-interaction-changed event 5c81bab
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## [2.5.30-beta.6](/compare/v2.5.30-beta.5...v2.5.30-beta.6) (2025-02-03)
|
|
7
26
|
|
|
8
27
|
**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.
|
|
3
|
+
"version": "2.5.30-beta.8",
|
|
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": "
|
|
54
|
+
"gitHead": "26a9950585cd816d7a7027cf4f0f8efb5cdedb1a"
|
|
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 {
|
|
7
|
+
import { ConfigProperties, IMSpci, QtiInteractionChangedDetail, QtiVariableJSON } from "@citolab/tspci";
|
|
8
8
|
import configProps from "./config.json";
|
|
9
9
|
import { StateModel, initStore } from "./store";
|
|
10
10
|
|
|
@@ -12,7 +12,7 @@ type PropTypes = typeof configProps;
|
|
|
12
12
|
|
|
13
13
|
class App implements IMSpci<PropTypes> {
|
|
14
14
|
typeIdentifier = "###___PCI_NAME___###"; // typeIdentifier is mandatory for all PCI's
|
|
15
|
-
config:
|
|
15
|
+
config: ConfigProperties<PropTypes>; // reference to the interface of the config object which you get when getInstance is called by the player
|
|
16
16
|
state: string; // keep a reference to the state
|
|
17
17
|
shadowdom: ShadowRoot; // Not mandatory, but its wise to create a shadowroot
|
|
18
18
|
store: IStore<StateModel>;
|
|
@@ -25,10 +25,12 @@ class App implements IMSpci<PropTypes> {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
getInstance = (dom: HTMLElement, config:
|
|
28
|
+
getInstance = (dom: HTMLElement, config: ConfigProperties<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 {
|
|
1
|
+
import { ConfigProperties, 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
|
|
@@ -10,9 +10,10 @@ type PropTypes = typeof configProps;
|
|
|
10
10
|
|
|
11
11
|
class Pci implements IMSpci<PropTypes> {
|
|
12
12
|
typeIdentifier = "###___PCI_NAME___###"; // typeIdentifier is mandatory for all PCI's
|
|
13
|
-
config:
|
|
13
|
+
config: ConfigProperties<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:
|
|
26
|
+
getInstance = (dom: HTMLElement, config: ConfigProperties<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>
|