@enspiredigital/xlms-headless 0.0.28 → 0.0.30
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 +157 -157
- 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;;;;;;;;;;;;;;;;;;;uBAwItB,IAAI;;;EAkFpB"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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
|
-
const [t, n] = A(null), [u, f] = A(null), [b,
|
|
5
|
-
function
|
|
6
|
-
n(!0), d !== void 0 && f(d),
|
|
4
|
+
const [t, n] = A(null), [u, f] = A(null), [b, h] = A(0);
|
|
5
|
+
function C(d) {
|
|
6
|
+
n(!0), d !== void 0 && f(d), h((S) => S + 1);
|
|
7
7
|
}
|
|
8
8
|
function o() {
|
|
9
9
|
n(!1), f(null);
|
|
@@ -16,7 +16,7 @@ function E() {
|
|
|
16
16
|
// derived
|
|
17
17
|
canAnswer: !t,
|
|
18
18
|
// actions
|
|
19
|
-
submitQuestion:
|
|
19
|
+
submitQuestion: C,
|
|
20
20
|
resetQuestion: o
|
|
21
21
|
};
|
|
22
22
|
}
|
|
@@ -42,31 +42,31 @@ function X(t) {
|
|
|
42
42
|
submitted: u,
|
|
43
43
|
isCorrect: f,
|
|
44
44
|
attempts: b,
|
|
45
|
-
resetQuestion:
|
|
46
|
-
submitQuestion:
|
|
45
|
+
resetQuestion: h,
|
|
46
|
+
submitQuestion: C
|
|
47
47
|
} = E(), [o, d] = A([]);
|
|
48
|
-
function
|
|
49
|
-
d((
|
|
48
|
+
function S(w) {
|
|
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
|
-
|
|
56
|
+
), g = J(o, w);
|
|
57
|
+
C(g);
|
|
58
58
|
}
|
|
59
|
-
function
|
|
60
|
-
d([]),
|
|
59
|
+
function Q() {
|
|
60
|
+
d([]), h();
|
|
61
61
|
}
|
|
62
62
|
return {
|
|
63
63
|
// data
|
|
64
64
|
question: t,
|
|
65
65
|
selectedIds: o,
|
|
66
66
|
// actions
|
|
67
|
-
select:
|
|
67
|
+
select: S,
|
|
68
68
|
submit: I,
|
|
69
|
-
reset:
|
|
69
|
+
reset: Q,
|
|
70
70
|
// base
|
|
71
71
|
submitted: u,
|
|
72
72
|
isCorrect: f,
|
|
@@ -80,46 +80,46 @@ function Y(t) {
|
|
|
80
80
|
submitted: u,
|
|
81
81
|
isCorrect: f,
|
|
82
82
|
attempts: b,
|
|
83
|
-
submitQuestion:
|
|
84
|
-
resetQuestion:
|
|
85
|
-
} = E(), [o, d] = A([]), [
|
|
83
|
+
submitQuestion: h,
|
|
84
|
+
resetQuestion: C
|
|
85
|
+
} = E(), [o, d] = A([]), [S, I] = A(
|
|
86
86
|
[]
|
|
87
|
-
), [
|
|
87
|
+
), [Q, 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
|
};
|
|
116
116
|
}
|
|
117
117
|
function c() {
|
|
118
118
|
const e = a();
|
|
119
|
-
return
|
|
119
|
+
return h(e.isCorrect), e;
|
|
120
120
|
}
|
|
121
121
|
function i() {
|
|
122
|
-
d([]),
|
|
122
|
+
d([]), C();
|
|
123
123
|
}
|
|
124
124
|
function r(e) {
|
|
125
125
|
const s = o.find((l) => l.sourceId === e)?.targetId;
|
|
@@ -131,21 +131,21 @@ 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,
|
|
144
144
|
targets: t.options.targets,
|
|
145
145
|
answers: o,
|
|
146
146
|
question: t,
|
|
147
|
-
availableSources:
|
|
148
|
-
availableTargets:
|
|
147
|
+
availableSources: S,
|
|
148
|
+
availableTargets: Q,
|
|
149
149
|
// base
|
|
150
150
|
submitted: u,
|
|
151
151
|
isCorrect: f,
|
|
@@ -165,14 +165,14 @@ function Z(t) {
|
|
|
165
165
|
submitted: u,
|
|
166
166
|
isCorrect: f,
|
|
167
167
|
attempts: b,
|
|
168
|
-
resetQuestion:
|
|
169
|
-
submitQuestion:
|
|
168
|
+
resetQuestion: h,
|
|
169
|
+
submitQuestion: C
|
|
170
170
|
} = E();
|
|
171
171
|
function o() {
|
|
172
|
-
|
|
172
|
+
C(!0);
|
|
173
173
|
}
|
|
174
174
|
function d() {
|
|
175
|
-
|
|
175
|
+
h();
|
|
176
176
|
}
|
|
177
177
|
return {
|
|
178
178
|
// data
|
|
@@ -195,9 +195,9 @@ function K(t) {
|
|
|
195
195
|
submitted: u,
|
|
196
196
|
isCorrect: f,
|
|
197
197
|
attempts: b,
|
|
198
|
-
submitQuestion:
|
|
199
|
-
resetQuestion:
|
|
200
|
-
} = E(), [o, d] = A([]), [
|
|
198
|
+
submitQuestion: h,
|
|
199
|
+
resetQuestion: C
|
|
200
|
+
} = E(), [o, d] = A([]), [S, I] = A(null), Q = T(() => {
|
|
201
201
|
const r = new Set(o.map((e) => e.itemId));
|
|
202
202
|
return t.options.answers.filter(
|
|
203
203
|
(e) => !r.has(String(e.id))
|
|
@@ -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,
|
|
@@ -241,10 +241,10 @@ function K(t) {
|
|
|
241
241
|
}
|
|
242
242
|
function a() {
|
|
243
243
|
const r = x();
|
|
244
|
-
return
|
|
244
|
+
return h(r.isCorrect), r;
|
|
245
245
|
}
|
|
246
246
|
function c() {
|
|
247
|
-
d([]),
|
|
247
|
+
d([]), C();
|
|
248
248
|
}
|
|
249
249
|
function i(r) {
|
|
250
250
|
const e = o.find((s) => s.blankIndex === r)?.itemId;
|
|
@@ -255,9 +255,9 @@ function K(t) {
|
|
|
255
255
|
items: t.options.answers,
|
|
256
256
|
groups: t.options.groups,
|
|
257
257
|
answers: o,
|
|
258
|
-
availableItems:
|
|
258
|
+
availableItems: Q,
|
|
259
259
|
question: t,
|
|
260
|
-
draggingItemId:
|
|
260
|
+
draggingItemId: S,
|
|
261
261
|
// base
|
|
262
262
|
submitted: u,
|
|
263
263
|
isCorrect: f,
|
|
@@ -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,
|
|
@@ -279,11 +279,11 @@ function H(t) {
|
|
|
279
279
|
submitted: u,
|
|
280
280
|
isCorrect: f,
|
|
281
281
|
attempts: b,
|
|
282
|
-
submitQuestion:
|
|
283
|
-
resetQuestion:
|
|
282
|
+
submitQuestion: h,
|
|
283
|
+
resetQuestion: C
|
|
284
284
|
} = E(), [o, d] = A(() => G(
|
|
285
285
|
t.options.answers.map((c) => String(c.id))
|
|
286
|
-
)),
|
|
286
|
+
)), S = T(() => o.map(
|
|
287
287
|
(c) => t.options.answers.find((i) => String(i.id) === c)
|
|
288
288
|
).filter((c) => c !== void 0), [o, t.options.answers]);
|
|
289
289
|
function I(c, i) {
|
|
@@ -292,7 +292,7 @@ function H(t) {
|
|
|
292
292
|
return e.splice(i, 0, s), e;
|
|
293
293
|
});
|
|
294
294
|
}
|
|
295
|
-
function
|
|
295
|
+
function Q(c) {
|
|
296
296
|
const i = o.indexOf(c);
|
|
297
297
|
i > 0 && I(i, i - 1);
|
|
298
298
|
}
|
|
@@ -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
|
}
|
|
@@ -320,16 +320,16 @@ function H(t) {
|
|
|
320
320
|
}
|
|
321
321
|
function x() {
|
|
322
322
|
const c = p();
|
|
323
|
-
return
|
|
323
|
+
return h(c.isCorrect), c;
|
|
324
324
|
}
|
|
325
325
|
function a() {
|
|
326
|
-
d(t.options.answers.map((c) => String(c.id))),
|
|
326
|
+
d(t.options.answers.map((c) => String(c.id))), C();
|
|
327
327
|
}
|
|
328
328
|
return {
|
|
329
329
|
// data
|
|
330
330
|
items: t.options.answers,
|
|
331
331
|
groups: t.options.groups,
|
|
332
|
-
orderedItems:
|
|
332
|
+
orderedItems: S,
|
|
333
333
|
orderedItemIds: o,
|
|
334
334
|
question: t,
|
|
335
335
|
// base
|
|
@@ -340,9 +340,9 @@ function H(t) {
|
|
|
340
340
|
// actions
|
|
341
341
|
setOrderedItemIds: d,
|
|
342
342
|
moveItem: I,
|
|
343
|
-
moveUp:
|
|
343
|
+
moveUp: Q,
|
|
344
344
|
moveDown: w,
|
|
345
|
-
moveToPosition:
|
|
345
|
+
moveToPosition: g,
|
|
346
346
|
submit: x,
|
|
347
347
|
reset: a
|
|
348
348
|
};
|
|
@@ -353,19 +353,19 @@ function q(t) {
|
|
|
353
353
|
submitted: u,
|
|
354
354
|
isCorrect: f,
|
|
355
355
|
attempts: b,
|
|
356
|
-
submitQuestion:
|
|
357
|
-
resetQuestion:
|
|
358
|
-
} = E(), [o, d] = A([]),
|
|
356
|
+
submitQuestion: h,
|
|
357
|
+
resetQuestion: C
|
|
358
|
+
} = E(), [o, d] = A([]), S = T(() => {
|
|
359
359
|
const i = new Set(o.map((r) => r.labelId));
|
|
360
360
|
return t.options.labels.filter(
|
|
361
361
|
(r) => !i.has(String(r.id))
|
|
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,
|
|
@@ -375,13 +375,13 @@ function q(t) {
|
|
|
375
375
|
}
|
|
376
376
|
]);
|
|
377
377
|
}
|
|
378
|
-
function
|
|
378
|
+
function Q(i) {
|
|
379
379
|
d((r) => r.filter((e) => e.labelId !== i));
|
|
380
380
|
}
|
|
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
|
}), {
|
|
@@ -411,10 +411,10 @@ function q(t) {
|
|
|
411
411
|
}
|
|
412
412
|
function a() {
|
|
413
413
|
const i = x();
|
|
414
|
-
return
|
|
414
|
+
return h(i.isCorrect), i;
|
|
415
415
|
}
|
|
416
416
|
function c() {
|
|
417
|
-
d([]),
|
|
417
|
+
d([]), C();
|
|
418
418
|
}
|
|
419
419
|
return {
|
|
420
420
|
// data
|
|
@@ -424,7 +424,7 @@ function q(t) {
|
|
|
424
424
|
imageWidth: t.image_width,
|
|
425
425
|
imageHeight: t.image_height,
|
|
426
426
|
answers: o,
|
|
427
|
-
availableLabels:
|
|
427
|
+
availableLabels: S,
|
|
428
428
|
question: t,
|
|
429
429
|
// base
|
|
430
430
|
submitted: u,
|
|
@@ -433,9 +433,9 @@ function q(t) {
|
|
|
433
433
|
canAnswer: n,
|
|
434
434
|
// actions
|
|
435
435
|
attachLabel: I,
|
|
436
|
-
removeLabel:
|
|
436
|
+
removeLabel: Q,
|
|
437
437
|
moveLabel: w,
|
|
438
|
-
getLabelAtBlank:
|
|
438
|
+
getLabelAtBlank: g,
|
|
439
439
|
getBlankForLabel: p,
|
|
440
440
|
submit: a,
|
|
441
441
|
reset: c
|
|
@@ -447,43 +447,43 @@ function tt(t) {
|
|
|
447
447
|
submitted: u,
|
|
448
448
|
isCorrect: f,
|
|
449
449
|
attempts: b,
|
|
450
|
-
submitQuestion:
|
|
451
|
-
resetQuestion:
|
|
450
|
+
submitQuestion: h,
|
|
451
|
+
resetQuestion: C
|
|
452
452
|
} = E(), [o, d] = A([]);
|
|
453
|
-
function
|
|
453
|
+
function S(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
|
-
function
|
|
482
|
-
const
|
|
483
|
-
return
|
|
481
|
+
function Q() {
|
|
482
|
+
const g = I();
|
|
483
|
+
return h(g.isCorrect), g;
|
|
484
484
|
}
|
|
485
485
|
function w() {
|
|
486
|
-
d([]),
|
|
486
|
+
d([]), C();
|
|
487
487
|
}
|
|
488
488
|
return {
|
|
489
489
|
// data
|
|
@@ -496,8 +496,8 @@ function tt(t) {
|
|
|
496
496
|
attempts: b,
|
|
497
497
|
canAnswer: n,
|
|
498
498
|
// actions
|
|
499
|
-
answer:
|
|
500
|
-
submit:
|
|
499
|
+
answer: S,
|
|
500
|
+
submit: Q,
|
|
501
501
|
reset: w
|
|
502
502
|
};
|
|
503
503
|
}
|
|
@@ -507,10 +507,10 @@ function et(t) {
|
|
|
507
507
|
submitted: u,
|
|
508
508
|
isCorrect: f,
|
|
509
509
|
attempts: b,
|
|
510
|
-
submitQuestion:
|
|
511
|
-
resetQuestion:
|
|
510
|
+
submitQuestion: h,
|
|
511
|
+
resetQuestion: C
|
|
512
512
|
} = E(), [o, d] = A([]);
|
|
513
|
-
function
|
|
513
|
+
function S(a, c) {
|
|
514
514
|
d((i) => {
|
|
515
515
|
const r = i.findIndex((e) => e.itemId === a);
|
|
516
516
|
if (r >= 0) {
|
|
@@ -523,15 +523,15 @@ function et(t) {
|
|
|
523
523
|
function I(a) {
|
|
524
524
|
d((c) => c.filter((i) => i.itemId !== a));
|
|
525
525
|
}
|
|
526
|
-
function
|
|
526
|
+
function Q() {
|
|
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,
|
|
@@ -539,11 +539,11 @@ function et(t) {
|
|
|
539
539
|
};
|
|
540
540
|
}
|
|
541
541
|
function w() {
|
|
542
|
-
const a =
|
|
543
|
-
return
|
|
542
|
+
const a = Q();
|
|
543
|
+
return h(a.isCorrect), a;
|
|
544
544
|
}
|
|
545
|
-
function
|
|
546
|
-
d([]),
|
|
545
|
+
function g() {
|
|
546
|
+
d([]), C();
|
|
547
547
|
}
|
|
548
548
|
const p = T(() => t.options.items.filter(
|
|
549
549
|
(a) => !o.some((c) => c.itemId === a.id)
|
|
@@ -571,10 +571,10 @@ function et(t) {
|
|
|
571
571
|
attempts: b,
|
|
572
572
|
canAnswer: n,
|
|
573
573
|
// actions
|
|
574
|
-
move:
|
|
574
|
+
move: S,
|
|
575
575
|
remove: I,
|
|
576
576
|
submit: w,
|
|
577
|
-
reset:
|
|
577
|
+
reset: g
|
|
578
578
|
};
|
|
579
579
|
}
|
|
580
580
|
function rt(t) {
|
|
@@ -583,14 +583,14 @@ function rt(t) {
|
|
|
583
583
|
submitted: u,
|
|
584
584
|
isCorrect: f,
|
|
585
585
|
attempts: b,
|
|
586
|
-
resetQuestion:
|
|
587
|
-
submitQuestion:
|
|
586
|
+
resetQuestion: h,
|
|
587
|
+
submitQuestion: C
|
|
588
588
|
} = E();
|
|
589
589
|
function o() {
|
|
590
|
-
u ||
|
|
590
|
+
u || C(!0);
|
|
591
591
|
}
|
|
592
592
|
function d() {
|
|
593
|
-
|
|
593
|
+
h();
|
|
594
594
|
}
|
|
595
595
|
return {
|
|
596
596
|
// data
|
|
@@ -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:
|
|
611
|
+
const { canAnswer: u, submitted: f, attempts: b, submitQuestion: h, resetQuestion: C } = E(), [o, d] = A(""), [S, I] = A(void 0), [Q, 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 {
|
|
@@ -643,12 +643,12 @@ function nt(t, n) {
|
|
|
643
643
|
() => ({
|
|
644
644
|
type: "writing",
|
|
645
645
|
text: o,
|
|
646
|
-
fileUrl:
|
|
646
|
+
fileUrl: S
|
|
647
647
|
}),
|
|
648
|
-
[o,
|
|
649
|
-
), i =
|
|
650
|
-
d(""), I(void 0), p(void 0),
|
|
651
|
-
}, [
|
|
648
|
+
[o, S]
|
|
649
|
+
), i = U(() => (h(), c), [h, c]), r = U(() => {
|
|
650
|
+
d(""), I(void 0), p(void 0), C();
|
|
651
|
+
}, [C]);
|
|
652
652
|
return {
|
|
653
653
|
question: t,
|
|
654
654
|
canAnswer: u,
|
|
@@ -656,10 +656,10 @@ function nt(t, n) {
|
|
|
656
656
|
attempts: b,
|
|
657
657
|
text: o,
|
|
658
658
|
setText: d,
|
|
659
|
-
fileUrl:
|
|
659
|
+
fileUrl: S,
|
|
660
660
|
setFileUrl: I,
|
|
661
|
-
isUploading:
|
|
662
|
-
uploadError:
|
|
661
|
+
isUploading: Q,
|
|
662
|
+
uploadError: g,
|
|
663
663
|
uploadFile: x,
|
|
664
664
|
uploadText: a,
|
|
665
665
|
submit: i,
|
|
@@ -668,12 +668,12 @@ function nt(t, n) {
|
|
|
668
668
|
};
|
|
669
669
|
}
|
|
670
670
|
function st(t, n) {
|
|
671
|
-
const { canAnswer: u, submitted: f, attempts: b, submitQuestion:
|
|
671
|
+
const { canAnswer: u, submitted: f, attempts: b, submitQuestion: h, resetQuestion: C } = E(), [o, d] = A(void 0), [S, I] = A("idle"), [Q, 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
|
-
const
|
|
675
|
-
l.current =
|
|
676
|
-
const k = new MediaRecorder(
|
|
674
|
+
const v = await navigator.mediaDevices.getUserMedia({ audio: !0 });
|
|
675
|
+
l.current = v;
|
|
676
|
+
const k = new MediaRecorder(v);
|
|
677
677
|
r.current = k, e.current = [], k.ondataavailable = (_) => {
|
|
678
678
|
_.data.size > 0 && e.current.push(_.data);
|
|
679
679
|
}, k.onstop = () => {
|
|
@@ -684,41 +684,41 @@ 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
|
-
} catch (
|
|
690
|
-
console.error("Failed to start recording:",
|
|
689
|
+
} catch (v) {
|
|
690
|
+
console.error("Failed to start recording:", v), a("Failed to access microphone");
|
|
691
691
|
}
|
|
692
|
-
}, []), y =
|
|
693
|
-
r.current &&
|
|
694
|
-
}, [
|
|
695
|
-
r.current &&
|
|
696
|
-
w((
|
|
692
|
+
}, []), y = U(() => {
|
|
693
|
+
r.current && S === "recording" && (r.current.pause(), I("paused"), s.current && clearInterval(s.current));
|
|
694
|
+
}, [S]), B = U(() => {
|
|
695
|
+
r.current && S === "paused" && (r.current.resume(), I("recording"), s.current = setInterval(() => {
|
|
696
|
+
w((v) => v + 1);
|
|
697
697
|
}, 1e3));
|
|
698
|
-
}, [
|
|
699
|
-
r.current &&
|
|
700
|
-
}, [
|
|
701
|
-
c ?
|
|
702
|
-
}, [c]), M =
|
|
698
|
+
}, [S]), R = U(() => {
|
|
699
|
+
r.current && r.current.state !== "inactive" && (r.current.stop(), i(!1), I("stopped"), s.current && clearInterval(s.current), l.current && l.current.getTracks().forEach((v) => v.stop()));
|
|
700
|
+
}, []), 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 {
|
|
706
|
-
const
|
|
706
|
+
const v = new Blob(e.current, {
|
|
707
707
|
type: "audio/webm"
|
|
708
|
-
}), k = `speaking-${Date.now()}.webm`, L = await n(
|
|
708
|
+
}), k = `speaking-${Date.now()}.webm`, L = await n(v, k);
|
|
709
709
|
L.success && L.url ? d(L.url) : a(L.error || "Upload failed");
|
|
710
|
-
} catch (
|
|
711
|
-
console.error("Upload failed:",
|
|
710
|
+
} catch (v) {
|
|
711
|
+
console.error("Upload failed:", v), a(v instanceof Error ? v.message : "Upload failed");
|
|
712
712
|
} finally {
|
|
713
713
|
p(!1);
|
|
714
714
|
}
|
|
715
715
|
}
|
|
716
|
-
}, [t, n]), D =
|
|
717
|
-
async (
|
|
716
|
+
}, [t, n]), D = U(
|
|
717
|
+
async (v) => {
|
|
718
718
|
if (n) {
|
|
719
719
|
p(!0), a(void 0);
|
|
720
720
|
try {
|
|
721
|
-
const k = await n(
|
|
721
|
+
const k = await n(v, v.name);
|
|
722
722
|
k.success && k.url ? d(k.url) : a(k.error || "Upload failed");
|
|
723
723
|
} catch (k) {
|
|
724
724
|
console.error("File upload failed:", k), a(
|
|
@@ -736,26 +736,26 @@ function st(t, n) {
|
|
|
736
736
|
audioUrl: o
|
|
737
737
|
}),
|
|
738
738
|
[t, o]
|
|
739
|
-
), $ =
|
|
740
|
-
d(void 0), I("idle"), w(0), a(void 0), e.current = [], s.current && clearInterval(s.current), l.current && l.current.getTracks().forEach((
|
|
741
|
-
}, [
|
|
739
|
+
), $ = U(() => (h(), j), [h, j]), N = U(() => {
|
|
740
|
+
d(void 0), I("idle"), w(0), a(void 0), e.current = [], s.current && clearInterval(s.current), l.current && l.current.getTracks().forEach((v) => v.stop()), C();
|
|
741
|
+
}, [C]);
|
|
742
742
|
return {
|
|
743
743
|
question: t,
|
|
744
744
|
canAnswer: u,
|
|
745
745
|
submitted: f,
|
|
746
746
|
attempts: b,
|
|
747
747
|
audioUrl: o,
|
|
748
|
-
recordingState:
|
|
749
|
-
recordingTime:
|
|
750
|
-
isUploading:
|
|
748
|
+
recordingState: S,
|
|
749
|
+
recordingTime: Q,
|
|
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,
|