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