@enspiredigital/xlms-headless 0.0.25 → 0.0.26

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.
@@ -16,19 +16,21 @@ export declare function useSpeaking(question: SpeakingQuestionType, uploadHandle
16
16
  submitted: boolean | null;
17
17
  attempts: number;
18
18
  audioUrl: string | undefined;
19
- setAudioUrl: import('react').Dispatch<import('react').SetStateAction<string | undefined>>;
20
19
  recordingState: RecordingState;
21
20
  recordingTime: number;
22
21
  isUploading: boolean;
23
22
  uploadError: string | undefined;
23
+ isRecording: boolean;
24
+ payload: SpeakingSubmitPayload;
25
+ setAudioUrl: import('react').Dispatch<import('react').SetStateAction<string | undefined>>;
24
26
  startRecording: () => Promise<void>;
25
27
  pauseRecording: () => void;
26
28
  resumeRecording: () => void;
27
29
  stopRecording: () => void;
30
+ toggleRecording: () => void | Promise<void>;
28
31
  uploadAudio: () => Promise<void>;
29
32
  uploadFile: (file: File) => Promise<void>;
30
33
  submit: () => SpeakingSubmitPayload;
31
34
  reset: () => void;
32
- payload: SpeakingSubmitPayload;
33
35
  };
34
36
  //# sourceMappingURL=useSpeaking.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSpeaking.d.ts","sourceRoot":"","sources":["../../src/hooks/useSpeaking.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,MAAM,qBAAqB,GAAG;IAClC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,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;;;;;;;;;;;;;;;;uBAsHtB,IAAI;;;;EAiFpB"}
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,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,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;;;;;;;;;;;;;;;;;;;uBAiItB,IAAI;;;EAmFpB"}
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import { useState as x, useRef as F, useEffect as D, useMemo as T, useCallback as B } from "react";
2
- import { jsx as j, Fragment as V } from "react/jsx-runtime";
3
- function M() {
4
- const [t, n] = x(null), [u, f] = x(null), [b, C] = x(0);
5
- function S(l) {
6
- n(!0), l !== void 0 && f(l), C((h) => h + 1);
1
+ import { useState as A, useRef as _, useEffect as V, useMemo as T, useCallback as R } from "react";
2
+ import { jsx as W, Fragment as $ } from "react/jsx-runtime";
3
+ function E() {
4
+ const [t, n] = A(null), [u, f] = A(null), [b, C] = A(0);
5
+ function S(d) {
6
+ n(!0), d !== void 0 && f(d), C((h) => h + 1);
7
7
  }
8
8
  function o() {
9
9
  n(!1), f(null);
@@ -20,7 +20,7 @@ function M() {
20
20
  resetQuestion: o
21
21
  };
22
22
  }
23
- function z(t, n) {
23
+ function J(t, n) {
24
24
  if (t.length !== n.length) return !1;
25
25
  const u = new Set(t), f = new Set(n);
26
26
  if (u.size !== f.size) return !1;
@@ -28,7 +28,7 @@ function z(t, n) {
28
28
  if (!f.has(b)) return !1;
29
29
  return !0;
30
30
  }
31
- function W(t) {
31
+ function z(t) {
32
32
  const n = [...t];
33
33
  for (let u = n.length - 1; u > 0; u--) {
34
34
  const f = Math.floor(Math.random() * (u + 1));
@@ -36,7 +36,7 @@ function W(t) {
36
36
  }
37
37
  return n;
38
38
  }
39
- function G(t) {
39
+ function X(t) {
40
40
  const {
41
41
  canAnswer: n,
42
42
  submitted: u,
@@ -44,20 +44,20 @@ function G(t) {
44
44
  attempts: b,
45
45
  resetQuestion: C,
46
46
  submitQuestion: S
47
- } = M(), [o, l] = x([]);
47
+ } = E(), [o, d] = A([]);
48
48
  function h(w) {
49
- l((m) => t.options.allowMultipleAnswers ? m.includes(w) ? m.filter((p) => p !== w) : [...m, w] : [w]);
49
+ d((m) => t.options.allowMultipleAnswers ? m.includes(w) ? m.filter((p) => p !== w) : [...m, w] : [w]);
50
50
  }
51
51
  function I() {
52
52
  if (o.length === 0) return;
53
53
  const w = t.options.answers.reduce(
54
- (p, A) => (A.is_correct && p.push(A.id), p),
54
+ (p, x) => (x.is_correct && p.push(x.id), p),
55
55
  []
56
- ), m = z(o, w);
56
+ ), m = J(o, w);
57
57
  S(m);
58
58
  }
59
59
  function v() {
60
- l([]), C();
60
+ d([]), C();
61
61
  }
62
62
  return {
63
63
  // data
@@ -74,7 +74,7 @@ function G(t) {
74
74
  canAnswer: n
75
75
  };
76
76
  }
77
- function N(t) {
77
+ function Y(t) {
78
78
  const {
79
79
  canAnswer: n,
80
80
  submitted: u,
@@ -82,62 +82,62 @@ function N(t) {
82
82
  attempts: b,
83
83
  submitQuestion: C,
84
84
  resetQuestion: S
85
- } = M(), [o, l] = x([]), [h, I] = x(
85
+ } = E(), [o, d] = A([]), [h, I] = A(
86
86
  []
87
- ), [v, w] = x(
87
+ ), [v, w] = A(
88
88
  []
89
- ), m = F([]);
90
- function p(e, c) {
91
- l((d) => [
92
- ...d.filter(
93
- (g) => g.targetId !== e && g.sourceId !== c
89
+ ), m = _([]);
90
+ function p(e, s) {
91
+ d((l) => [
92
+ ...l.filter(
93
+ (g) => g.targetId !== e && g.sourceId !== s
94
94
  ),
95
- { targetId: e, sourceId: c }
95
+ { targetId: e, sourceId: s }
96
96
  ]);
97
97
  }
98
- function A(e, c) {
99
- l(
100
- (d) => d.filter((g) => g.targetId !== e || g.sourceId !== c)
98
+ function x(e, s) {
99
+ d(
100
+ (l) => l.filter((g) => g.targetId !== e || g.sourceId !== s)
101
101
  );
102
102
  }
103
103
  function a() {
104
- let e = 0, c = !0;
105
- return t.options.targets.forEach((d) => {
106
- const g = o.find((U) => U.targetId === d.id), y = t.options.sources[d.content.correct_position - 1];
107
- g && y && g.sourceId === y.id ? e += d.content.point : c = !1;
104
+ let e = 0, s = !0;
105
+ return t.options.targets.forEach((l) => {
106
+ const g = o.find((U) => U.targetId === l.id), y = t.options.sources[l.content.correct_position - 1];
107
+ g && y && g.sourceId === y.id ? e += l.content.point : s = !1;
108
108
  }), {
109
- isCorrect: c,
109
+ isCorrect: s,
110
110
  score: e,
111
111
  maxScore: t.options.targets.reduce(
112
- (d, g) => d + g.content.point,
112
+ (l, g) => l + g.content.point,
113
113
  0
114
114
  )
115
115
  };
116
116
  }
117
- function i() {
117
+ function c() {
118
118
  const e = a();
119
119
  return C(e.isCorrect), e;
120
120
  }
121
- function s() {
122
- l([]), S();
121
+ function i() {
122
+ d([]), S();
123
123
  }
124
124
  function r(e) {
125
- const c = o.find((d) => d.sourceId === e)?.targetId;
126
- return t.options.targets.find((d) => d.id === c);
125
+ const s = o.find((l) => l.sourceId === e)?.targetId;
126
+ return t.options.targets.find((l) => l.id === s);
127
127
  }
128
- return D(() => {
128
+ return V(() => {
129
129
  const e = t.options.sources.filter(
130
- (c) => !o.some((d) => d.sourceId === c.id)
130
+ (s) => !o.some((l) => l.sourceId === s.id)
131
131
  );
132
132
  I(e);
133
- }, [o, t.options.sources]), D(() => {
133
+ }, [o, t.options.sources]), V(() => {
134
134
  if (m.current.length === 0) return;
135
135
  const e = m.current.filter(
136
- (c) => !o.some((d) => d.targetId === c.id)
136
+ (s) => !o.some((l) => l.targetId === s.id)
137
137
  );
138
138
  w(e);
139
- }, [o]), D(() => {
140
- m.current = W(t.options.targets);
139
+ }, [o]), V(() => {
140
+ m.current = z(t.options.targets);
141
141
  }, [t.options.targets]), {
142
142
  // data
143
143
  sources: t.options.sources,
@@ -154,12 +154,12 @@ function N(t) {
154
154
  // actions
155
155
  getTargetBySourceId: r,
156
156
  select: p,
157
- remove: A,
158
- submit: i,
159
- reset: s
157
+ remove: x,
158
+ submit: c,
159
+ reset: i
160
160
  };
161
161
  }
162
- function P(t) {
162
+ function Z(t) {
163
163
  const {
164
164
  canAnswer: n,
165
165
  submitted: u,
@@ -167,11 +167,11 @@ function P(t) {
167
167
  attempts: b,
168
168
  resetQuestion: C,
169
169
  submitQuestion: S
170
- } = M();
170
+ } = E();
171
171
  function o() {
172
172
  S(!0);
173
173
  }
174
- function l() {
174
+ function d() {
175
175
  C();
176
176
  }
177
177
  return {
@@ -181,7 +181,7 @@ function P(t) {
181
181
  type: t.options.urlType,
182
182
  // actions
183
183
  submit: o,
184
- reset: l,
184
+ reset: d,
185
185
  // base
186
186
  submitted: u,
187
187
  isCorrect: f,
@@ -189,7 +189,7 @@ function P(t) {
189
189
  canAnswer: n
190
190
  };
191
191
  }
192
- function J(t) {
192
+ function K(t) {
193
193
  const {
194
194
  canAnswer: n,
195
195
  submitted: u,
@@ -197,15 +197,15 @@ function J(t) {
197
197
  attempts: b,
198
198
  submitQuestion: C,
199
199
  resetQuestion: S
200
- } = M(), [o, l] = x([]), [h, I] = x(null), v = T(() => {
200
+ } = E(), [o, d] = A([]), [h, I] = A(null), v = 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))
204
204
  );
205
205
  }, [o, t.options.answers]);
206
206
  function w(r, e) {
207
- l((c) => [
208
- ...c.filter(
207
+ d((s) => [
208
+ ...s.filter(
209
209
  (g) => g.blankIndex !== e && g.itemId !== r
210
210
  ),
211
211
  {
@@ -215,40 +215,40 @@ function J(t) {
215
215
  ]);
216
216
  }
217
217
  function m(r) {
218
- l((e) => e.filter((c) => c.itemId !== r));
218
+ d((e) => e.filter((s) => s.itemId !== r));
219
219
  }
220
220
  function p(r, e) {
221
221
  w(r, e);
222
222
  }
223
- function A() {
224
- let r = 0, e = !0, c = 0;
225
- const d = t.correct_answers.list, g = new Map(o.map((y) => [y.blankIndex, y.itemId]));
226
- return Object.entries(d).forEach(([y, U]) => {
227
- const R = y, L = g.get(R);
223
+ function x() {
224
+ let r = 0, e = !0, s = 0;
225
+ const l = t.correct_answers.list, g = new Map(o.map((y) => [y.blankIndex, y.itemId]));
226
+ return Object.entries(l).forEach(([y, U]) => {
227
+ const B = y, L = g.get(B);
228
228
  if (!L) {
229
229
  e = !1;
230
230
  return;
231
231
  }
232
- const O = t.options.answers.find((_) => _.id === L);
233
- O && String(O.group_position) === String(U) ? (r++, c += O.point) : e = !1;
232
+ const M = t.options.answers.find((D) => D.id === L);
233
+ M && String(M.group_position) === String(U) ? (r++, s += M.point) : e = !1;
234
234
  }), {
235
235
  isCorrect: e,
236
236
  correctCount: r,
237
- totalCount: Object.keys(d).length,
237
+ totalCount: Object.keys(l).length,
238
238
  maxScore: t.metadata.points,
239
- score: c
239
+ score: s
240
240
  };
241
241
  }
242
242
  function a() {
243
- const r = A();
243
+ const r = x();
244
244
  return C(r.isCorrect), r;
245
245
  }
246
- function i() {
247
- l([]), S();
246
+ function c() {
247
+ d([]), S();
248
248
  }
249
- function s(r) {
250
- const e = o.find((c) => c.blankIndex === r)?.itemId;
251
- return t.options.answers.find((c) => c.id === e);
249
+ function i(r) {
250
+ const e = o.find((s) => s.blankIndex === r)?.itemId;
251
+ return t.options.answers.find((s) => s.id === e);
252
252
  }
253
253
  return {
254
254
  // data
@@ -268,12 +268,12 @@ function J(t) {
268
268
  removeItem: m,
269
269
  moveItem: p,
270
270
  setDraggingItemId: I,
271
- getItemByBlankId: s,
271
+ getItemByBlankId: i,
272
272
  submit: a,
273
- reset: i
273
+ reset: c
274
274
  };
275
275
  }
276
- function X(t) {
276
+ function H(t) {
277
277
  const {
278
278
  canAnswer: n,
279
279
  submitted: u,
@@ -281,49 +281,49 @@ function X(t) {
281
281
  attempts: b,
282
282
  submitQuestion: C,
283
283
  resetQuestion: S
284
- } = M(), [o, l] = x(() => W(
285
- t.options.answers.map((i) => String(i.id))
284
+ } = E(), [o, d] = A(() => z(
285
+ t.options.answers.map((c) => String(c.id))
286
286
  )), h = T(() => o.map(
287
- (i) => t.options.answers.find((s) => String(s.id) === i)
288
- ).filter((i) => i !== void 0), [o, t.options.answers]);
289
- function I(i, s) {
290
- l((r) => {
291
- const e = [...r], [c] = e.splice(i, 1);
292
- return e.splice(s, 0, c), e;
287
+ (c) => t.options.answers.find((i) => String(i.id) === c)
288
+ ).filter((c) => c !== void 0), [o, t.options.answers]);
289
+ function I(c, i) {
290
+ d((r) => {
291
+ const e = [...r], [s] = e.splice(c, 1);
292
+ return e.splice(i, 0, s), e;
293
293
  });
294
294
  }
295
- function v(i) {
296
- const s = o.indexOf(i);
297
- s > 0 && I(s, s - 1);
295
+ function v(c) {
296
+ const i = o.indexOf(c);
297
+ i > 0 && I(i, i - 1);
298
298
  }
299
- function w(i) {
300
- const s = o.indexOf(i);
301
- s < o.length - 1 && I(s, s + 1);
299
+ function w(c) {
300
+ const i = o.indexOf(c);
301
+ i < o.length - 1 && I(i, i + 1);
302
302
  }
303
- function m(i, s) {
304
- const r = o.indexOf(i);
305
- r !== -1 && s >= 0 && s < o.length && I(r, s);
303
+ function m(c, i) {
304
+ const r = o.indexOf(c);
305
+ r !== -1 && i >= 0 && i < o.length && I(r, i);
306
306
  }
307
307
  function p() {
308
- let i = 0, s = !0;
308
+ let c = 0, i = !0;
309
309
  return t.options.answers.forEach((r, e) => {
310
- const c = o.indexOf(String(r.id));
311
- c !== -1 && c + 1 === r.correct_position ? i += r.point : s = !1;
310
+ const s = o.indexOf(String(r.id));
311
+ s !== -1 && s + 1 === r.correct_position ? c += r.point : i = !1;
312
312
  }), {
313
- isCorrect: s,
314
- score: i,
313
+ isCorrect: i,
314
+ score: c,
315
315
  maxScore: t.options.answers.reduce(
316
316
  (r, e) => r + e.point,
317
317
  0
318
318
  )
319
319
  };
320
320
  }
321
- function A() {
322
- const i = p();
323
- return C(i.isCorrect), i;
321
+ function x() {
322
+ const c = p();
323
+ return C(c.isCorrect), c;
324
324
  }
325
325
  function a() {
326
- l(t.options.answers.map((i) => String(i.id))), S();
326
+ d(t.options.answers.map((c) => String(c.id))), S();
327
327
  }
328
328
  return {
329
329
  // data
@@ -338,16 +338,16 @@ function X(t) {
338
338
  attempts: b,
339
339
  canAnswer: n,
340
340
  // actions
341
- setOrderedItemIds: l,
341
+ setOrderedItemIds: d,
342
342
  moveItem: I,
343
343
  moveUp: v,
344
344
  moveDown: w,
345
345
  moveToPosition: m,
346
- submit: A,
346
+ submit: x,
347
347
  reset: a
348
348
  };
349
349
  }
350
- function Y(t) {
350
+ function q(t) {
351
351
  const {
352
352
  canAnswer: n,
353
353
  submitted: u,
@@ -355,66 +355,66 @@ function Y(t) {
355
355
  attempts: b,
356
356
  submitQuestion: C,
357
357
  resetQuestion: S
358
- } = M(), [o, l] = x([]), h = T(() => {
359
- const s = new Set(o.map((r) => r.labelId));
358
+ } = E(), [o, d] = A([]), h = T(() => {
359
+ const i = new Set(o.map((r) => r.labelId));
360
360
  return t.options.labels.filter(
361
- (r) => !s.has(String(r.id))
361
+ (r) => !i.has(String(r.id))
362
362
  );
363
363
  }, [o, t.options.labels]);
364
- function I(s, r, e, c) {
365
- const d = t.options.blanks.find((g) => String(g.id) === r);
366
- d && l((g) => [
364
+ function I(i, r, e, s) {
365
+ const l = t.options.blanks.find((g) => String(g.id) === r);
366
+ l && d((g) => [
367
367
  ...g.filter(
368
- (U) => U.labelId !== s && U.blankId !== r
368
+ (U) => U.labelId !== i && U.blankId !== r
369
369
  ),
370
370
  {
371
- labelId: s,
371
+ labelId: i,
372
372
  blankId: r,
373
- x: e ?? d.coordinates.x,
374
- y: c ?? d.coordinates.y
373
+ x: e ?? l.coordinates.x,
374
+ y: s ?? l.coordinates.y
375
375
  }
376
376
  ]);
377
377
  }
378
- function v(s) {
379
- l((r) => r.filter((e) => e.labelId !== s));
378
+ function v(i) {
379
+ d((r) => r.filter((e) => e.labelId !== i));
380
380
  }
381
- function w(s, r, e, c) {
382
- I(s, r, e, c);
381
+ function w(i, r, e, s) {
382
+ I(i, r, e, s);
383
383
  }
384
- function m(s) {
385
- const r = o.find((e) => e.blankId === s);
384
+ function m(i) {
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
388
388
  ) || null;
389
389
  }
390
- function p(s) {
391
- const r = o.find((e) => e.labelId === s);
390
+ function p(i) {
391
+ const r = o.find((e) => e.labelId === i);
392
392
  return r ? r.blankId : null;
393
393
  }
394
- function A() {
395
- let s = 0, r = !0;
394
+ function x() {
395
+ let i = 0, r = !0;
396
396
  return t.options.labels.forEach((e) => {
397
- const c = o.find(
397
+ const s = o.find(
398
398
  (g) => String(g.labelId) === String(e.id)
399
- ), d = t.options.blanks.find(
399
+ ), l = t.options.blanks.find(
400
400
  (g, y) => y + 1 === e.correct_position
401
401
  );
402
- c && d && c.blankId === String(d.id) ? s += e.point : r = !1;
402
+ s && l && s.blankId === String(l.id) ? i += e.point : r = !1;
403
403
  }), {
404
404
  isCorrect: r,
405
- score: s,
405
+ score: i,
406
406
  maxScore: t.options.labels.reduce(
407
- (e, c) => e + c.point,
407
+ (e, s) => e + s.point,
408
408
  0
409
409
  )
410
410
  };
411
411
  }
412
412
  function a() {
413
- const s = A();
414
- return C(s.isCorrect), s;
413
+ const i = x();
414
+ return C(i.isCorrect), i;
415
415
  }
416
- function i() {
417
- l([]), S();
416
+ function c() {
417
+ d([]), S();
418
418
  }
419
419
  return {
420
420
  // data
@@ -438,10 +438,10 @@ function Y(t) {
438
438
  getLabelAtBlank: m,
439
439
  getBlankForLabel: p,
440
440
  submit: a,
441
- reset: i
441
+ reset: c
442
442
  };
443
443
  }
444
- function Z(t) {
444
+ function tt(t) {
445
445
  const {
446
446
  canAnswer: n,
447
447
  submitted: u,
@@ -449,33 +449,33 @@ function Z(t) {
449
449
  attempts: b,
450
450
  submitQuestion: C,
451
451
  resetQuestion: S
452
- } = M(), [o, l] = x([]);
452
+ } = E(), [o, d] = A([]);
453
453
  function h(m, p) {
454
- l((A) => {
455
- const a = A.findIndex((i) => i.blankId === m);
454
+ d((x) => {
455
+ const a = x.findIndex((c) => c.blankId === m);
456
456
  if (a >= 0) {
457
- const i = [...A];
458
- return i[a] = { blankId: m, value: p }, i;
457
+ const c = [...x];
458
+ return c[a] = { blankId: m, value: p }, c;
459
459
  }
460
- return [...A, { blankId: m, value: p }];
460
+ return [...x, { blankId: m, value: p }];
461
461
  });
462
462
  }
463
463
  function I() {
464
- let m = 0, p = 0, A = 0;
465
- const a = t.correct_answers.list || {}, i = Object.keys(a).length;
464
+ let m = 0, p = 0, x = 0;
465
+ const a = t.correct_answers.list || {}, c = Object.keys(a).length;
466
466
  Object.entries(a).forEach(([r, e]) => {
467
- const c = String(e).trim().toLowerCase(), d = t.options.answers.find(
468
- (R) => R.correct_position === Number(r)
469
- ), g = d && d.point || 1;
470
- A += g;
471
- const y = o.find((R) => R.blankId === r);
472
- (y ? String(y.value).trim().toLowerCase() : "") === c && (m += g, p++);
467
+ const s = String(e).trim().toLowerCase(), l = t.options.answers.find(
468
+ (B) => B.correct_position === Number(r)
469
+ ), g = l && l.point || 1;
470
+ x += g;
471
+ const y = o.find((B) => B.blankId === r);
472
+ (y ? String(y.value).trim().toLowerCase() : "") === s && (m += g, p++);
473
473
  });
474
- const s = p === i && i > 0;
475
- return A === 0 && i > 0 && (A = i), {
476
- isCorrect: s,
474
+ const i = p === c && c > 0;
475
+ return x === 0 && c > 0 && (x = c), {
476
+ isCorrect: i,
477
477
  score: Math.round(m * 100) / 100,
478
- maxScore: Math.round(A * 100) / 100
478
+ maxScore: Math.round(x * 100) / 100
479
479
  };
480
480
  }
481
481
  function v() {
@@ -483,7 +483,7 @@ function Z(t) {
483
483
  return C(m.isCorrect), m;
484
484
  }
485
485
  function w() {
486
- l([]), S();
486
+ d([]), S();
487
487
  }
488
488
  return {
489
489
  // data
@@ -501,7 +501,7 @@ function Z(t) {
501
501
  reset: w
502
502
  };
503
503
  }
504
- function K(t) {
504
+ function et(t) {
505
505
  const {
506
506
  canAnswer: n,
507
507
  submitted: u,
@@ -509,33 +509,33 @@ function K(t) {
509
509
  attempts: b,
510
510
  submitQuestion: C,
511
511
  resetQuestion: S
512
- } = M(), [o, l] = x([]);
513
- function h(a, i) {
514
- l((s) => {
515
- const r = s.findIndex((e) => e.itemId === a);
512
+ } = E(), [o, d] = A([]);
513
+ function h(a, c) {
514
+ d((i) => {
515
+ const r = i.findIndex((e) => e.itemId === a);
516
516
  if (r >= 0) {
517
- const e = [...s];
518
- return e[r] = { itemId: a, categoryId: i }, e;
517
+ const e = [...i];
518
+ return e[r] = { itemId: a, categoryId: c }, e;
519
519
  }
520
- return [...s, { itemId: a, categoryId: i }];
520
+ return [...i, { itemId: a, categoryId: c }];
521
521
  });
522
522
  }
523
523
  function I(a) {
524
- l((i) => i.filter((s) => s.itemId !== a));
524
+ d((c) => c.filter((i) => i.itemId !== a));
525
525
  }
526
526
  function v() {
527
- let a = 0, i = 0;
527
+ let a = 0, c = 0;
528
528
  const r = t.correct_answers.list || {}, e = Object.keys(r).length;
529
- let c = 0;
529
+ let s = 0;
530
530
  return Object.entries(r).forEach(([g, y]) => {
531
- const U = t.options.items.find((O) => O.id === g), R = U ? U.point : 0;
532
- c += R;
533
- const L = o.find((O) => O.itemId === g);
534
- L && L.categoryId === y && (a += R, i++);
535
- }), a = Math.round(a * 100) / 100, c = Math.round(c * 100) / 100, {
536
- isCorrect: i === e && e > 0,
531
+ const U = t.options.items.find((M) => M.id === g), B = U ? U.point : 0;
532
+ s += B;
533
+ const L = o.find((M) => M.itemId === g);
534
+ L && L.categoryId === y && (a += B, c++);
535
+ }), a = Math.round(a * 100) / 100, s = Math.round(s * 100) / 100, {
536
+ isCorrect: c === e && e > 0,
537
537
  score: a,
538
- maxScore: c
538
+ maxScore: s
539
539
  };
540
540
  }
541
541
  function w() {
@@ -543,17 +543,17 @@ function K(t) {
543
543
  return C(a.isCorrect), a;
544
544
  }
545
545
  function m() {
546
- l([]), S();
546
+ d([]), S();
547
547
  }
548
548
  const p = T(() => t.options.items.filter(
549
- (a) => !o.some((i) => i.itemId === a.id)
550
- ), [t.options.items, o]), A = T(() => t.options.categories.map((a) => {
551
- const i = o.filter((s) => s.categoryId === a.id).map((s) => ({
552
- ...t.options.items.find((e) => e.id === s.itemId)
549
+ (a) => !o.some((c) => c.itemId === a.id)
550
+ ), [t.options.items, o]), x = T(() => t.options.categories.map((a) => {
551
+ const c = o.filter((i) => i.categoryId === a.id).map((i) => ({
552
+ ...t.options.items.find((e) => e.id === i.itemId)
553
553
  }));
554
554
  return {
555
555
  ...a,
556
- items: i
556
+ items: c
557
557
  };
558
558
  }), [t.options.categories, t.options.items, o]);
559
559
  return {
@@ -561,7 +561,7 @@ function K(t) {
561
561
  categories: t.options.categories,
562
562
  allItems: t.options.items,
563
563
  question: t,
564
- categoriesWithItems: A,
564
+ categoriesWithItems: x,
565
565
  // state
566
566
  answers: o,
567
567
  unassignedItems: p,
@@ -577,7 +577,7 @@ function K(t) {
577
577
  reset: m
578
578
  };
579
579
  }
580
- function H(t) {
580
+ function rt(t) {
581
581
  const {
582
582
  canAnswer: n,
583
583
  submitted: u,
@@ -585,11 +585,11 @@ function H(t) {
585
585
  attempts: b,
586
586
  resetQuestion: C,
587
587
  submitQuestion: S
588
- } = M();
588
+ } = E();
589
589
  function o() {
590
590
  u || S(!0);
591
591
  }
592
- function l() {
592
+ function d() {
593
593
  C();
594
594
  }
595
595
  return {
@@ -599,7 +599,7 @@ function H(t) {
599
599
  type: t.options.urlType,
600
600
  // actions
601
601
  submit: o,
602
- reset: l,
602
+ reset: d,
603
603
  // base
604
604
  submitted: u,
605
605
  isCorrect: f,
@@ -607,17 +607,17 @@ function H(t) {
607
607
  canAnswer: n
608
608
  };
609
609
  }
610
- function q(t, n) {
611
- const { canAnswer: u, submitted: f, attempts: b, submitQuestion: C, resetQuestion: S } = M(), [o, l] = x(""), [h, I] = x(void 0), [v, w] = x(!1), [m, p] = x(void 0), A = B(
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), [m, p] = A(void 0), x = R(
612
612
  async (e) => {
613
613
  if (n) {
614
614
  w(!0), p(void 0);
615
615
  try {
616
- const c = await n(e, e.name);
617
- c.success && c.url ? I(c.url) : p(c.error || "Upload failed");
618
- } catch (c) {
619
- console.error("File upload failed:", c), p(
620
- c instanceof Error ? c.message : "File upload failed"
616
+ const s = await n(e, e.name);
617
+ s.success && s.url ? I(s.url) : p(s.error || "Upload failed");
618
+ } catch (s) {
619
+ console.error("File upload failed:", s), p(
620
+ s instanceof Error ? s.message : "File upload failed"
621
621
  );
622
622
  } finally {
623
623
  w(!1);
@@ -625,12 +625,12 @@ function q(t, n) {
625
625
  }
626
626
  },
627
627
  [n]
628
- ), a = B(async () => {
628
+ ), a = R(async () => {
629
629
  if (!(!n || !o)) {
630
630
  w(!0), p(void 0);
631
631
  try {
632
- const e = new Blob([o], { type: "text/plain; charset=utf-8" }), c = `writing-${t.id}-${Date.now()}.txt`, d = await n(e, c);
633
- d.success && d.url ? I(d.url) : p(d.error || "Upload failed");
632
+ const e = new Blob([o], { type: "text/plain; charset=utf-8" }), s = `writing-${t.id}-${Date.now()}.txt`, l = await n(e, s);
633
+ l.success && l.url ? I(l.url) : p(l.error || "Upload failed");
634
634
  } catch (e) {
635
635
  console.error("Text upload failed:", e), p(
636
636
  e instanceof Error ? e.message : "Text upload failed"
@@ -639,7 +639,7 @@ function q(t, n) {
639
639
  w(!1);
640
640
  }
641
641
  }
642
- }, [o, t.id, n]), i = T(
642
+ }, [o, t.id, n]), c = T(
643
643
  () => ({
644
644
  questionId: t.id || "",
645
645
  type: "writing",
@@ -647,8 +647,8 @@ function q(t, n) {
647
647
  fileUrl: h
648
648
  }),
649
649
  [t.id, o, h]
650
- ), s = B(() => (C(), i), [C, i]), r = B(() => {
651
- l(""), I(void 0), p(void 0), S();
650
+ ), i = R(() => (C(), c), [C, c]), r = R(() => {
651
+ d(""), I(void 0), p(void 0), S();
652
652
  }, [S]);
653
653
  return {
654
654
  question: t,
@@ -656,66 +656,69 @@ function q(t, n) {
656
656
  submitted: f,
657
657
  attempts: b,
658
658
  text: o,
659
- setText: l,
659
+ setText: d,
660
660
  fileUrl: h,
661
661
  setFileUrl: I,
662
662
  isUploading: v,
663
663
  uploadError: m,
664
- uploadFile: A,
664
+ uploadFile: x,
665
665
  uploadText: a,
666
- submit: s,
666
+ submit: i,
667
667
  reset: r,
668
- payload: i
668
+ payload: c
669
669
  };
670
670
  }
671
- function tt(t, n) {
672
- const { canAnswer: u, submitted: f, attempts: b, submitQuestion: C, resetQuestion: S } = M(), [o, l] = x(void 0), [h, I] = x("idle"), [v, w] = x(0), [m, p] = x(!1), [A, a] = x(void 0), i = F(null), s = F([]), r = F(null), e = F(null), c = B(async () => {
671
+ function st(t, n) {
672
+ 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), [m, p] = A(!1), [x, a] = A(void 0), [c, i] = A(!1), r = _(null), e = _([]), s = _(null), l = _(null), g = R(async () => {
673
+ i(!0);
673
674
  try {
674
675
  const Q = await navigator.mediaDevices.getUserMedia({ audio: !0 });
675
- e.current = Q;
676
+ l.current = Q;
676
677
  const k = new MediaRecorder(Q);
677
- i.current = k, s.current = [], k.ondataavailable = (E) => {
678
- E.data.size > 0 && s.current.push(E.data);
678
+ r.current = k, e.current = [], k.ondataavailable = (F) => {
679
+ F.data.size > 0 && e.current.push(F.data);
679
680
  }, k.onstop = () => {
680
- const E = new Blob(s.current, {
681
+ const F = new Blob(e.current, {
681
682
  type: "audio/webm"
682
- }), $ = URL.createObjectURL(E);
683
- l($);
684
- }, k.start(), I("recording"), w(0), r.current = setInterval(() => {
685
- w((E) => E + 1);
683
+ }), P = URL.createObjectURL(F);
684
+ d(P);
685
+ }, k.start(), I("recording"), w(0);
686
+ let O = 0;
687
+ s.current = setInterval(() => {
688
+ O++, w((F) => F + 1), O >= (t.metadata?.max_recording_time || 300) && B();
686
689
  }, 1e3);
687
690
  } catch (Q) {
688
691
  console.error("Failed to start recording:", Q), a("Failed to access microphone");
689
692
  }
690
- }, []), d = B(() => {
691
- i.current && h === "recording" && (i.current.pause(), I("paused"), r.current && clearInterval(r.current));
692
- }, [h]), g = B(() => {
693
- i.current && h === "paused" && (i.current.resume(), I("recording"), r.current = setInterval(() => {
693
+ }, []), y = R(() => {
694
+ r.current && h === "recording" && (r.current.pause(), I("paused"), s.current && clearInterval(s.current));
695
+ }, [h]), U = R(() => {
696
+ r.current && h === "paused" && (r.current.resume(), I("recording"), s.current = setInterval(() => {
694
697
  w((Q) => Q + 1);
695
698
  }, 1e3));
696
- }, [h]), y = B(() => {
697
- i.current && h !== "idle" && (i.current.stop(), I("stopped"), r.current && clearInterval(r.current), e.current && e.current.getTracks().forEach((Q) => Q.stop()));
698
- }, [h]), U = B(async () => {
699
- if (!(!s.current.length || !n)) {
699
+ }, [h]), B = R(() => {
700
+ r.current && h !== "idle" && (r.current.stop(), I("stopped"), s.current && clearInterval(s.current), l.current && l.current.getTracks().forEach((Q) => Q.stop()), i(!1));
701
+ }, [h]), L = R(() => c ? B() : g(), []), M = R(async () => {
702
+ if (!(!e.current.length || !n)) {
700
703
  p(!0), a(void 0);
701
704
  try {
702
- const Q = new Blob(s.current, {
705
+ const Q = new Blob(e.current, {
703
706
  type: "audio/webm"
704
- }), k = `speaking-${t.id}-${Date.now()}.webm`, E = await n(Q, k);
705
- E.success && E.url ? l(E.url) : a(E.error || "Upload failed");
707
+ }), k = `speaking-${t.id}-${Date.now()}.webm`, O = await n(Q, k);
708
+ O.success && O.url ? d(O.url) : a(O.error || "Upload failed");
706
709
  } catch (Q) {
707
710
  console.error("Upload failed:", Q), a(Q instanceof Error ? Q.message : "Upload failed");
708
711
  } finally {
709
712
  p(!1);
710
713
  }
711
714
  }
712
- }, [t.id, n]), R = B(
715
+ }, [t.id, n]), D = R(
713
716
  async (Q) => {
714
717
  if (n) {
715
718
  p(!0), a(void 0);
716
719
  try {
717
720
  const k = await n(Q, Q.name);
718
- k.success && k.url ? l(k.url) : a(k.error || "Upload failed");
721
+ k.success && k.url ? d(k.url) : a(k.error || "Upload failed");
719
722
  } catch (k) {
720
723
  console.error("File upload failed:", k), a(
721
724
  k instanceof Error ? k.message : "File upload failed"
@@ -726,15 +729,15 @@ function tt(t, n) {
726
729
  }
727
730
  },
728
731
  [n]
729
- ), L = T(
732
+ ), j = T(
730
733
  () => ({
731
734
  questionId: t.id || "",
732
735
  type: "speaking",
733
736
  audioUrl: o
734
737
  }),
735
738
  [t.id, o]
736
- ), O = B(() => (C(), L), [C, L]), _ = B(() => {
737
- l(void 0), I("idle"), w(0), a(void 0), s.current = [], r.current && clearInterval(r.current), e.current && e.current.getTracks().forEach((Q) => Q.stop()), S();
739
+ ), G = R(() => (C(), j), [C, j]), N = R(() => {
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();
738
741
  }, [S]);
739
742
  return {
740
743
  question: t,
@@ -742,125 +745,127 @@ function tt(t, n) {
742
745
  submitted: f,
743
746
  attempts: b,
744
747
  audioUrl: o,
745
- setAudioUrl: l,
746
748
  recordingState: h,
747
749
  recordingTime: v,
748
750
  isUploading: m,
749
- uploadError: A,
750
- startRecording: c,
751
- pauseRecording: d,
752
- resumeRecording: g,
753
- stopRecording: y,
754
- uploadAudio: U,
755
- uploadFile: R,
756
- submit: O,
757
- reset: _,
758
- payload: L
751
+ uploadError: x,
752
+ isRecording: c,
753
+ payload: j,
754
+ setAudioUrl: d,
755
+ startRecording: g,
756
+ pauseRecording: y,
757
+ resumeRecording: U,
758
+ stopRecording: B,
759
+ toggleRecording: L,
760
+ uploadAudio: M,
761
+ uploadFile: D,
762
+ submit: G,
763
+ reset: N
759
764
  };
760
765
  }
761
- function nt({
766
+ function ct({
762
767
  getData: t,
763
768
  children: n
764
769
  }) {
765
- const u = G(t());
770
+ const u = X(t());
766
771
  return n(u);
767
772
  }
768
- function st({
773
+ function ut({
769
774
  getData: t,
770
775
  children: n
771
776
  }) {
772
- const u = N(t());
777
+ const u = Y(t());
773
778
  return n(u);
774
779
  }
775
- function ot({
780
+ function at({
776
781
  getData: t,
777
782
  children: n
778
783
  }) {
779
- const u = P(t());
784
+ const u = Z(t());
780
785
  return n(u);
781
786
  }
782
- function it({
787
+ function lt({
783
788
  getData: t,
784
789
  children: n
785
790
  }) {
786
- const u = J(t());
791
+ const u = K(t());
787
792
  return n(u);
788
793
  }
789
- function ct({
794
+ function dt({
790
795
  getData: t,
791
796
  children: n
792
797
  }) {
793
- const u = X(t());
798
+ const u = H(t());
794
799
  return n(u);
795
800
  }
796
- function ut({
801
+ function ft({
797
802
  getData: t,
798
803
  children: n
799
804
  }) {
800
- const u = Y(t());
805
+ const u = q(t());
801
806
  return n(u);
802
807
  }
803
- function at({
808
+ function pt({
804
809
  getData: t,
805
810
  children: n
806
811
  }) {
807
- const u = Z(t());
812
+ const u = tt(t());
808
813
  return n(u);
809
814
  }
810
- function lt({
815
+ function mt({
811
816
  getData: t,
812
817
  children: n
813
818
  }) {
814
- const u = K(t());
819
+ const u = et(t());
815
820
  return n(u);
816
821
  }
817
- function dt({
822
+ function gt({
818
823
  getData: t,
819
824
  children: n
820
825
  }) {
821
- const u = H(t());
826
+ const u = rt(t());
822
827
  return n(u);
823
828
  }
824
- function ft({
829
+ function bt({
825
830
  getData: t,
826
831
  children: n,
827
832
  uploadHandler: u
828
833
  }) {
829
- const f = t(), b = q(f, u);
830
- return /* @__PURE__ */ j(V, { children: n(b) });
834
+ const f = t(), b = nt(f, u);
835
+ return /* @__PURE__ */ W($, { children: n(b) });
831
836
  }
832
- function pt({
837
+ function wt({
833
838
  getData: t,
834
839
  children: n,
835
840
  uploadHandler: u
836
841
  }) {
837
- const f = t(), b = tt(f, u);
838
- return /* @__PURE__ */ j(V, { children: n(b) });
842
+ const f = t(), b = st(f, u);
843
+ return /* @__PURE__ */ W($, { children: n(b) });
839
844
  }
840
845
  export {
841
- it as DragDropQuestion,
842
- at as FillInBlankQuestion,
843
- lt as GroupingQuestion,
844
- ut as LabelingQuestion,
845
- st as MatchingQuestion,
846
- nt as MultipleChoicesQuestion,
847
- ct as OrderingQuestion,
848
- dt as PowerpointQuestion,
849
- pt as SpeakingQuestion,
850
- ot as VideoQuestion,
851
- ft as WritingQuestion,
852
- z as isSameSet,
853
- W as shuffleArray,
854
- M as useBaseQuestion,
855
- J as useDragDrop,
856
- Z as useFillInBlank,
857
- K as useGrouping,
858
- Y as useLabeling,
859
- N as useMatching,
860
- G as useMultipleChoice,
861
- X as useOrdering,
862
- H as usePowerpoint,
863
- tt as useSpeaking,
864
- P as useVideo,
865
- q as useWriting
846
+ lt as DragDropQuestion,
847
+ pt as FillInBlankQuestion,
848
+ mt as GroupingQuestion,
849
+ ft as LabelingQuestion,
850
+ ut as MatchingQuestion,
851
+ ct as MultipleChoicesQuestion,
852
+ dt as OrderingQuestion,
853
+ gt as PowerpointQuestion,
854
+ wt as SpeakingQuestion,
855
+ at as VideoQuestion,
856
+ bt as WritingQuestion,
857
+ J as isSameSet,
858
+ z as shuffleArray,
859
+ E as useBaseQuestion,
860
+ K as useDragDrop,
861
+ tt as useFillInBlank,
862
+ et as useGrouping,
863
+ q as useLabeling,
864
+ Y as useMatching,
865
+ X as useMultipleChoice,
866
+ H as useOrdering,
867
+ rt as usePowerpoint,
868
+ st as useSpeaking,
869
+ Z as useVideo,
870
+ nt as useWriting
866
871
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enspiredigital/xlms-headless",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",