@enspiredigital/xlms-headless 0.0.22 → 0.0.23
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.map +1 -1
- package/dist/index.js +84 -83
- package/package.json +1 -1
|
@@ -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;AAGlB,wBAAgB,WAAW,CAAC,QAAQ,EAAE,oBAAoB;;;;;;;;;;;oCAiFjB,MAAM;uBA9DnB,MAAM,YAAY,MAAM;uBAaxB,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;AAGlB,wBAAgB,WAAW,CAAC,QAAQ,EAAE,oBAAoB;;;;;;;;;;;oCAiFjB,MAAM;uBA9DnB,MAAM,YAAY,MAAM;uBAaxB,MAAM,YAAY,MAAM;;;;;;;EAgGnD"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useState as k, useRef as E, useEffect as _, useMemo as y } from "react";
|
|
2
2
|
function M() {
|
|
3
|
-
const [t, i] = k(null), [c,
|
|
4
|
-
function
|
|
5
|
-
i(!0),
|
|
3
|
+
const [t, i] = k(null), [c, p] = k(null), [g, w] = k(0);
|
|
4
|
+
function h(f) {
|
|
5
|
+
i(!0), p(f), w((A) => A + 1);
|
|
6
6
|
}
|
|
7
7
|
function s() {
|
|
8
|
-
i(!1),
|
|
8
|
+
i(!1), p(null);
|
|
9
9
|
}
|
|
10
10
|
return {
|
|
11
11
|
// state
|
|
@@ -15,23 +15,23 @@ function M() {
|
|
|
15
15
|
// derived
|
|
16
16
|
canAnswer: !t,
|
|
17
17
|
// actions
|
|
18
|
-
submitQuestion:
|
|
18
|
+
submitQuestion: h,
|
|
19
19
|
resetQuestion: s
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
function T(t, i) {
|
|
23
23
|
if (t.length !== i.length) return !1;
|
|
24
|
-
const c = new Set(t),
|
|
25
|
-
if (c.size !==
|
|
24
|
+
const c = new Set(t), p = new Set(i);
|
|
25
|
+
if (c.size !== p.size) return !1;
|
|
26
26
|
for (const g of c)
|
|
27
|
-
if (!
|
|
27
|
+
if (!p.has(g)) return !1;
|
|
28
28
|
return !0;
|
|
29
29
|
}
|
|
30
30
|
function j(t) {
|
|
31
31
|
const i = [...t];
|
|
32
32
|
for (let c = i.length - 1; c > 0; c--) {
|
|
33
|
-
const
|
|
34
|
-
[i[c], i[
|
|
33
|
+
const p = Math.floor(Math.random() * (c + 1));
|
|
34
|
+
[i[c], i[p]] = [i[p], i[c]];
|
|
35
35
|
}
|
|
36
36
|
return i;
|
|
37
37
|
}
|
|
@@ -39,21 +39,21 @@ function V(t) {
|
|
|
39
39
|
const {
|
|
40
40
|
canAnswer: i,
|
|
41
41
|
submitted: c,
|
|
42
|
-
isCorrect:
|
|
42
|
+
isCorrect: p,
|
|
43
43
|
attempts: g,
|
|
44
44
|
resetQuestion: w,
|
|
45
|
-
submitQuestion:
|
|
45
|
+
submitQuestion: h
|
|
46
46
|
} = M(), [s, f] = k([]);
|
|
47
|
-
function A(
|
|
48
|
-
f((
|
|
47
|
+
function A(C) {
|
|
48
|
+
f((m) => t.options.allowMultipleAnswers ? m.includes(C) ? m.filter((I) => I !== C) : [...m, C] : [C]);
|
|
49
49
|
}
|
|
50
50
|
function S() {
|
|
51
51
|
if (s.length === 0) return;
|
|
52
|
-
const
|
|
52
|
+
const C = t.options.answers.reduce(
|
|
53
53
|
(I, b) => (b.is_correct && I.push(b.id), I),
|
|
54
54
|
[]
|
|
55
|
-
),
|
|
56
|
-
|
|
55
|
+
), m = T(s, C);
|
|
56
|
+
h(m);
|
|
57
57
|
}
|
|
58
58
|
function x() {
|
|
59
59
|
f([]), w();
|
|
@@ -68,7 +68,7 @@ function V(t) {
|
|
|
68
68
|
reset: x,
|
|
69
69
|
// base
|
|
70
70
|
submitted: c,
|
|
71
|
-
isCorrect:
|
|
71
|
+
isCorrect: p,
|
|
72
72
|
attempts: g,
|
|
73
73
|
canAnswer: i
|
|
74
74
|
};
|
|
@@ -77,15 +77,15 @@ function F(t) {
|
|
|
77
77
|
const {
|
|
78
78
|
canAnswer: i,
|
|
79
79
|
submitted: c,
|
|
80
|
-
isCorrect:
|
|
80
|
+
isCorrect: p,
|
|
81
81
|
attempts: g,
|
|
82
82
|
submitQuestion: w,
|
|
83
|
-
resetQuestion:
|
|
83
|
+
resetQuestion: h
|
|
84
84
|
} = M(), [s, f] = k([]), [A, S] = k(
|
|
85
85
|
[]
|
|
86
|
-
), [x,
|
|
86
|
+
), [x, C] = k(
|
|
87
87
|
[]
|
|
88
|
-
),
|
|
88
|
+
), m = E([]);
|
|
89
89
|
function I(e, u) {
|
|
90
90
|
f((l) => [
|
|
91
91
|
...l.filter(
|
|
@@ -118,7 +118,7 @@ function F(t) {
|
|
|
118
118
|
return w(e.isCorrect), e;
|
|
119
119
|
}
|
|
120
120
|
function r() {
|
|
121
|
-
f([]),
|
|
121
|
+
f([]), h();
|
|
122
122
|
}
|
|
123
123
|
function n(e) {
|
|
124
124
|
const u = s.find((l) => l.sourceId === e)?.targetId;
|
|
@@ -130,12 +130,13 @@ function F(t) {
|
|
|
130
130
|
);
|
|
131
131
|
S(e);
|
|
132
132
|
}, [s, t.options.sources]), _(() => {
|
|
133
|
-
|
|
133
|
+
if (m.current.length === 0) return;
|
|
134
|
+
const e = m.current.filter(
|
|
134
135
|
(u) => !s.some((l) => l.targetId === u.id)
|
|
135
136
|
);
|
|
136
|
-
|
|
137
|
+
C(e);
|
|
137
138
|
}, [s]), _(() => {
|
|
138
|
-
|
|
139
|
+
m.current = j(t.options.targets);
|
|
139
140
|
}, [t.options.targets]), {
|
|
140
141
|
// data
|
|
141
142
|
sources: t.options.sources,
|
|
@@ -146,7 +147,7 @@ function F(t) {
|
|
|
146
147
|
availableTargets: x,
|
|
147
148
|
// base
|
|
148
149
|
submitted: c,
|
|
149
|
-
isCorrect:
|
|
150
|
+
isCorrect: p,
|
|
150
151
|
attempts: g,
|
|
151
152
|
canAnswer: i,
|
|
152
153
|
// actions
|
|
@@ -161,13 +162,13 @@ function z(t) {
|
|
|
161
162
|
const {
|
|
162
163
|
canAnswer: i,
|
|
163
164
|
submitted: c,
|
|
164
|
-
isCorrect:
|
|
165
|
+
isCorrect: p,
|
|
165
166
|
attempts: g,
|
|
166
167
|
resetQuestion: w,
|
|
167
|
-
submitQuestion:
|
|
168
|
+
submitQuestion: h
|
|
168
169
|
} = M();
|
|
169
170
|
function s() {
|
|
170
|
-
|
|
171
|
+
h(!0);
|
|
171
172
|
}
|
|
172
173
|
function f() {
|
|
173
174
|
w();
|
|
@@ -182,7 +183,7 @@ function z(t) {
|
|
|
182
183
|
reset: f,
|
|
183
184
|
// base
|
|
184
185
|
submitted: c,
|
|
185
|
-
isCorrect:
|
|
186
|
+
isCorrect: p,
|
|
186
187
|
attempts: g,
|
|
187
188
|
canAnswer: i
|
|
188
189
|
};
|
|
@@ -191,17 +192,17 @@ function G(t) {
|
|
|
191
192
|
const {
|
|
192
193
|
canAnswer: i,
|
|
193
194
|
submitted: c,
|
|
194
|
-
isCorrect:
|
|
195
|
+
isCorrect: p,
|
|
195
196
|
attempts: g,
|
|
196
197
|
submitQuestion: w,
|
|
197
|
-
resetQuestion:
|
|
198
|
+
resetQuestion: h
|
|
198
199
|
} = M(), [s, f] = k([]), [A, S] = k(null), x = y(() => {
|
|
199
200
|
const n = new Set(s.map((e) => e.itemId));
|
|
200
201
|
return t.options.answers.filter(
|
|
201
202
|
(e) => !n.has(String(e.id))
|
|
202
203
|
);
|
|
203
204
|
}, [s, t.options.answers]);
|
|
204
|
-
function
|
|
205
|
+
function C(n, e) {
|
|
205
206
|
f((u) => [
|
|
206
207
|
...u.filter(
|
|
207
208
|
(d) => d.blankIndex !== e && d.itemId !== n
|
|
@@ -212,11 +213,11 @@ function G(t) {
|
|
|
212
213
|
}
|
|
213
214
|
]);
|
|
214
215
|
}
|
|
215
|
-
function
|
|
216
|
+
function m(n) {
|
|
216
217
|
f((e) => e.filter((u) => u.itemId !== n));
|
|
217
218
|
}
|
|
218
219
|
function I(n, e) {
|
|
219
|
-
|
|
220
|
+
C(n, e);
|
|
220
221
|
}
|
|
221
222
|
function b() {
|
|
222
223
|
let n = 0, e = !0, u = 0;
|
|
@@ -242,7 +243,7 @@ function G(t) {
|
|
|
242
243
|
return w(n.isCorrect), n;
|
|
243
244
|
}
|
|
244
245
|
function o() {
|
|
245
|
-
f([]),
|
|
246
|
+
f([]), h();
|
|
246
247
|
}
|
|
247
248
|
function r(n) {
|
|
248
249
|
const e = s.find((u) => u.blankIndex === n)?.itemId;
|
|
@@ -258,12 +259,12 @@ function G(t) {
|
|
|
258
259
|
draggingItemId: A,
|
|
259
260
|
// base
|
|
260
261
|
submitted: c,
|
|
261
|
-
isCorrect:
|
|
262
|
+
isCorrect: p,
|
|
262
263
|
attempts: g,
|
|
263
264
|
canAnswer: i,
|
|
264
265
|
// actions
|
|
265
|
-
dropItem:
|
|
266
|
-
removeItem:
|
|
266
|
+
dropItem: C,
|
|
267
|
+
removeItem: m,
|
|
267
268
|
moveItem: I,
|
|
268
269
|
setDraggingItemId: S,
|
|
269
270
|
getItemByBlankId: r,
|
|
@@ -275,10 +276,10 @@ function R(t) {
|
|
|
275
276
|
const {
|
|
276
277
|
canAnswer: i,
|
|
277
278
|
submitted: c,
|
|
278
|
-
isCorrect:
|
|
279
|
+
isCorrect: p,
|
|
279
280
|
attempts: g,
|
|
280
281
|
submitQuestion: w,
|
|
281
|
-
resetQuestion:
|
|
282
|
+
resetQuestion: h
|
|
282
283
|
} = M(), [s, f] = k(() => j(
|
|
283
284
|
t.options.answers.map((o) => String(o.id))
|
|
284
285
|
)), A = y(() => s.map(
|
|
@@ -294,11 +295,11 @@ function R(t) {
|
|
|
294
295
|
const r = s.indexOf(o);
|
|
295
296
|
r > 0 && S(r, r - 1);
|
|
296
297
|
}
|
|
297
|
-
function
|
|
298
|
+
function C(o) {
|
|
298
299
|
const r = s.indexOf(o);
|
|
299
300
|
r < s.length - 1 && S(r, r + 1);
|
|
300
301
|
}
|
|
301
|
-
function
|
|
302
|
+
function m(o, r) {
|
|
302
303
|
const n = s.indexOf(o);
|
|
303
304
|
n !== -1 && r >= 0 && r < s.length && S(n, r);
|
|
304
305
|
}
|
|
@@ -321,7 +322,7 @@ function R(t) {
|
|
|
321
322
|
return w(o.isCorrect), o;
|
|
322
323
|
}
|
|
323
324
|
function a() {
|
|
324
|
-
f(t.options.answers.map((o) => String(o.id))),
|
|
325
|
+
f(t.options.answers.map((o) => String(o.id))), h();
|
|
325
326
|
}
|
|
326
327
|
return {
|
|
327
328
|
// data
|
|
@@ -332,15 +333,15 @@ function R(t) {
|
|
|
332
333
|
question: t,
|
|
333
334
|
// base
|
|
334
335
|
submitted: c,
|
|
335
|
-
isCorrect:
|
|
336
|
+
isCorrect: p,
|
|
336
337
|
attempts: g,
|
|
337
338
|
canAnswer: i,
|
|
338
339
|
// actions
|
|
339
340
|
setOrderedItemIds: f,
|
|
340
341
|
moveItem: S,
|
|
341
342
|
moveUp: x,
|
|
342
|
-
moveDown:
|
|
343
|
-
moveToPosition:
|
|
343
|
+
moveDown: C,
|
|
344
|
+
moveToPosition: m,
|
|
344
345
|
submit: b,
|
|
345
346
|
reset: a
|
|
346
347
|
};
|
|
@@ -349,10 +350,10 @@ function W(t) {
|
|
|
349
350
|
const {
|
|
350
351
|
canAnswer: i,
|
|
351
352
|
submitted: c,
|
|
352
|
-
isCorrect:
|
|
353
|
+
isCorrect: p,
|
|
353
354
|
attempts: g,
|
|
354
355
|
submitQuestion: w,
|
|
355
|
-
resetQuestion:
|
|
356
|
+
resetQuestion: h
|
|
356
357
|
} = M(), [s, f] = k([]), A = y(() => {
|
|
357
358
|
const r = new Set(s.map((n) => n.labelId));
|
|
358
359
|
return t.options.labels.filter(
|
|
@@ -376,10 +377,10 @@ function W(t) {
|
|
|
376
377
|
function x(r) {
|
|
377
378
|
f((n) => n.filter((e) => e.labelId !== r));
|
|
378
379
|
}
|
|
379
|
-
function
|
|
380
|
+
function C(r, n, e, u) {
|
|
380
381
|
S(r, n, e, u);
|
|
381
382
|
}
|
|
382
|
-
function
|
|
383
|
+
function m(r) {
|
|
383
384
|
const n = s.find((e) => e.blankId === r);
|
|
384
385
|
return n && t.options.labels.find(
|
|
385
386
|
(e) => String(e.id) === n.labelId
|
|
@@ -412,7 +413,7 @@ function W(t) {
|
|
|
412
413
|
return w(r.isCorrect), r;
|
|
413
414
|
}
|
|
414
415
|
function o() {
|
|
415
|
-
f([]),
|
|
416
|
+
f([]), h();
|
|
416
417
|
}
|
|
417
418
|
return {
|
|
418
419
|
// data
|
|
@@ -426,14 +427,14 @@ function W(t) {
|
|
|
426
427
|
question: t,
|
|
427
428
|
// base
|
|
428
429
|
submitted: c,
|
|
429
|
-
isCorrect:
|
|
430
|
+
isCorrect: p,
|
|
430
431
|
attempts: g,
|
|
431
432
|
canAnswer: i,
|
|
432
433
|
// actions
|
|
433
434
|
attachLabel: S,
|
|
434
435
|
removeLabel: x,
|
|
435
|
-
moveLabel:
|
|
436
|
-
getLabelAtBlank:
|
|
436
|
+
moveLabel: C,
|
|
437
|
+
getLabelAtBlank: m,
|
|
437
438
|
getBlankForLabel: I,
|
|
438
439
|
submit: a,
|
|
439
440
|
reset: o
|
|
@@ -443,23 +444,23 @@ function H(t) {
|
|
|
443
444
|
const {
|
|
444
445
|
canAnswer: i,
|
|
445
446
|
submitted: c,
|
|
446
|
-
isCorrect:
|
|
447
|
+
isCorrect: p,
|
|
447
448
|
attempts: g,
|
|
448
449
|
submitQuestion: w,
|
|
449
|
-
resetQuestion:
|
|
450
|
+
resetQuestion: h
|
|
450
451
|
} = M(), [s, f] = k([]);
|
|
451
|
-
function A(
|
|
452
|
+
function A(m, I) {
|
|
452
453
|
f((b) => {
|
|
453
|
-
const a = b.findIndex((o) => o.blankId ===
|
|
454
|
+
const a = b.findIndex((o) => o.blankId === m);
|
|
454
455
|
if (a >= 0) {
|
|
455
456
|
const o = [...b];
|
|
456
|
-
return o[a] = { blankId:
|
|
457
|
+
return o[a] = { blankId: m, value: I }, o;
|
|
457
458
|
}
|
|
458
|
-
return [...b, { blankId:
|
|
459
|
+
return [...b, { blankId: m, value: I }];
|
|
459
460
|
});
|
|
460
461
|
}
|
|
461
462
|
function S() {
|
|
462
|
-
let
|
|
463
|
+
let m = 0, I = 0, b = 0;
|
|
463
464
|
const a = t.correct_answers.list || {}, o = Object.keys(a).length;
|
|
464
465
|
Object.entries(a).forEach(([n, e]) => {
|
|
465
466
|
const u = String(e).trim().toLowerCase(), l = t.options.answers.find(
|
|
@@ -467,21 +468,21 @@ function H(t) {
|
|
|
467
468
|
), d = l && l.point || 1;
|
|
468
469
|
b += d;
|
|
469
470
|
const Q = s.find((O) => O.blankId === n);
|
|
470
|
-
(Q ? String(Q.value).trim().toLowerCase() : "") === u && (
|
|
471
|
+
(Q ? String(Q.value).trim().toLowerCase() : "") === u && (m += d, I++);
|
|
471
472
|
});
|
|
472
473
|
const r = I === o && o > 0;
|
|
473
474
|
return b === 0 && o > 0 && (b = o), {
|
|
474
475
|
isCorrect: r,
|
|
475
|
-
score: Math.round(
|
|
476
|
+
score: Math.round(m * 100) / 100,
|
|
476
477
|
maxScore: Math.round(b * 100) / 100
|
|
477
478
|
};
|
|
478
479
|
}
|
|
479
480
|
function x() {
|
|
480
|
-
const
|
|
481
|
-
return w(
|
|
481
|
+
const m = S();
|
|
482
|
+
return w(m.isCorrect), m;
|
|
482
483
|
}
|
|
483
|
-
function
|
|
484
|
-
f([]),
|
|
484
|
+
function C() {
|
|
485
|
+
f([]), h();
|
|
485
486
|
}
|
|
486
487
|
return {
|
|
487
488
|
// data
|
|
@@ -490,23 +491,23 @@ function H(t) {
|
|
|
490
491
|
question: t,
|
|
491
492
|
// base
|
|
492
493
|
submitted: c,
|
|
493
|
-
isCorrect:
|
|
494
|
+
isCorrect: p,
|
|
494
495
|
attempts: g,
|
|
495
496
|
canAnswer: i,
|
|
496
497
|
// actions
|
|
497
498
|
answer: A,
|
|
498
499
|
submit: x,
|
|
499
|
-
reset:
|
|
500
|
+
reset: C
|
|
500
501
|
};
|
|
501
502
|
}
|
|
502
503
|
function N(t) {
|
|
503
504
|
const {
|
|
504
505
|
canAnswer: i,
|
|
505
506
|
submitted: c,
|
|
506
|
-
isCorrect:
|
|
507
|
+
isCorrect: p,
|
|
507
508
|
attempts: g,
|
|
508
509
|
submitQuestion: w,
|
|
509
|
-
resetQuestion:
|
|
510
|
+
resetQuestion: h
|
|
510
511
|
} = M(), [s, f] = k([]);
|
|
511
512
|
function A(a, o) {
|
|
512
513
|
f((r) => {
|
|
@@ -536,12 +537,12 @@ function N(t) {
|
|
|
536
537
|
maxScore: u
|
|
537
538
|
};
|
|
538
539
|
}
|
|
539
|
-
function
|
|
540
|
+
function C() {
|
|
540
541
|
const a = x();
|
|
541
542
|
return w(a.isCorrect), a;
|
|
542
543
|
}
|
|
543
|
-
function
|
|
544
|
-
f([]),
|
|
544
|
+
function m() {
|
|
545
|
+
f([]), h();
|
|
545
546
|
}
|
|
546
547
|
const I = y(() => t.options.items.filter(
|
|
547
548
|
(a) => !s.some((o) => o.itemId === a.id)
|
|
@@ -565,27 +566,27 @@ function N(t) {
|
|
|
565
566
|
unassignedItems: I,
|
|
566
567
|
// base
|
|
567
568
|
submitted: c,
|
|
568
|
-
isCorrect:
|
|
569
|
+
isCorrect: p,
|
|
569
570
|
attempts: g,
|
|
570
571
|
canAnswer: i,
|
|
571
572
|
// actions
|
|
572
573
|
move: A,
|
|
573
574
|
remove: S,
|
|
574
|
-
submit:
|
|
575
|
-
reset:
|
|
575
|
+
submit: C,
|
|
576
|
+
reset: m
|
|
576
577
|
};
|
|
577
578
|
}
|
|
578
579
|
function P(t) {
|
|
579
580
|
const {
|
|
580
581
|
canAnswer: i,
|
|
581
582
|
submitted: c,
|
|
582
|
-
isCorrect:
|
|
583
|
+
isCorrect: p,
|
|
583
584
|
attempts: g,
|
|
584
585
|
resetQuestion: w,
|
|
585
|
-
submitQuestion:
|
|
586
|
+
submitQuestion: h
|
|
586
587
|
} = M();
|
|
587
588
|
function s() {
|
|
588
|
-
c ||
|
|
589
|
+
c || h(!0);
|
|
589
590
|
}
|
|
590
591
|
function f() {
|
|
591
592
|
w();
|
|
@@ -600,7 +601,7 @@ function P(t) {
|
|
|
600
601
|
reset: f,
|
|
601
602
|
// base
|
|
602
603
|
submitted: c,
|
|
603
|
-
isCorrect:
|
|
604
|
+
isCorrect: p,
|
|
604
605
|
attempts: g,
|
|
605
606
|
canAnswer: i
|
|
606
607
|
};
|