@enspiredigital/xlms-headless 0.0.28 → 0.0.29
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/useSpeaking.d.ts.map +1 -1
- package/dist/index.js +68 -68
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSpeaking.d.ts","sourceRoot":"","sources":["../../src/hooks/useSpeaking.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEzE,MAAM,MAAM,qBAAqB,GAAG,CAClC,SAAS,EAAE,IAAI,EACf,QAAQ,CAAC,EAAE,MAAM,KACd,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAEjE,wBAAgB,WAAW,CACzB,QAAQ,EAAE,oBAAoB,EAC9B,aAAa,CAAC,EAAE,qBAAqB;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useSpeaking.d.ts","sourceRoot":"","sources":["../../src/hooks/useSpeaking.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEzE,MAAM,MAAM,qBAAqB,GAAG,CAClC,SAAS,EAAE,IAAI,EACf,QAAQ,CAAC,EAAE,MAAM,KACd,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAEjE,wBAAgB,WAAW,CACzB,QAAQ,EAAE,oBAAoB,EAC9B,aAAa,CAAC,EAAE,qBAAqB;;;;;;;;;;;;;;;;;;;uBAqItB,IAAI;;;EAkFpB"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState as A, useRef as F, useEffect as V, useMemo as T, useCallback as
|
|
1
|
+
import { useState as A, useRef as F, useEffect as V, useMemo as T, useCallback as U } from "react";
|
|
2
2
|
import { jsx as W, Fragment as z } from "react/jsx-runtime";
|
|
3
3
|
function E() {
|
|
4
4
|
const [t, n] = A(null), [u, f] = A(null), [b, C] = A(0);
|
|
@@ -46,15 +46,15 @@ function X(t) {
|
|
|
46
46
|
submitQuestion: S
|
|
47
47
|
} = E(), [o, d] = A([]);
|
|
48
48
|
function h(w) {
|
|
49
|
-
d((
|
|
49
|
+
d((g) => t.options.allowMultipleAnswers ? g.includes(w) ? g.filter((p) => p !== w) : [...g, w] : [w]);
|
|
50
50
|
}
|
|
51
51
|
function I() {
|
|
52
52
|
if (o.length === 0) return;
|
|
53
53
|
const w = t.options.answers.reduce(
|
|
54
54
|
(p, x) => (x.is_correct && p.push(x.id), p),
|
|
55
55
|
[]
|
|
56
|
-
),
|
|
57
|
-
S(
|
|
56
|
+
), g = J(o, w);
|
|
57
|
+
S(g);
|
|
58
58
|
}
|
|
59
59
|
function v() {
|
|
60
60
|
d([]), C();
|
|
@@ -86,30 +86,30 @@ function Y(t) {
|
|
|
86
86
|
[]
|
|
87
87
|
), [v, w] = A(
|
|
88
88
|
[]
|
|
89
|
-
),
|
|
89
|
+
), g = F([]);
|
|
90
90
|
function p(e, s) {
|
|
91
91
|
d((l) => [
|
|
92
92
|
...l.filter(
|
|
93
|
-
(
|
|
93
|
+
(m) => m.targetId !== e && m.sourceId !== s
|
|
94
94
|
),
|
|
95
95
|
{ targetId: e, sourceId: s }
|
|
96
96
|
]);
|
|
97
97
|
}
|
|
98
98
|
function x(e, s) {
|
|
99
99
|
d(
|
|
100
|
-
(l) => l.filter((
|
|
100
|
+
(l) => l.filter((m) => m.targetId !== e || m.sourceId !== s)
|
|
101
101
|
);
|
|
102
102
|
}
|
|
103
103
|
function a() {
|
|
104
104
|
let e = 0, s = !0;
|
|
105
105
|
return t.options.targets.forEach((l) => {
|
|
106
|
-
const
|
|
107
|
-
|
|
106
|
+
const m = o.find((B) => B.targetId === l.id), y = t.options.sources[l.content.correct_position - 1];
|
|
107
|
+
m && y && m.sourceId === y.id ? e += l.content.point : s = !1;
|
|
108
108
|
}), {
|
|
109
109
|
isCorrect: s,
|
|
110
110
|
score: e,
|
|
111
111
|
maxScore: t.options.targets.reduce(
|
|
112
|
-
(l,
|
|
112
|
+
(l, m) => l + m.content.point,
|
|
113
113
|
0
|
|
114
114
|
)
|
|
115
115
|
};
|
|
@@ -131,13 +131,13 @@ function Y(t) {
|
|
|
131
131
|
);
|
|
132
132
|
I(e);
|
|
133
133
|
}, [o, t.options.sources]), V(() => {
|
|
134
|
-
if (
|
|
135
|
-
const e =
|
|
134
|
+
if (g.current.length === 0) return;
|
|
135
|
+
const e = g.current.filter(
|
|
136
136
|
(s) => !o.some((l) => l.targetId === s.id)
|
|
137
137
|
);
|
|
138
138
|
w(e);
|
|
139
139
|
}, [o]), V(() => {
|
|
140
|
-
|
|
140
|
+
g.current = G(t.options.targets);
|
|
141
141
|
}, [t.options.targets]), {
|
|
142
142
|
// data
|
|
143
143
|
sources: t.options.sources,
|
|
@@ -206,7 +206,7 @@ function K(t) {
|
|
|
206
206
|
function w(r, e) {
|
|
207
207
|
d((s) => [
|
|
208
208
|
...s.filter(
|
|
209
|
-
(
|
|
209
|
+
(m) => m.blankIndex !== e && m.itemId !== r
|
|
210
210
|
),
|
|
211
211
|
{
|
|
212
212
|
itemId: r,
|
|
@@ -214,7 +214,7 @@ function K(t) {
|
|
|
214
214
|
}
|
|
215
215
|
]);
|
|
216
216
|
}
|
|
217
|
-
function
|
|
217
|
+
function g(r) {
|
|
218
218
|
d((e) => e.filter((s) => s.itemId !== r));
|
|
219
219
|
}
|
|
220
220
|
function p(r, e) {
|
|
@@ -222,15 +222,15 @@ function K(t) {
|
|
|
222
222
|
}
|
|
223
223
|
function x() {
|
|
224
224
|
let r = 0, e = !0, s = 0;
|
|
225
|
-
const l = t.correct_answers.list,
|
|
226
|
-
return Object.entries(l).forEach(([y,
|
|
227
|
-
const
|
|
225
|
+
const l = t.correct_answers.list, m = new Map(o.map((y) => [y.blankIndex, y.itemId]));
|
|
226
|
+
return Object.entries(l).forEach(([y, B]) => {
|
|
227
|
+
const R = y, O = m.get(R);
|
|
228
228
|
if (!O) {
|
|
229
229
|
e = !1;
|
|
230
230
|
return;
|
|
231
231
|
}
|
|
232
232
|
const M = t.options.answers.find((D) => D.id === O);
|
|
233
|
-
M && String(M.group_position) === String(
|
|
233
|
+
M && String(M.group_position) === String(B) ? (r++, s += M.point) : e = !1;
|
|
234
234
|
}), {
|
|
235
235
|
isCorrect: e,
|
|
236
236
|
correctCount: r,
|
|
@@ -265,7 +265,7 @@ function K(t) {
|
|
|
265
265
|
canAnswer: n,
|
|
266
266
|
// actions
|
|
267
267
|
dropItem: w,
|
|
268
|
-
removeItem:
|
|
268
|
+
removeItem: g,
|
|
269
269
|
moveItem: p,
|
|
270
270
|
setDraggingItemId: I,
|
|
271
271
|
getItemByBlankId: i,
|
|
@@ -300,7 +300,7 @@ function H(t) {
|
|
|
300
300
|
const i = o.indexOf(c);
|
|
301
301
|
i < o.length - 1 && I(i, i + 1);
|
|
302
302
|
}
|
|
303
|
-
function
|
|
303
|
+
function g(c, i) {
|
|
304
304
|
const r = o.indexOf(c);
|
|
305
305
|
r !== -1 && i >= 0 && i < o.length && I(r, i);
|
|
306
306
|
}
|
|
@@ -342,7 +342,7 @@ function H(t) {
|
|
|
342
342
|
moveItem: I,
|
|
343
343
|
moveUp: v,
|
|
344
344
|
moveDown: w,
|
|
345
|
-
moveToPosition:
|
|
345
|
+
moveToPosition: g,
|
|
346
346
|
submit: x,
|
|
347
347
|
reset: a
|
|
348
348
|
};
|
|
@@ -362,10 +362,10 @@ function q(t) {
|
|
|
362
362
|
);
|
|
363
363
|
}, [o, t.options.labels]);
|
|
364
364
|
function I(i, r, e, s) {
|
|
365
|
-
const l = t.options.blanks.find((
|
|
366
|
-
l && d((
|
|
367
|
-
...
|
|
368
|
-
(
|
|
365
|
+
const l = t.options.blanks.find((m) => String(m.id) === r);
|
|
366
|
+
l && d((m) => [
|
|
367
|
+
...m.filter(
|
|
368
|
+
(B) => B.labelId !== i && B.blankId !== r
|
|
369
369
|
),
|
|
370
370
|
{
|
|
371
371
|
labelId: i,
|
|
@@ -381,7 +381,7 @@ function q(t) {
|
|
|
381
381
|
function w(i, r, e, s) {
|
|
382
382
|
I(i, r, e, s);
|
|
383
383
|
}
|
|
384
|
-
function
|
|
384
|
+
function g(i) {
|
|
385
385
|
const r = o.find((e) => e.blankId === i);
|
|
386
386
|
return r && t.options.labels.find(
|
|
387
387
|
(e) => String(e.id) === r.labelId
|
|
@@ -395,9 +395,9 @@ function q(t) {
|
|
|
395
395
|
let i = 0, r = !0;
|
|
396
396
|
return t.options.labels.forEach((e) => {
|
|
397
397
|
const s = o.find(
|
|
398
|
-
(
|
|
398
|
+
(m) => String(m.labelId) === String(e.id)
|
|
399
399
|
), l = t.options.blanks.find(
|
|
400
|
-
(
|
|
400
|
+
(m, y) => y + 1 === e.correct_position
|
|
401
401
|
);
|
|
402
402
|
s && l && s.blankId === String(l.id) ? i += e.point : r = !1;
|
|
403
403
|
}), {
|
|
@@ -435,7 +435,7 @@ function q(t) {
|
|
|
435
435
|
attachLabel: I,
|
|
436
436
|
removeLabel: v,
|
|
437
437
|
moveLabel: w,
|
|
438
|
-
getLabelAtBlank:
|
|
438
|
+
getLabelAtBlank: g,
|
|
439
439
|
getBlankForLabel: p,
|
|
440
440
|
submit: a,
|
|
441
441
|
reset: c
|
|
@@ -450,37 +450,37 @@ function tt(t) {
|
|
|
450
450
|
submitQuestion: C,
|
|
451
451
|
resetQuestion: S
|
|
452
452
|
} = E(), [o, d] = A([]);
|
|
453
|
-
function h(
|
|
453
|
+
function h(g, p) {
|
|
454
454
|
d((x) => {
|
|
455
|
-
const a = x.findIndex((c) => c.blankId ===
|
|
455
|
+
const a = x.findIndex((c) => c.blankId === g);
|
|
456
456
|
if (a >= 0) {
|
|
457
457
|
const c = [...x];
|
|
458
|
-
return c[a] = { blankId:
|
|
458
|
+
return c[a] = { blankId: g, value: p }, c;
|
|
459
459
|
}
|
|
460
|
-
return [...x, { blankId:
|
|
460
|
+
return [...x, { blankId: g, value: p }];
|
|
461
461
|
});
|
|
462
462
|
}
|
|
463
463
|
function I() {
|
|
464
|
-
let
|
|
464
|
+
let g = 0, p = 0, x = 0;
|
|
465
465
|
const a = t.correct_answers.list || {}, c = Object.keys(a).length;
|
|
466
466
|
Object.entries(a).forEach(([r, e]) => {
|
|
467
467
|
const s = String(e).trim().toLowerCase(), l = t.options.answers.find(
|
|
468
|
-
(
|
|
469
|
-
),
|
|
470
|
-
x +=
|
|
471
|
-
const y = o.find((
|
|
472
|
-
(y ? String(y.value).trim().toLowerCase() : "") === s && (
|
|
468
|
+
(R) => R.correct_position === Number(r)
|
|
469
|
+
), m = l && l.point || 1;
|
|
470
|
+
x += m;
|
|
471
|
+
const y = o.find((R) => R.blankId === r);
|
|
472
|
+
(y ? String(y.value).trim().toLowerCase() : "") === s && (g += m, p++);
|
|
473
473
|
});
|
|
474
474
|
const i = p === c && c > 0;
|
|
475
475
|
return x === 0 && c > 0 && (x = c), {
|
|
476
476
|
isCorrect: i,
|
|
477
|
-
score: Math.round(
|
|
477
|
+
score: Math.round(g * 100) / 100,
|
|
478
478
|
maxScore: Math.round(x * 100) / 100
|
|
479
479
|
};
|
|
480
480
|
}
|
|
481
481
|
function v() {
|
|
482
|
-
const
|
|
483
|
-
return C(
|
|
482
|
+
const g = I();
|
|
483
|
+
return C(g.isCorrect), g;
|
|
484
484
|
}
|
|
485
485
|
function w() {
|
|
486
486
|
d([]), S();
|
|
@@ -527,11 +527,11 @@ function et(t) {
|
|
|
527
527
|
let a = 0, c = 0;
|
|
528
528
|
const r = t.correct_answers.list || {}, e = Object.keys(r).length;
|
|
529
529
|
let s = 0;
|
|
530
|
-
return Object.entries(r).forEach(([
|
|
531
|
-
const
|
|
532
|
-
s +=
|
|
533
|
-
const O = o.find((M) => M.itemId ===
|
|
534
|
-
O && O.categoryId === y && (a +=
|
|
530
|
+
return Object.entries(r).forEach(([m, y]) => {
|
|
531
|
+
const B = t.options.items.find((M) => M.id === m), R = B ? B.point : 0;
|
|
532
|
+
s += R;
|
|
533
|
+
const O = o.find((M) => M.itemId === m);
|
|
534
|
+
O && O.categoryId === y && (a += R, c++);
|
|
535
535
|
}), a = Math.round(a * 100) / 100, s = Math.round(s * 100) / 100, {
|
|
536
536
|
isCorrect: c === e && e > 0,
|
|
537
537
|
score: a,
|
|
@@ -542,7 +542,7 @@ function et(t) {
|
|
|
542
542
|
const a = v();
|
|
543
543
|
return C(a.isCorrect), a;
|
|
544
544
|
}
|
|
545
|
-
function
|
|
545
|
+
function g() {
|
|
546
546
|
d([]), S();
|
|
547
547
|
}
|
|
548
548
|
const p = T(() => t.options.items.filter(
|
|
@@ -574,7 +574,7 @@ function et(t) {
|
|
|
574
574
|
move: h,
|
|
575
575
|
remove: I,
|
|
576
576
|
submit: w,
|
|
577
|
-
reset:
|
|
577
|
+
reset: g
|
|
578
578
|
};
|
|
579
579
|
}
|
|
580
580
|
function rt(t) {
|
|
@@ -608,7 +608,7 @@ function rt(t) {
|
|
|
608
608
|
};
|
|
609
609
|
}
|
|
610
610
|
function nt(t, n) {
|
|
611
|
-
const { canAnswer: u, submitted: f, attempts: b, submitQuestion: C, resetQuestion: S } = E(), [o, d] = A(""), [h, I] = A(void 0), [v, w] = A(!1), [
|
|
611
|
+
const { canAnswer: u, submitted: f, attempts: b, submitQuestion: C, resetQuestion: S } = E(), [o, d] = A(""), [h, I] = A(void 0), [v, w] = A(!1), [g, p] = A(void 0), x = U(
|
|
612
612
|
async (e) => {
|
|
613
613
|
if (n) {
|
|
614
614
|
w(!0), p(void 0);
|
|
@@ -625,7 +625,7 @@ function nt(t, n) {
|
|
|
625
625
|
}
|
|
626
626
|
},
|
|
627
627
|
[n]
|
|
628
|
-
), a =
|
|
628
|
+
), a = U(async () => {
|
|
629
629
|
if (!(!n || !o)) {
|
|
630
630
|
w(!0), p(void 0);
|
|
631
631
|
try {
|
|
@@ -646,7 +646,7 @@ function nt(t, n) {
|
|
|
646
646
|
fileUrl: h
|
|
647
647
|
}),
|
|
648
648
|
[o, h]
|
|
649
|
-
), i =
|
|
649
|
+
), i = U(() => (C(), c), [C, c]), r = U(() => {
|
|
650
650
|
d(""), I(void 0), p(void 0), S();
|
|
651
651
|
}, [S]);
|
|
652
652
|
return {
|
|
@@ -659,7 +659,7 @@ function nt(t, n) {
|
|
|
659
659
|
fileUrl: h,
|
|
660
660
|
setFileUrl: I,
|
|
661
661
|
isUploading: v,
|
|
662
|
-
uploadError:
|
|
662
|
+
uploadError: g,
|
|
663
663
|
uploadFile: x,
|
|
664
664
|
uploadText: a,
|
|
665
665
|
submit: i,
|
|
@@ -668,7 +668,7 @@ function nt(t, n) {
|
|
|
668
668
|
};
|
|
669
669
|
}
|
|
670
670
|
function st(t, n) {
|
|
671
|
-
const { canAnswer: u, submitted: f, attempts: b, submitQuestion: C, resetQuestion: S } = E(), [o, d] = A(void 0), [h, I] = A("idle"), [v, w] = A(0), [
|
|
671
|
+
const { canAnswer: u, submitted: f, attempts: b, submitQuestion: C, resetQuestion: S } = E(), [o, d] = A(void 0), [h, I] = A("idle"), [v, w] = A(0), [g, p] = A(!1), [x, a] = A(void 0), [c, i] = A(!1), r = F(null), e = F([]), s = F(null), l = F(null), m = U(async () => {
|
|
672
672
|
i(!0);
|
|
673
673
|
try {
|
|
674
674
|
const Q = await navigator.mediaDevices.getUserMedia({ audio: !0 });
|
|
@@ -684,22 +684,22 @@ function st(t, n) {
|
|
|
684
684
|
}, k.start(), I("recording"), w(0);
|
|
685
685
|
let L = 0;
|
|
686
686
|
s.current = setInterval(() => {
|
|
687
|
-
L++, w(L), L >= (t.metadata?.max_recording_time || 300) &&
|
|
687
|
+
L++, w(L), L >= (t.metadata?.max_recording_time || 300) && R();
|
|
688
688
|
}, 1e3);
|
|
689
689
|
} catch (Q) {
|
|
690
690
|
console.error("Failed to start recording:", Q), a("Failed to access microphone");
|
|
691
691
|
}
|
|
692
|
-
}, []), y =
|
|
692
|
+
}, []), y = U(() => {
|
|
693
693
|
r.current && h === "recording" && (r.current.pause(), I("paused"), s.current && clearInterval(s.current));
|
|
694
|
-
}, [h]),
|
|
694
|
+
}, [h]), B = U(() => {
|
|
695
695
|
r.current && h === "paused" && (r.current.resume(), I("recording"), s.current = setInterval(() => {
|
|
696
696
|
w((Q) => Q + 1);
|
|
697
697
|
}, 1e3));
|
|
698
|
-
}, [h]),
|
|
698
|
+
}, [h]), R = U(() => {
|
|
699
699
|
r.current && h !== "idle" && (r.current.stop(), i(!1), I("stopped"), s.current && clearInterval(s.current), l.current && l.current.getTracks().forEach((Q) => Q.stop()));
|
|
700
|
-
}, [h]), O =
|
|
701
|
-
c ?
|
|
702
|
-
}, [c]), M =
|
|
700
|
+
}, [h]), O = U(() => {
|
|
701
|
+
c ? R() : m();
|
|
702
|
+
}, [c, m, R]), M = U(async () => {
|
|
703
703
|
if (!(!e.current.length || !n)) {
|
|
704
704
|
p(!0), a(void 0);
|
|
705
705
|
try {
|
|
@@ -713,7 +713,7 @@ function st(t, n) {
|
|
|
713
713
|
p(!1);
|
|
714
714
|
}
|
|
715
715
|
}
|
|
716
|
-
}, [t, n]), D =
|
|
716
|
+
}, [t, n]), D = U(
|
|
717
717
|
async (Q) => {
|
|
718
718
|
if (n) {
|
|
719
719
|
p(!0), a(void 0);
|
|
@@ -736,7 +736,7 @@ function st(t, n) {
|
|
|
736
736
|
audioUrl: o
|
|
737
737
|
}),
|
|
738
738
|
[t, o]
|
|
739
|
-
), $ =
|
|
739
|
+
), $ = U(() => (C(), j), [C, j]), N = U(() => {
|
|
740
740
|
d(void 0), I("idle"), w(0), a(void 0), e.current = [], s.current && clearInterval(s.current), l.current && l.current.getTracks().forEach((Q) => Q.stop()), S();
|
|
741
741
|
}, [S]);
|
|
742
742
|
return {
|
|
@@ -747,15 +747,15 @@ function st(t, n) {
|
|
|
747
747
|
audioUrl: o,
|
|
748
748
|
recordingState: h,
|
|
749
749
|
recordingTime: v,
|
|
750
|
-
isUploading:
|
|
750
|
+
isUploading: g,
|
|
751
751
|
uploadError: x,
|
|
752
752
|
isRecording: c,
|
|
753
753
|
payload: j,
|
|
754
754
|
setAudioUrl: d,
|
|
755
|
-
startRecording:
|
|
755
|
+
startRecording: m,
|
|
756
756
|
pauseRecording: y,
|
|
757
|
-
resumeRecording:
|
|
758
|
-
stopRecording:
|
|
757
|
+
resumeRecording: B,
|
|
758
|
+
stopRecording: R,
|
|
759
759
|
toggleRecording: O,
|
|
760
760
|
uploadAudio: M,
|
|
761
761
|
uploadFile: D,
|