@citolab/tspci 2.6.2 → 2.6.3-beta.1

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,30 @@
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.6.3-beta.1](/compare/v2.6.3-beta.0...v2.6.3-beta.1) (2025-04-14)
7
+
8
+ **Note:** Version bump only for package @citolab/tspci
9
+
10
+
11
+
12
+
13
+
14
+ ## [2.6.3-beta.0](/compare/v2.6.2...v2.6.3-beta.0) (2025-04-14)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * update tailwindcss version to 4.1.3 in package.json and package-lock.json 55c8ccb
20
+
21
+
22
+ ### Features
23
+
24
+ * implement setResponse method in PCI 1e4dffa
25
+
26
+
27
+
28
+
29
+
6
30
  ## [2.6.2](/compare/v2.6.1...v2.6.2) (2025-02-04)
7
31
 
8
32
  **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.6.2",
3
+ "version": "2.6.3-beta.1",
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",
@@ -46,10 +46,10 @@
46
46
  "rollup-plugin-node-globals": "^1.4.0",
47
47
  "rollup-plugin-postcss": "^4.0.2",
48
48
  "rollup-plugin-string": "^3.0.0",
49
- "tailwindcss": "^4.0.3"
49
+ "tailwindcss": "^4.1.3"
50
50
  },
51
51
  "resolutions": {
52
52
  "chokidar": "^4.0.0"
53
53
  },
54
- "gitHead": "750b04d92da7e806cbfafeb84dcb5bedb719536d"
54
+ "gitHead": "86cdeaf19f50955e56c729ea9fe96ab82d1df171"
55
55
  }
@@ -2,7 +2,6 @@ import * as ctx from "qtiCustomInteractionContext";
2
2
  import configProps from "./config.json";
3
3
  import style from "./styles.css"; // import and bundle this style file ( you can use tailwind and nested css )
4
4
  import procenten from "./assets/procenten.png"; // image types are bundled inside the js
5
-
6
5
  class Pci {
7
6
  /**
8
7
  * @constructor
@@ -41,6 +40,13 @@ class Pci {
41
40
 
42
41
  this.shadowdom = dom.attachShadow({ mode: "closed" });
43
42
  this.render();
43
+
44
+ if (this.config.boundTo && Object.keys(this.config.boundTo).length > 0) {
45
+ const responseIdentifier = Object.keys(this.config.boundTo)[0];
46
+ const response = this.config.boundTo[responseIdentifier];
47
+ this.setResponse(response);
48
+ }
49
+
44
50
  const event = {
45
51
  interaction: this,
46
52
  responseIdentifier: this.config.responseIdentifier,
@@ -68,6 +74,12 @@ class Pci {
68
74
  this.dom.dispatchEvent(interactionChangedEvent);
69
75
  };
70
76
 
77
+ setResponse = (response) => {
78
+ // TODO restore the response
79
+ // Get the actual value by the variable type like:
80
+ // - response?.base?.string or response?.base?.integer
81
+ }
82
+
71
83
  render = () => {
72
84
  this.shadowdom.addEventListener("change", (e) => {
73
85
  const value = e.target.value;
@@ -108,6 +120,21 @@ class Pci {
108
120
  */
109
121
  getState = () => this.state.toString();
110
122
 
123
+
124
+ /**
125
+ * @method resetResponse
126
+ * @description Can set the response to a previously stored state.
127
+ * Also a way in TAO to show the correct response in the score-editor.
128
+ * @param {QtiVariableJSON} response - The response to set.
129
+ * @returns {void}
130
+ * @example
131
+ * const response = {
132
+ * base: {
133
+ * integer: 100
134
+ * }
135
+ * };
136
+ */
137
+ setResponse = (response) => { }
111
138
  /**
112
139
  * @method oncompleted
113
140
  * @description called when the PCI is completed.
@@ -60,6 +60,12 @@ class App implements IMSpci<PropTypes> {
60
60
 
61
61
  this.render();
62
62
 
63
+ if (this.config.boundTo && Object.keys(this.config.boundTo).length > 0) {
64
+ const responseIdentifier = Object.keys(this.config.boundTo)[0];
65
+ const response = this.config.boundTo[responseIdentifier];
66
+ this.setResponse(response);
67
+ }
68
+
63
69
  if (this.config.onready) {
64
70
  this.config.onready(this);
65
71
  }
@@ -73,6 +79,13 @@ class App implements IMSpci<PropTypes> {
73
79
  render(<Interaction config={this.config.properties} dom={this.shadowdom} store={this.store} />, this.shadowdom);
74
80
  };
75
81
 
82
+ setResponse = (response: QtiVariableJSON) => {
83
+ // TODO restore the response
84
+ // Get the actual value by the variable type like:
85
+ // - response?.base?.string or response?.base?.integer
86
+ }
87
+
88
+
76
89
  getState = () =>
77
90
  JSON.stringify({
78
91
  state: this.store.getState(),
@@ -25,7 +25,7 @@ class Pci implements IMSpci<PropTypes> {
25
25
  // config is the configuration object which has an onready
26
26
  getInstance = (dom: HTMLElement, config: ConfigProperties<PropTypes>, state: string) => {
27
27
  config.properties = { ...configProps, ...config.properties }; // merge current props with incoming
28
- this.config = config;
28
+ this.config = config;
29
29
  this.state = state ? state : "";
30
30
  if (!dom) {
31
31
  throw new Error("No DOM Element provided");
@@ -35,9 +35,21 @@ class Pci implements IMSpci<PropTypes> {
35
35
 
36
36
  this.render();
37
37
 
38
+ if (this.config.boundTo && Object.keys(this.config.boundTo).length > 0) {
39
+ const responseIdentifier = Object.keys(this.config.boundTo)[0];
40
+ const response = this.config.boundTo[responseIdentifier];
41
+ this.setResponse(response);
42
+ }
43
+
38
44
  config.onready(this);
39
45
  };
40
46
 
47
+ setResponse = (response: QtiVariableJSON) => {
48
+ // TODO restore the response
49
+ // Get the actual value by the variable type like:
50
+ // - response?.base?.string or response?.base?.integer
51
+ }
52
+
41
53
  private interactionChanged = () => {
42
54
  const event: QtiInteractionChangedDetail = {
43
55
  interaction: this,
package/readme.md CHANGED
@@ -123,6 +123,10 @@ class Pci implements IMSpci<{}> {
123
123
  };
124
124
 
125
125
  getState = () => null;
126
+
127
+ setResponse = () => {
128
+
129
+ }
126
130
  }
127
131
  export default new Pci();
128
132
  ```
package/types/index.d.ts CHANGED
@@ -52,6 +52,7 @@ export interface IMSpci<T> {
52
52
  */
53
53
  getState: () => string;
54
54
  oncompleted?: () => void;
55
+ setResponse?: (response: QtiVariableJSON) => void; // No IMS specification for this, but best option to set the response when bound to a QTI variable
55
56
  destroy?: () => void; // Not used in IMS and not in TAO implementation, so not used here (optional)
56
57
  }
57
58
 
@@ -74,14 +75,8 @@ export interface InputResponseFormat<T> {
74
75
  export interface Calculate {
75
76
  calculate: () => ResponseType;
76
77
  }
77
- export declare type QtiVariableJSON = {
78
- [K in "list" | "base"]?: {
79
- [Ka in "boolean" | "integer" | "float" | "string" | "pair" | "directedPair" | "identifier"]?: ResponseType;
80
- };
81
- };
82
78
  export declare type float = number;
83
79
  export declare type integer = number;
84
- export declare type ResponseType = boolean | directedPair | float | integer | string | ResponseType[];
85
80
  export declare enum BaseType {
86
81
  boolean = "boolean",
87
82
  directedPair = "directedPair",
@@ -96,3 +91,82 @@ export declare enum Cardinality {
96
91
  ordered = "ordered",
97
92
  single = "single",
98
93
  }
94
+
95
+ // Individual type definitions for different QTI data types
96
+
97
+ // File type representation
98
+ export type QtiFileData = {
99
+ data: string;
100
+ mime: string;
101
+ name?: string;
102
+ };
103
+
104
+ // Possible base types
105
+ export type QtiBaseBoolean = boolean;
106
+ export type QtiBaseInteger = number;
107
+ export type QtiBaseFloat = number;
108
+ export type QtiBaseString = string;
109
+ export type QtiBasePoint = [number, number];
110
+ export type QtiBasePair = [string, string];
111
+ export type QtiBaseDirectedPair = [string, string];
112
+ export type QtiBaseDuration = string; // ISO 8601 duration format
113
+ export type QtiBaseFile = QtiFileData;
114
+ export type QtiBaseUri = string;
115
+ export type QtiBaseIntOrIdentifier = number | string;
116
+ export type QtiBaseIdentifier = string;
117
+
118
+ // Union of all possible response types for base and list
119
+ export type ResponseType =
120
+ boolean |
121
+ number |
122
+ string |
123
+ QtiBasePair |
124
+ QtiBasePoint |
125
+ QtiFileData |
126
+ Array<boolean | number | string | QtiBasePair | QtiBasePoint | QtiFileData>;
127
+
128
+ // Record item type
129
+ export type QtiRecordItem = {
130
+ name: string;
131
+ base?: QtiBaseTypeJSON | null;
132
+ list?: QtiListTypeJSON | null;
133
+ };
134
+
135
+ // Base type JSON representation
136
+ export type QtiBaseTypeJSON = {
137
+ boolean?: QtiBaseBoolean;
138
+ integer?: QtiBaseInteger;
139
+ float?: QtiBaseFloat;
140
+ string?: QtiBaseString;
141
+ point?: QtiBasePoint;
142
+ pair?: QtiBasePair;
143
+ directedPair?: QtiBaseDirectedPair;
144
+ duration?: QtiBaseDuration;
145
+ file?: QtiBaseFile;
146
+ uri?: QtiBaseUri;
147
+ intOrIdentifier?: QtiBaseIntOrIdentifier;
148
+ identifier?: QtiBaseIdentifier;
149
+ } | null;
150
+
151
+ // List type JSON representation
152
+ export type QtiListTypeJSON = {
153
+ boolean?: QtiBaseBoolean[];
154
+ integer?: QtiBaseInteger[];
155
+ float?: QtiBaseFloat[];
156
+ string?: QtiBaseString[];
157
+ point?: QtiBasePoint[];
158
+ pair?: QtiBasePair[];
159
+ directedPair?: QtiBaseDirectedPair[];
160
+ duration?: QtiBaseDuration[];
161
+ file?: QtiBaseFile[];
162
+ uri?: QtiBaseUri[];
163
+ intOrIdentifier?: QtiBaseIntOrIdentifier[];
164
+ identifier?: QtiBaseIdentifier[];
165
+ } | null;
166
+
167
+ // Complete QTI Variable JSON type
168
+ export declare type QtiVariableJSON = {
169
+ base?: QtiBaseTypeJSON;
170
+ list?: QtiListTypeJSON;
171
+ record?: QtiRecordItem[] | null;
172
+ };