@citolab/tspci-qbci 2.4.3 → 2.4.6
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/package.json +2 -2
- package/public/index.html +76 -18
- package/questify-default/metadata.json +6 -6
- package/src/createPackage.mjs +10 -16
- package/types/index.d.ts +5 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@citolab/tspci-qbci",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.6",
|
|
4
4
|
"description": "create a .ci file that can be imported into Questify",
|
|
5
5
|
"author": "patrick <patrick.deklein@cito.nl>, Marcel Hoekstra <marcel.hoekstra@cito.nl>",
|
|
6
6
|
"repository": "",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"archiver": "^5.3.0"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {},
|
|
13
|
-
"gitHead": "
|
|
13
|
+
"gitHead": "ad870b11096e4c5d5b151143569c3bee51a12fc6",
|
|
14
14
|
"publishConfig": {
|
|
15
15
|
"access": "public"
|
|
16
16
|
}
|
package/public/index.html
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
font-size: 100%;
|
|
19
19
|
}
|
|
20
20
|
#pciContainer {
|
|
21
|
-
display:block;
|
|
21
|
+
display: block;
|
|
22
22
|
width: 100%;
|
|
23
23
|
/* min-width: 800px; */
|
|
24
24
|
padding: 20px;
|
|
@@ -41,20 +41,28 @@
|
|
|
41
41
|
</head>
|
|
42
42
|
<body class="bg-light">
|
|
43
43
|
<div class="container">
|
|
44
|
-
<
|
|
44
|
+
<div id="pciContainer" class="shadow-sm"></div>
|
|
45
45
|
<div id="devtools"></div>
|
|
46
46
|
</div>
|
|
47
47
|
|
|
48
48
|
<script type="module">
|
|
49
49
|
import { h, Component, render } from "https://unpkg.com/preact@latest?module";
|
|
50
|
-
import { useState, useEffect } from "https://unpkg.com/preact@latest/hooks/dist/hooks.module.js?module";
|
|
50
|
+
import { useState, useEffect, useRef } from "https://unpkg.com/preact@latest/hooks/dist/hooks.module.js?module";
|
|
51
51
|
import htm from "https://unpkg.com/htm?module";
|
|
52
52
|
// Initialize htm with Preact
|
|
53
53
|
const html = htm.bind(h);
|
|
54
54
|
|
|
55
|
-
function App() {
|
|
55
|
+
function App({ item }) {
|
|
56
56
|
const [show, setShow] = useState(false);
|
|
57
57
|
|
|
58
|
+
let keyArray = [];
|
|
59
|
+
if (item.config && item.config.properties) {
|
|
60
|
+
keyArray = Object.keys(item.config.properties).map((keyName, keyIndex) => ({
|
|
61
|
+
key: keyName,
|
|
62
|
+
value: item.config.properties[keyName],
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
|
|
58
66
|
function resetlocalstorage() {
|
|
59
67
|
localStorage.removeItem(item.typeIdentifier + "_props");
|
|
60
68
|
localStorage.removeItem(item.typeIdentifier + "_response");
|
|
@@ -68,7 +76,7 @@
|
|
|
68
76
|
|
|
69
77
|
function changeConfig(key, value) {
|
|
70
78
|
item.config.properties[key] = value;
|
|
71
|
-
item.trigger(`change${key}`, value);
|
|
79
|
+
item.trigger && item.trigger(`change${key}`, value);
|
|
72
80
|
}
|
|
73
81
|
|
|
74
82
|
function reConfig(key, value) {
|
|
@@ -78,9 +86,46 @@
|
|
|
78
86
|
|
|
79
87
|
return html`
|
|
80
88
|
<div>
|
|
89
|
+
<div style="width:300px" class="shadow offcanvas offcanvas-end ${show ? "show visible" : ""}">
|
|
90
|
+
<div class="offcanvas-header">
|
|
91
|
+
<h5 class="offcanvas-title" id="offcanvasExampleLabel">properties</h5>
|
|
92
|
+
<button
|
|
93
|
+
type="button"
|
|
94
|
+
onClick="${() => setShow(false)}"
|
|
95
|
+
disabled="${!item.config}"
|
|
96
|
+
class="btn-close text-reset"
|
|
97
|
+
></button>
|
|
98
|
+
</div>
|
|
99
|
+
<div class="offcanvas-body">
|
|
100
|
+
<ul class="card-body">
|
|
101
|
+
${keyArray.map(
|
|
102
|
+
({ key, value }) => html`<div>
|
|
103
|
+
<div>${key}</div>
|
|
104
|
+
<input
|
|
105
|
+
type="text"
|
|
106
|
+
class="form-control"
|
|
107
|
+
value="${value}"
|
|
108
|
+
onkeyup="${(e) => changeConfig(key, e.target.value)}"
|
|
109
|
+
/>
|
|
110
|
+
</div>`
|
|
111
|
+
)}
|
|
112
|
+
</ul>
|
|
113
|
+
<button class="btn btn-primary" onClick="${() => reConfig()}">save and reload</button>
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
|
|
81
117
|
<div class="d-flex justify-content-start mt-3" role="toolbar" aria-label="Toolbar with button groups">
|
|
82
|
-
<div class="
|
|
83
|
-
<
|
|
118
|
+
<div class="d-flex flex-column">
|
|
119
|
+
<small class="text-muted">configuration</small>
|
|
120
|
+
<div class="btn-group me-2 shadow-sm" role="group" aria-label="Basic checkbox toggle button group">
|
|
121
|
+
<button class="btn btn-outline-secondary" onClick="${() => setShow(true)}">config</button>
|
|
122
|
+
</div>
|
|
123
|
+
</div>
|
|
124
|
+
<div class="d-flex flex-column">
|
|
125
|
+
<small class="text-muted">state</small>
|
|
126
|
+
<div class="btn-group me-2 shadow-sm" role="group" aria-label="Basic checkbox toggle button group">
|
|
127
|
+
<button class="btn btn-outline-secondary" onClick="${() => reload()}">reload</button>
|
|
128
|
+
</div>
|
|
84
129
|
</div>
|
|
85
130
|
</div>
|
|
86
131
|
</div>
|
|
@@ -96,25 +141,38 @@
|
|
|
96
141
|
window["CES"] = {
|
|
97
142
|
response: response,
|
|
98
143
|
setResponse: (data) => {
|
|
99
|
-
console.log("setting the data", data)
|
|
144
|
+
console.log("setting the data", data);
|
|
100
145
|
response = data;
|
|
101
146
|
},
|
|
102
|
-
getResponse: () => {
|
|
147
|
+
getResponse: (itemInstance = null) => {
|
|
103
148
|
console.log("getting the data");
|
|
104
149
|
return response;
|
|
105
150
|
},
|
|
106
151
|
};
|
|
107
|
-
var iframe = document.getElementById("pciContainer"),
|
|
108
|
-
iframeWin = iframe.contentWindow || iframe,
|
|
109
|
-
iframeDoc = iframe.contentDocument || iframeWin.document;
|
|
110
152
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
153
|
+
const pciContainer = document.getElementById("pciContainer");
|
|
154
|
+
|
|
155
|
+
define("qtiCustomInteractionContext", (qtiCustomInteractionContext) => {
|
|
156
|
+
// return { register: (ctxA) => register(ctxA) };
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
function loadItem() {
|
|
160
|
+
requirejs(["index.js"], (itemInstance) => {
|
|
161
|
+
render(html`<${App} item="${new itemInstance.App(pciContainer)}" />`, document.getElementById("devtools"));
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
window.onload = loadItem;
|
|
166
|
+
|
|
167
|
+
// if (itemInstance) render(html`<${App} item="${itemInstance}" />`, document.getElementById("devtools"));
|
|
168
|
+
|
|
169
|
+
// const iframe = pciContainer;
|
|
170
|
+
// const iframeWin = iframe.contentWindow || iframe;
|
|
171
|
+
// const iframeDoc = iframe.contentDocument || iframeWin.document;
|
|
114
172
|
|
|
115
|
-
iframeDoc.open();
|
|
116
|
-
iframeDoc.write("\<html>\<head>\<script src='index.js'>\<\/script>\<\/head>\<body>\<\/body>\<\/html>");
|
|
117
|
-
iframeDoc.close();
|
|
173
|
+
// iframeDoc.open();
|
|
174
|
+
// iframeDoc.write("\<html>\<head>\<script src='index.js'>\<\/script>\<\/head>\<body>\<\/body>\<\/html>");
|
|
175
|
+
// iframeDoc.close();
|
|
118
176
|
|
|
119
177
|
localStorage.removeItem("ci_response");
|
|
120
178
|
</script>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
2
|
+
"title": "###___title___###",
|
|
3
|
+
"typeIdentifier": "###___typeIdentifier___###",
|
|
4
|
+
"width": 500,
|
|
5
|
+
"height": 500,
|
|
6
|
+
"scalable": true
|
|
7
|
+
}
|
package/src/createPackage.mjs
CHANGED
|
@@ -30,34 +30,28 @@ export const bundle = () => {
|
|
|
30
30
|
const rawConfigData = fs.readFileSync(config);
|
|
31
31
|
const packageData = JSON.parse(rawConfigData);
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
// PACKAGE_ROOT_PATH
|
|
34
|
+
let questifyMetadata = path.join(PACKAGE_ROOT_PATH, "metadata.json");
|
|
35
|
+
if (!fs.existsSync(questifyMetadata)) {
|
|
35
36
|
console.error(`cannot find metadata.json: ${questifyMetadata}`);
|
|
36
|
-
|
|
37
|
+
questifyMetadata = path.join(path.join(PACKAGER_PATH, "questify-default"), "metadata.json");
|
|
37
38
|
}
|
|
39
|
+
|
|
38
40
|
const rawMetadata = fs.readFileSync(questifyMetadata);
|
|
39
41
|
const questifyMetadataData = JSON.parse(rawMetadata);
|
|
40
42
|
|
|
41
43
|
const propertiesToReplace = {
|
|
42
|
-
typeIdentifier: "emptytypeIdentifier"
|
|
43
|
-
width: "500",
|
|
44
|
-
height: "500",
|
|
44
|
+
typeIdentifier: "emptytypeIdentifier"
|
|
45
45
|
};
|
|
46
46
|
copyDirectoryRecursiveSync(path.join(PACKAGER_PATH, "questify-default"), outputDirectoryTemp, false);
|
|
47
47
|
|
|
48
48
|
const name = packageData.label
|
|
49
49
|
? packageData.label
|
|
50
50
|
: packageData.name
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
? packageData.name.split("/")[packageData.name.split("/").length - 1]
|
|
52
|
+
: "ci";
|
|
53
53
|
|
|
54
54
|
for (const propertyName in propertiesToReplace) {
|
|
55
|
-
if (!packageData.config?.tspci[propertyName]) {
|
|
56
|
-
console.error(
|
|
57
|
-
"'typeIdentifier' should be added as an option in package.json and should match the typeIdentifier of the PCI code file."
|
|
58
|
-
);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
55
|
if (propertyName === "typeIdentifier") {
|
|
62
56
|
if (!packageData.config?.tspci[propertyName]) {
|
|
63
57
|
console.error(
|
|
@@ -71,12 +65,12 @@ export const bundle = () => {
|
|
|
71
65
|
);
|
|
72
66
|
}
|
|
73
67
|
}
|
|
74
|
-
if (
|
|
68
|
+
if (packageData.config.tspci[propertyName]) {
|
|
75
69
|
propertiesToReplace[propertyName] = packageData.config.tspci[propertyName];
|
|
76
70
|
}
|
|
77
71
|
}
|
|
78
72
|
|
|
79
|
-
for(const propertyName in propertiesToReplace) {
|
|
73
|
+
for (const propertyName in propertiesToReplace) {
|
|
80
74
|
questifyMetadataData[propertyName] = propertiesToReplace[propertyName];
|
|
81
75
|
}
|
|
82
76
|
|
package/types/index.d.ts
CHANGED
|
@@ -20,12 +20,12 @@ export interface CES {
|
|
|
20
20
|
// */
|
|
21
21
|
// getMedia: () => [];
|
|
22
22
|
|
|
23
|
-
// /**
|
|
23
|
+
// /**
|
|
24
24
|
// * @access public
|
|
25
25
|
// * @deprecated not really deprecated, but bundled ci does not contain media ever again
|
|
26
|
-
// * Convenience function to adjust the height of the generated iframe
|
|
26
|
+
// * Convenience function to adjust the height of the generated iframe
|
|
27
27
|
// * to the current height of the custom interaction’s content height;
|
|
28
|
-
// * if that content’s visual size exceeds its layout box (e.g. by using box-shadow),
|
|
28
|
+
// * if that content’s visual size exceeds its layout box (e.g. by using box-shadow),
|
|
29
29
|
// * an optional vertical margin can be specified.
|
|
30
30
|
// * @method setStageHeight
|
|
31
31
|
// * @arg NumberverticalMargin
|
|
@@ -46,9 +46,9 @@ export interface CI<ConfigProperties> {
|
|
|
46
46
|
* This must have been obtained from a prior call to getState on an
|
|
47
47
|
* instance of this type (same typeIdentifier)
|
|
48
48
|
*/
|
|
49
|
-
|
|
49
|
+
getInstance: (dom: HTMLElement, configuration: Configuration<ConfigProperties>, state: string) => void;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export declare type Configuration<T> = {
|
|
53
53
|
properties: T;
|
|
54
|
-
};
|
|
54
|
+
};
|