@enspiredigital/xlms-headless 0.0.7 → 0.0.9
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBaseQuestion.d.ts","sourceRoot":"","sources":["../../src/hooks/useBaseQuestion.ts"],"names":[],"mappings":"AAEA,wBAAgB,eAAe;;;;;gCAKM,OAAO;;
|
|
1
|
+
{"version":3,"file":"useBaseQuestion.d.ts","sourceRoot":"","sources":["../../src/hooks/useBaseQuestion.ts"],"names":[],"mappings":"AAEA,wBAAgB,eAAe;;;;;gCAKM,OAAO;;EAwB3C"}
|
|
@@ -11,7 +11,7 @@ export declare function useMatching(question: MatchingQuestionType): {
|
|
|
11
11
|
attempts: number;
|
|
12
12
|
canAnswer: boolean;
|
|
13
13
|
select: (targetId: string, sourceId: string) => void;
|
|
14
|
-
remove: (
|
|
14
|
+
remove: (targetId: string, sourceId: string) => void;
|
|
15
15
|
submit: () => {
|
|
16
16
|
isCorrect: boolean;
|
|
17
17
|
score: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMatching.d.ts","sourceRoot":"","sources":["../../src/hooks/useMatching.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,cAAc,EACf,MAAM,UAAU,CAAC;AAElB,wBAAgB,WAAW,CAAC,QAAQ,EAAE,oBAAoB;;;;;;;;;;;uBAkB9B,MAAM,YAAY,MAAM;
|
|
1
|
+
{"version":3,"file":"useMatching.d.ts","sourceRoot":"","sources":["../../src/hooks/useMatching.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,cAAc,EACf,MAAM,UAAU,CAAC;AAElB,wBAAgB,WAAW,CAAC,QAAQ,EAAE,oBAAoB;;;;;;;;;;;uBAkB9B,MAAM,YAAY,MAAM;uBAaxB,MAAM,YAAY,MAAM;;;;;;;EAoFnD"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { useState as
|
|
1
|
+
import { useState as C, useEffect as B } from "react";
|
|
2
2
|
function S() {
|
|
3
|
-
const [t, e] =
|
|
4
|
-
function
|
|
5
|
-
|
|
3
|
+
const [t, e] = C(null), [s, i] = C(null), [a, g] = C(0);
|
|
4
|
+
function w(c) {
|
|
5
|
+
e(!0), i(c), g((A) => A + 1);
|
|
6
6
|
}
|
|
7
7
|
function r() {
|
|
8
|
-
e(!1),
|
|
8
|
+
e(!1), i(null);
|
|
9
9
|
}
|
|
10
10
|
return {
|
|
11
11
|
// state
|
|
@@ -15,29 +15,29 @@ function S() {
|
|
|
15
15
|
// derived
|
|
16
16
|
canAnswer: !t,
|
|
17
17
|
// actions
|
|
18
|
-
submitQuestion:
|
|
18
|
+
submitQuestion: w,
|
|
19
19
|
resetQuestion: r
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
function k(t, e) {
|
|
23
23
|
if (t.length !== e.length) return !1;
|
|
24
|
-
const s = new Set(t),
|
|
25
|
-
if (s.size !==
|
|
24
|
+
const s = new Set(t), i = new Set(e);
|
|
25
|
+
if (s.size !== i.size) return !1;
|
|
26
26
|
for (const a of s)
|
|
27
|
-
if (!
|
|
27
|
+
if (!i.has(a)) return !1;
|
|
28
28
|
return !0;
|
|
29
29
|
}
|
|
30
30
|
function V(t) {
|
|
31
31
|
const {
|
|
32
32
|
canAnswer: e,
|
|
33
33
|
submitted: s,
|
|
34
|
-
isCorrect:
|
|
34
|
+
isCorrect: i,
|
|
35
35
|
attempts: a,
|
|
36
|
-
resetQuestion:
|
|
37
|
-
submitQuestion:
|
|
38
|
-
} = S(), [r,
|
|
39
|
-
function
|
|
40
|
-
|
|
36
|
+
resetQuestion: g,
|
|
37
|
+
submitQuestion: w
|
|
38
|
+
} = S(), [r, c] = C([]);
|
|
39
|
+
function A(d) {
|
|
40
|
+
c((n) => t.options.allowMultipleAnswers ? n.includes(d) ? n.filter((l) => l !== d) : [...n, d] : [d]);
|
|
41
41
|
}
|
|
42
42
|
function h() {
|
|
43
43
|
if (r.length === 0) return;
|
|
@@ -45,22 +45,22 @@ function V(t) {
|
|
|
45
45
|
(l, f) => (f.is_correct && l.push(f.id), l),
|
|
46
46
|
[]
|
|
47
47
|
), n = k(r, d);
|
|
48
|
-
|
|
48
|
+
w(n);
|
|
49
49
|
}
|
|
50
50
|
function I() {
|
|
51
|
-
|
|
51
|
+
c([]), g();
|
|
52
52
|
}
|
|
53
53
|
return {
|
|
54
54
|
// data
|
|
55
55
|
question: t,
|
|
56
56
|
selectedIds: r,
|
|
57
57
|
// actions
|
|
58
|
-
select:
|
|
58
|
+
select: A,
|
|
59
59
|
submit: h,
|
|
60
60
|
reset: I,
|
|
61
61
|
// base
|
|
62
62
|
submitted: s,
|
|
63
|
-
isCorrect:
|
|
63
|
+
isCorrect: i,
|
|
64
64
|
attempts: a,
|
|
65
65
|
canAnswer: e
|
|
66
66
|
};
|
|
@@ -69,57 +69,57 @@ function v(t) {
|
|
|
69
69
|
const {
|
|
70
70
|
canAnswer: e,
|
|
71
71
|
submitted: s,
|
|
72
|
-
isCorrect:
|
|
72
|
+
isCorrect: i,
|
|
73
73
|
attempts: a,
|
|
74
|
-
submitQuestion:
|
|
75
|
-
resetQuestion:
|
|
76
|
-
} = S(), [r,
|
|
74
|
+
submitQuestion: g,
|
|
75
|
+
resetQuestion: w
|
|
76
|
+
} = S(), [r, c] = C([]), [A, h] = C(
|
|
77
77
|
[]
|
|
78
|
-
), [I, d] =
|
|
78
|
+
), [I, d] = C(
|
|
79
79
|
[]
|
|
80
80
|
);
|
|
81
81
|
function n(o, m) {
|
|
82
|
-
|
|
83
|
-
...
|
|
84
|
-
(
|
|
82
|
+
c((u) => [
|
|
83
|
+
...u.filter(
|
|
84
|
+
(p) => p.targetId !== o && p.sourceId !== m
|
|
85
85
|
),
|
|
86
86
|
{ targetId: o, sourceId: m }
|
|
87
87
|
]);
|
|
88
88
|
}
|
|
89
|
-
function l(o) {
|
|
90
|
-
|
|
91
|
-
(
|
|
89
|
+
function l(o, m) {
|
|
90
|
+
c(
|
|
91
|
+
(u) => u.filter((p) => p.targetId !== o || p.sourceId !== m)
|
|
92
92
|
);
|
|
93
93
|
}
|
|
94
94
|
function f() {
|
|
95
95
|
let o = 0, m = !0;
|
|
96
|
-
return t.options.targets.forEach((
|
|
97
|
-
const
|
|
98
|
-
|
|
96
|
+
return t.options.targets.forEach((u) => {
|
|
97
|
+
const p = r.find((M) => M.targetId === u.id), x = t.options.sources[u.content.correct_position - 1];
|
|
98
|
+
p && x && p.sourceId === x.id ? o += u.content.point : m = !1;
|
|
99
99
|
}), {
|
|
100
100
|
isCorrect: m,
|
|
101
101
|
score: o,
|
|
102
102
|
maxScore: t.options.targets.reduce(
|
|
103
|
-
(
|
|
103
|
+
(u, p) => u + p.content.point,
|
|
104
104
|
0
|
|
105
105
|
)
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
108
|
function Q() {
|
|
109
109
|
const o = f();
|
|
110
|
-
return
|
|
110
|
+
return g(o.isCorrect), o;
|
|
111
111
|
}
|
|
112
|
-
function
|
|
113
|
-
|
|
112
|
+
function b() {
|
|
113
|
+
c([]), w();
|
|
114
114
|
}
|
|
115
115
|
return B(() => {
|
|
116
116
|
const o = t.options.sources.filter(
|
|
117
|
-
(m) => !r.some((
|
|
117
|
+
(m) => !r.some((u) => u.sourceId === m.id)
|
|
118
118
|
);
|
|
119
119
|
h(o);
|
|
120
120
|
}, [r, t.options.sources]), B(() => {
|
|
121
121
|
const o = t.options.targets.filter(
|
|
122
|
-
(m) => !r.some((
|
|
122
|
+
(m) => !r.some((u) => u.targetId === m.id)
|
|
123
123
|
);
|
|
124
124
|
d(o);
|
|
125
125
|
}, [r, t.options.targets]), {
|
|
@@ -128,34 +128,34 @@ function v(t) {
|
|
|
128
128
|
targets: t.options.targets,
|
|
129
129
|
answers: r,
|
|
130
130
|
question: t,
|
|
131
|
-
availableSources:
|
|
131
|
+
availableSources: A,
|
|
132
132
|
availableTargets: I,
|
|
133
133
|
// base
|
|
134
134
|
submitted: s,
|
|
135
|
-
isCorrect:
|
|
135
|
+
isCorrect: i,
|
|
136
136
|
attempts: a,
|
|
137
137
|
canAnswer: e,
|
|
138
138
|
// actions
|
|
139
139
|
select: n,
|
|
140
140
|
remove: l,
|
|
141
141
|
submit: Q,
|
|
142
|
-
reset:
|
|
142
|
+
reset: b
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
145
|
function T(t) {
|
|
146
146
|
const {
|
|
147
147
|
canAnswer: e,
|
|
148
148
|
submitted: s,
|
|
149
|
-
isCorrect:
|
|
149
|
+
isCorrect: i,
|
|
150
150
|
attempts: a,
|
|
151
|
-
resetQuestion:
|
|
152
|
-
submitQuestion:
|
|
151
|
+
resetQuestion: g,
|
|
152
|
+
submitQuestion: w
|
|
153
153
|
} = S();
|
|
154
154
|
function r() {
|
|
155
|
-
|
|
155
|
+
w(!0);
|
|
156
156
|
}
|
|
157
|
-
function
|
|
158
|
-
|
|
157
|
+
function c() {
|
|
158
|
+
g();
|
|
159
159
|
}
|
|
160
160
|
return {
|
|
161
161
|
// data
|
|
@@ -164,10 +164,10 @@ function T(t) {
|
|
|
164
164
|
type: t.options.urlType,
|
|
165
165
|
// actions
|
|
166
166
|
submit: r,
|
|
167
|
-
reset:
|
|
167
|
+
reset: c,
|
|
168
168
|
// base
|
|
169
169
|
submitted: s,
|
|
170
|
-
isCorrect:
|
|
170
|
+
isCorrect: i,
|
|
171
171
|
attempts: a,
|
|
172
172
|
canAnswer: e
|
|
173
173
|
};
|
|
@@ -176,17 +176,17 @@ function _(t) {
|
|
|
176
176
|
const {
|
|
177
177
|
canAnswer: e,
|
|
178
178
|
submitted: s,
|
|
179
|
-
isCorrect:
|
|
179
|
+
isCorrect: i,
|
|
180
180
|
attempts: a,
|
|
181
|
-
submitQuestion:
|
|
182
|
-
resetQuestion:
|
|
183
|
-
} = S(), [r,
|
|
184
|
-
function
|
|
185
|
-
e &&
|
|
186
|
-
const Q = f.findIndex((
|
|
181
|
+
submitQuestion: g,
|
|
182
|
+
resetQuestion: w
|
|
183
|
+
} = S(), [r, c] = C([]);
|
|
184
|
+
function A(n, l) {
|
|
185
|
+
e && c((f) => {
|
|
186
|
+
const Q = f.findIndex((b) => b.targetId === n);
|
|
187
187
|
if (Q >= 0) {
|
|
188
|
-
const
|
|
189
|
-
return
|
|
188
|
+
const b = [...f];
|
|
189
|
+
return b[Q] = { targetId: n, value: l }, b;
|
|
190
190
|
}
|
|
191
191
|
return [...f, { targetId: n, value: l }];
|
|
192
192
|
});
|
|
@@ -197,8 +197,8 @@ function _(t) {
|
|
|
197
197
|
n = !1;
|
|
198
198
|
else
|
|
199
199
|
for (const l of t.options.targets) {
|
|
200
|
-
const f = r.find((o) => o.targetId === l.id), Q = f ? f.value.trim() : "",
|
|
201
|
-
if (Q.toLowerCase() !==
|
|
200
|
+
const f = r.find((o) => o.targetId === l.id), Q = f ? f.value.trim() : "", b = l.content.correct_answer.trim();
|
|
201
|
+
if (Q.toLowerCase() !== b.toLowerCase()) {
|
|
202
202
|
n = !1;
|
|
203
203
|
break;
|
|
204
204
|
}
|
|
@@ -211,10 +211,10 @@ function _(t) {
|
|
|
211
211
|
}
|
|
212
212
|
function I() {
|
|
213
213
|
const n = h();
|
|
214
|
-
return
|
|
214
|
+
return g(n.isCorrect), n;
|
|
215
215
|
}
|
|
216
216
|
function d() {
|
|
217
|
-
|
|
217
|
+
c([]), w();
|
|
218
218
|
}
|
|
219
219
|
return {
|
|
220
220
|
// data
|
|
@@ -223,11 +223,11 @@ function _(t) {
|
|
|
223
223
|
question: t,
|
|
224
224
|
// base
|
|
225
225
|
submitted: s,
|
|
226
|
-
isCorrect:
|
|
226
|
+
isCorrect: i,
|
|
227
227
|
attempts: a,
|
|
228
228
|
canAnswer: e,
|
|
229
229
|
// actions
|
|
230
|
-
answer:
|
|
230
|
+
answer: A,
|
|
231
231
|
submit: I,
|
|
232
232
|
reset: d
|
|
233
233
|
};
|