@enspiredigital/xlms-headless 0.0.4 → 0.0.5
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 +3 -2
- package/dist/hooks/useMatching.d.ts.map +1 -1
- package/dist/index.js +115 -107
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { MatchingAnswer, MatchingQuestionType, MatchingSource } from '../types';
|
|
1
|
+
import { MatchingAnswer, MatchingQuestionType, MatchingSource, MatchingTarget } from '../types';
|
|
2
2
|
export declare function useMatching(question: MatchingQuestionType): {
|
|
3
3
|
sources: MatchingSource[];
|
|
4
|
-
targets:
|
|
4
|
+
targets: MatchingTarget[];
|
|
5
5
|
answers: MatchingAnswer[];
|
|
6
6
|
question: MatchingQuestionType;
|
|
7
7
|
availableSources: MatchingSource[];
|
|
8
|
+
availableTargets: MatchingTarget[];
|
|
8
9
|
submitted: boolean | null;
|
|
9
10
|
isCorrect: boolean | null;
|
|
10
11
|
attempts: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMatching.d.ts","sourceRoot":"","sources":["../../src/hooks/useMatching.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
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;;;;;;;EAkFjC"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { useState as b, useEffect as
|
|
2
|
-
function
|
|
3
|
-
const [t, e] = b(null), [s,
|
|
4
|
-
function
|
|
5
|
-
t || (e(!0), c
|
|
1
|
+
import { useState as b, useEffect as B } from "react";
|
|
2
|
+
function S() {
|
|
3
|
+
const [t, e] = b(null), [s, i] = b(null), [a, p] = b(0);
|
|
4
|
+
function g(c) {
|
|
5
|
+
t || (e(!0), i(c), p((C) => C + 1));
|
|
6
6
|
}
|
|
7
|
-
function
|
|
8
|
-
e(!1),
|
|
7
|
+
function r() {
|
|
8
|
+
e(!1), i(null);
|
|
9
9
|
}
|
|
10
10
|
return {
|
|
11
11
|
// state
|
|
@@ -15,136 +15,144 @@ function h() {
|
|
|
15
15
|
// derived
|
|
16
16
|
canAnswer: !t,
|
|
17
17
|
// actions
|
|
18
|
-
submitQuestion:
|
|
19
|
-
resetQuestion:
|
|
18
|
+
submitQuestion: g,
|
|
19
|
+
resetQuestion: r
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
function
|
|
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
|
-
function
|
|
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
36
|
resetQuestion: p,
|
|
37
|
-
submitQuestion:
|
|
38
|
-
} =
|
|
39
|
-
function
|
|
40
|
-
|
|
37
|
+
submitQuestion: g
|
|
38
|
+
} = S(), [r, c] = b([]);
|
|
39
|
+
function C(d) {
|
|
40
|
+
c((n) => t.options.allowMultipleAnswers ? n.includes(d) ? n.filter((l) => l !== d) : [...n, d] : [d]);
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
if (
|
|
42
|
+
function h() {
|
|
43
|
+
if (r.length === 0) return;
|
|
44
44
|
const d = t.options.answers.reduce(
|
|
45
|
-
(
|
|
45
|
+
(l, f) => (f.is_correct && l.push(f.id), l),
|
|
46
46
|
[]
|
|
47
|
-
), n =
|
|
48
|
-
|
|
47
|
+
), n = k(r, d);
|
|
48
|
+
g(n);
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
50
|
+
function I() {
|
|
51
|
+
c([]), p();
|
|
52
52
|
}
|
|
53
53
|
return {
|
|
54
54
|
// data
|
|
55
55
|
question: t,
|
|
56
|
-
selectedIds:
|
|
56
|
+
selectedIds: r,
|
|
57
57
|
// actions
|
|
58
|
-
select:
|
|
59
|
-
submit:
|
|
60
|
-
reset:
|
|
58
|
+
select: C,
|
|
59
|
+
submit: h,
|
|
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
|
};
|
|
67
67
|
}
|
|
68
|
-
function
|
|
68
|
+
function v(t) {
|
|
69
69
|
const {
|
|
70
70
|
canAnswer: e,
|
|
71
71
|
submitted: s,
|
|
72
|
-
isCorrect:
|
|
72
|
+
isCorrect: i,
|
|
73
73
|
attempts: a,
|
|
74
74
|
submitQuestion: p,
|
|
75
|
-
resetQuestion:
|
|
76
|
-
} =
|
|
75
|
+
resetQuestion: g
|
|
76
|
+
} = S(), [r, c] = b([]), [C, h] = b(
|
|
77
|
+
[]
|
|
78
|
+
), [I, d] = b(
|
|
77
79
|
[]
|
|
78
80
|
);
|
|
79
|
-
function
|
|
80
|
-
|
|
81
|
-
...
|
|
82
|
-
(
|
|
81
|
+
function n(o, m) {
|
|
82
|
+
c((u) => [
|
|
83
|
+
...u.filter(
|
|
84
|
+
(A) => A.targetId !== o && A.sourceId !== m
|
|
83
85
|
),
|
|
84
|
-
{ targetId:
|
|
86
|
+
{ targetId: o, sourceId: m }
|
|
85
87
|
]);
|
|
86
88
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
+
function l(o) {
|
|
90
|
+
c((m) => m.filter((u) => u.targetId !== o));
|
|
89
91
|
}
|
|
90
|
-
function
|
|
91
|
-
let
|
|
92
|
-
return t.options.targets.forEach((
|
|
93
|
-
const
|
|
94
|
-
|
|
92
|
+
function f() {
|
|
93
|
+
let o = 0, m = !0;
|
|
94
|
+
return t.options.targets.forEach((u) => {
|
|
95
|
+
const A = r.find((M) => M.targetId === u.id), x = t.options.sources[u.content.correct_position - 1];
|
|
96
|
+
A && x && A.sourceId === x.id ? o += u.content.point : m = !1;
|
|
95
97
|
}), {
|
|
96
|
-
isCorrect:
|
|
97
|
-
score:
|
|
98
|
+
isCorrect: m,
|
|
99
|
+
score: o,
|
|
98
100
|
maxScore: t.options.targets.reduce(
|
|
99
|
-
(
|
|
101
|
+
(u, A) => u + A.content.point,
|
|
100
102
|
0
|
|
101
103
|
)
|
|
102
104
|
};
|
|
103
105
|
}
|
|
104
|
-
function
|
|
105
|
-
const
|
|
106
|
-
return p(
|
|
106
|
+
function Q() {
|
|
107
|
+
const o = f();
|
|
108
|
+
return p(o.isCorrect), o;
|
|
107
109
|
}
|
|
108
|
-
function
|
|
109
|
-
|
|
110
|
+
function w() {
|
|
111
|
+
c([]), g();
|
|
110
112
|
}
|
|
111
|
-
return
|
|
112
|
-
const
|
|
113
|
-
(
|
|
113
|
+
return B(() => {
|
|
114
|
+
const o = t.options.sources.filter(
|
|
115
|
+
(m) => !r.some((u) => u.sourceId === m.id)
|
|
116
|
+
);
|
|
117
|
+
h(o);
|
|
118
|
+
}, [r, t.options.sources]), B(() => {
|
|
119
|
+
const o = t.options.targets.filter(
|
|
120
|
+
(m) => !r.some((u) => u.targetId === m.id)
|
|
114
121
|
);
|
|
115
|
-
|
|
116
|
-
}, [
|
|
122
|
+
d(o);
|
|
123
|
+
}, [r, t.options.targets]), {
|
|
117
124
|
// data
|
|
118
125
|
sources: t.options.sources,
|
|
119
126
|
targets: t.options.targets,
|
|
120
|
-
answers:
|
|
127
|
+
answers: r,
|
|
121
128
|
question: t,
|
|
122
|
-
availableSources:
|
|
129
|
+
availableSources: C,
|
|
130
|
+
availableTargets: I,
|
|
123
131
|
// base
|
|
124
132
|
submitted: s,
|
|
125
|
-
isCorrect:
|
|
133
|
+
isCorrect: i,
|
|
126
134
|
attempts: a,
|
|
127
135
|
canAnswer: e,
|
|
128
136
|
// actions
|
|
129
|
-
select:
|
|
130
|
-
remove:
|
|
131
|
-
submit:
|
|
132
|
-
reset:
|
|
137
|
+
select: n,
|
|
138
|
+
remove: l,
|
|
139
|
+
submit: Q,
|
|
140
|
+
reset: w
|
|
133
141
|
};
|
|
134
142
|
}
|
|
135
|
-
function
|
|
143
|
+
function T(t) {
|
|
136
144
|
const {
|
|
137
145
|
canAnswer: e,
|
|
138
146
|
submitted: s,
|
|
139
|
-
isCorrect:
|
|
147
|
+
isCorrect: i,
|
|
140
148
|
attempts: a,
|
|
141
149
|
resetQuestion: p,
|
|
142
|
-
submitQuestion:
|
|
143
|
-
} =
|
|
144
|
-
function
|
|
145
|
-
|
|
150
|
+
submitQuestion: g
|
|
151
|
+
} = S();
|
|
152
|
+
function r() {
|
|
153
|
+
g(!0);
|
|
146
154
|
}
|
|
147
|
-
function
|
|
155
|
+
function c() {
|
|
148
156
|
p();
|
|
149
157
|
}
|
|
150
158
|
return {
|
|
@@ -153,11 +161,11 @@ function V(t) {
|
|
|
153
161
|
url: t.options.url,
|
|
154
162
|
type: t.options.urlType,
|
|
155
163
|
// actions
|
|
156
|
-
submit:
|
|
157
|
-
reset:
|
|
164
|
+
submit: r,
|
|
165
|
+
reset: c,
|
|
158
166
|
// base
|
|
159
167
|
submitted: s,
|
|
160
|
-
isCorrect:
|
|
168
|
+
isCorrect: i,
|
|
161
169
|
attempts: a,
|
|
162
170
|
canAnswer: e
|
|
163
171
|
};
|
|
@@ -166,29 +174,29 @@ function _(t) {
|
|
|
166
174
|
const {
|
|
167
175
|
canAnswer: e,
|
|
168
176
|
submitted: s,
|
|
169
|
-
isCorrect:
|
|
177
|
+
isCorrect: i,
|
|
170
178
|
attempts: a,
|
|
171
179
|
submitQuestion: p,
|
|
172
|
-
resetQuestion:
|
|
173
|
-
} =
|
|
174
|
-
function
|
|
175
|
-
e &&
|
|
176
|
-
const
|
|
177
|
-
if (
|
|
178
|
-
const
|
|
179
|
-
return
|
|
180
|
+
resetQuestion: g
|
|
181
|
+
} = S(), [r, c] = b([]);
|
|
182
|
+
function C(n, l) {
|
|
183
|
+
e && c((f) => {
|
|
184
|
+
const Q = f.findIndex((w) => w.targetId === n);
|
|
185
|
+
if (Q >= 0) {
|
|
186
|
+
const w = [...f];
|
|
187
|
+
return w[Q] = { targetId: n, value: l }, w;
|
|
180
188
|
}
|
|
181
|
-
return [...
|
|
189
|
+
return [...f, { targetId: n, value: l }];
|
|
182
190
|
});
|
|
183
191
|
}
|
|
184
|
-
function
|
|
192
|
+
function h() {
|
|
185
193
|
let n = !0;
|
|
186
|
-
if (
|
|
194
|
+
if (r.length < t.options.targets.length)
|
|
187
195
|
n = !1;
|
|
188
196
|
else
|
|
189
|
-
for (const
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
197
|
+
for (const l of t.options.targets) {
|
|
198
|
+
const f = r.find((o) => o.targetId === l.id), Q = f ? f.value.trim() : "", w = l.content.correct_answer.trim();
|
|
199
|
+
if (Q.toLowerCase() !== w.toLowerCase()) {
|
|
192
200
|
n = !1;
|
|
193
201
|
break;
|
|
194
202
|
}
|
|
@@ -199,26 +207,26 @@ function _(t) {
|
|
|
199
207
|
maxScore: 1
|
|
200
208
|
};
|
|
201
209
|
}
|
|
202
|
-
function
|
|
203
|
-
const n =
|
|
210
|
+
function I() {
|
|
211
|
+
const n = h();
|
|
204
212
|
return p(n.isCorrect), n;
|
|
205
213
|
}
|
|
206
214
|
function d() {
|
|
207
|
-
|
|
215
|
+
c([]), g();
|
|
208
216
|
}
|
|
209
217
|
return {
|
|
210
218
|
// data
|
|
211
219
|
targets: t.options.targets,
|
|
212
|
-
answers:
|
|
220
|
+
answers: r,
|
|
213
221
|
question: t,
|
|
214
222
|
// base
|
|
215
223
|
submitted: s,
|
|
216
|
-
isCorrect:
|
|
224
|
+
isCorrect: i,
|
|
217
225
|
attempts: a,
|
|
218
226
|
canAnswer: e,
|
|
219
227
|
// actions
|
|
220
|
-
answer:
|
|
221
|
-
submit:
|
|
228
|
+
answer: C,
|
|
229
|
+
submit: I,
|
|
222
230
|
reset: d
|
|
223
231
|
};
|
|
224
232
|
}
|
|
@@ -226,21 +234,21 @@ function z({
|
|
|
226
234
|
getData: t,
|
|
227
235
|
children: e
|
|
228
236
|
}) {
|
|
229
|
-
const s =
|
|
237
|
+
const s = V(t());
|
|
230
238
|
return e(s);
|
|
231
239
|
}
|
|
232
240
|
function E({
|
|
233
241
|
getData: t,
|
|
234
242
|
children: e
|
|
235
243
|
}) {
|
|
236
|
-
const s =
|
|
244
|
+
const s = v(t());
|
|
237
245
|
return e(s);
|
|
238
246
|
}
|
|
239
247
|
function F({
|
|
240
248
|
getData: t,
|
|
241
249
|
children: e
|
|
242
250
|
}) {
|
|
243
|
-
const s =
|
|
251
|
+
const s = T(t());
|
|
244
252
|
return e(s);
|
|
245
253
|
}
|
|
246
254
|
function L({
|
|
@@ -255,10 +263,10 @@ export {
|
|
|
255
263
|
E as MatchingQuestion,
|
|
256
264
|
z as MultipleChoicesQuestion,
|
|
257
265
|
F as VideoQuestion,
|
|
258
|
-
|
|
259
|
-
|
|
266
|
+
k as isSameSet,
|
|
267
|
+
S as useBaseQuestion,
|
|
260
268
|
_ as useFillInBlank,
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
269
|
+
v as useMatching,
|
|
270
|
+
V as useMultipleChoice,
|
|
271
|
+
T as useVideo
|
|
264
272
|
};
|