@enspiredigital/xlms-headless 0.0.23 → 0.0.24

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/index.js CHANGED
@@ -1,177 +1,178 @@
1
- import { useState as k, useRef as E, useEffect as _, useMemo as y } from "react";
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";
2
3
  function M() {
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);
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);
6
7
  }
7
- function s() {
8
- i(!1), p(null);
8
+ function o() {
9
+ n(!1), f(null);
9
10
  }
10
11
  return {
11
12
  // state
12
13
  submitted: t,
13
- isCorrect: c,
14
- attempts: g,
14
+ isCorrect: u,
15
+ attempts: b,
15
16
  // derived
16
17
  canAnswer: !t,
17
18
  // actions
18
- submitQuestion: h,
19
- resetQuestion: s
19
+ submitQuestion: S,
20
+ resetQuestion: o
20
21
  };
21
22
  }
22
- function T(t, i) {
23
- if (t.length !== i.length) return !1;
24
- const c = new Set(t), p = new Set(i);
25
- if (c.size !== p.size) return !1;
26
- for (const g of c)
27
- if (!p.has(g)) return !1;
23
+ function z(t, n) {
24
+ if (t.length !== n.length) return !1;
25
+ const u = new Set(t), f = new Set(n);
26
+ if (u.size !== f.size) return !1;
27
+ for (const b of u)
28
+ if (!f.has(b)) return !1;
28
29
  return !0;
29
30
  }
30
- function j(t) {
31
- const i = [...t];
32
- for (let c = i.length - 1; c > 0; c--) {
33
- const p = Math.floor(Math.random() * (c + 1));
34
- [i[c], i[p]] = [i[p], i[c]];
31
+ function W(t) {
32
+ const n = [...t];
33
+ for (let u = n.length - 1; u > 0; u--) {
34
+ const f = Math.floor(Math.random() * (u + 1));
35
+ [n[u], n[f]] = [n[f], n[u]];
35
36
  }
36
- return i;
37
+ return n;
37
38
  }
38
- function V(t) {
39
+ function G(t) {
39
40
  const {
40
- canAnswer: i,
41
- submitted: c,
42
- isCorrect: p,
43
- attempts: g,
44
- resetQuestion: w,
45
- submitQuestion: h
46
- } = M(), [s, f] = k([]);
47
- function A(C) {
48
- f((m) => t.options.allowMultipleAnswers ? m.includes(C) ? m.filter((I) => I !== C) : [...m, C] : [C]);
49
- }
50
- function S() {
51
- if (s.length === 0) return;
52
- const C = t.options.answers.reduce(
53
- (I, b) => (b.is_correct && I.push(b.id), I),
41
+ canAnswer: n,
42
+ submitted: u,
43
+ isCorrect: f,
44
+ attempts: b,
45
+ resetQuestion: C,
46
+ submitQuestion: S
47
+ } = M(), [o, l] = x([]);
48
+ function h(w) {
49
+ l((m) => t.options.allowMultipleAnswers ? m.includes(w) ? m.filter((p) => p !== w) : [...m, w] : [w]);
50
+ }
51
+ function I() {
52
+ if (o.length === 0) return;
53
+ const w = t.options.answers.reduce(
54
+ (p, A) => (A.is_correct && p.push(A.id), p),
54
55
  []
55
- ), m = T(s, C);
56
- h(m);
56
+ ), m = z(o, w);
57
+ S(m);
57
58
  }
58
- function x() {
59
- f([]), w();
59
+ function v() {
60
+ l([]), C();
60
61
  }
61
62
  return {
62
63
  // data
63
64
  question: t,
64
- selectedIds: s,
65
+ selectedIds: o,
65
66
  // actions
66
- select: A,
67
- submit: S,
68
- reset: x,
67
+ select: h,
68
+ submit: I,
69
+ reset: v,
69
70
  // base
70
- submitted: c,
71
- isCorrect: p,
72
- attempts: g,
73
- canAnswer: i
71
+ submitted: u,
72
+ isCorrect: f,
73
+ attempts: b,
74
+ canAnswer: n
74
75
  };
75
76
  }
76
- function F(t) {
77
+ function N(t) {
77
78
  const {
78
- canAnswer: i,
79
- submitted: c,
80
- isCorrect: p,
81
- attempts: g,
82
- submitQuestion: w,
83
- resetQuestion: h
84
- } = M(), [s, f] = k([]), [A, S] = k(
79
+ canAnswer: n,
80
+ submitted: u,
81
+ isCorrect: f,
82
+ attempts: b,
83
+ submitQuestion: C,
84
+ resetQuestion: S
85
+ } = M(), [o, l] = x([]), [h, I] = x(
85
86
  []
86
- ), [x, C] = k(
87
+ ), [v, w] = x(
87
88
  []
88
- ), m = E([]);
89
- function I(e, u) {
90
- f((l) => [
91
- ...l.filter(
92
- (d) => d.targetId !== e && d.sourceId !== u
89
+ ), m = F([]);
90
+ function p(e, c) {
91
+ l((d) => [
92
+ ...d.filter(
93
+ (g) => g.targetId !== e && g.sourceId !== c
93
94
  ),
94
- { targetId: e, sourceId: u }
95
+ { targetId: e, sourceId: c }
95
96
  ]);
96
97
  }
97
- function b(e, u) {
98
- f(
99
- (l) => l.filter((d) => d.targetId !== e || d.sourceId !== u)
98
+ function A(e, c) {
99
+ l(
100
+ (d) => d.filter((g) => g.targetId !== e || g.sourceId !== c)
100
101
  );
101
102
  }
102
103
  function a() {
103
- let e = 0, u = !0;
104
- return t.options.targets.forEach((l) => {
105
- const d = s.find((v) => v.targetId === l.id), Q = t.options.sources[l.content.correct_position - 1];
106
- d && Q && d.sourceId === Q.id ? e += l.content.point : u = !1;
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;
107
108
  }), {
108
- isCorrect: u,
109
+ isCorrect: c,
109
110
  score: e,
110
111
  maxScore: t.options.targets.reduce(
111
- (l, d) => l + d.content.point,
112
+ (d, g) => d + g.content.point,
112
113
  0
113
114
  )
114
115
  };
115
116
  }
116
- function o() {
117
+ function i() {
117
118
  const e = a();
118
- return w(e.isCorrect), e;
119
+ return C(e.isCorrect), e;
119
120
  }
120
- function r() {
121
- f([]), h();
121
+ function s() {
122
+ l([]), S();
122
123
  }
123
- function n(e) {
124
- const u = s.find((l) => l.sourceId === e)?.targetId;
125
- return t.options.targets.find((l) => l.id === u);
124
+ function r(e) {
125
+ const c = o.find((d) => d.sourceId === e)?.targetId;
126
+ return t.options.targets.find((d) => d.id === c);
126
127
  }
127
- return _(() => {
128
+ return D(() => {
128
129
  const e = t.options.sources.filter(
129
- (u) => !s.some((l) => l.sourceId === u.id)
130
+ (c) => !o.some((d) => d.sourceId === c.id)
130
131
  );
131
- S(e);
132
- }, [s, t.options.sources]), _(() => {
132
+ I(e);
133
+ }, [o, t.options.sources]), D(() => {
133
134
  if (m.current.length === 0) return;
134
135
  const e = m.current.filter(
135
- (u) => !s.some((l) => l.targetId === u.id)
136
+ (c) => !o.some((d) => d.targetId === c.id)
136
137
  );
137
- C(e);
138
- }, [s]), _(() => {
139
- m.current = j(t.options.targets);
138
+ w(e);
139
+ }, [o]), D(() => {
140
+ m.current = W(t.options.targets);
140
141
  }, [t.options.targets]), {
141
142
  // data
142
143
  sources: t.options.sources,
143
144
  targets: t.options.targets,
144
- answers: s,
145
+ answers: o,
145
146
  question: t,
146
- availableSources: A,
147
- availableTargets: x,
147
+ availableSources: h,
148
+ availableTargets: v,
148
149
  // base
149
- submitted: c,
150
- isCorrect: p,
151
- attempts: g,
152
- canAnswer: i,
150
+ submitted: u,
151
+ isCorrect: f,
152
+ attempts: b,
153
+ canAnswer: n,
153
154
  // actions
154
- getTargetBySourceId: n,
155
- select: I,
156
- remove: b,
157
- submit: o,
158
- reset: r
155
+ getTargetBySourceId: r,
156
+ select: p,
157
+ remove: A,
158
+ submit: i,
159
+ reset: s
159
160
  };
160
161
  }
161
- function z(t) {
162
+ function P(t) {
162
163
  const {
163
- canAnswer: i,
164
- submitted: c,
165
- isCorrect: p,
166
- attempts: g,
167
- resetQuestion: w,
168
- submitQuestion: h
164
+ canAnswer: n,
165
+ submitted: u,
166
+ isCorrect: f,
167
+ attempts: b,
168
+ resetQuestion: C,
169
+ submitQuestion: S
169
170
  } = M();
170
- function s() {
171
- h(!0);
171
+ function o() {
172
+ S(!0);
172
173
  }
173
- function f() {
174
- w();
174
+ function l() {
175
+ C();
175
176
  }
176
177
  return {
177
178
  // data
@@ -179,241 +180,241 @@ function z(t) {
179
180
  url: t.options.url,
180
181
  type: t.options.urlType,
181
182
  // actions
182
- submit: s,
183
- reset: f,
183
+ submit: o,
184
+ reset: l,
184
185
  // base
185
- submitted: c,
186
- isCorrect: p,
187
- attempts: g,
188
- canAnswer: i
186
+ submitted: u,
187
+ isCorrect: f,
188
+ attempts: b,
189
+ canAnswer: n
189
190
  };
190
191
  }
191
- function G(t) {
192
+ function J(t) {
192
193
  const {
193
- canAnswer: i,
194
- submitted: c,
195
- isCorrect: p,
196
- attempts: g,
197
- submitQuestion: w,
198
- resetQuestion: h
199
- } = M(), [s, f] = k([]), [A, S] = k(null), x = y(() => {
200
- const n = new Set(s.map((e) => e.itemId));
194
+ canAnswer: n,
195
+ submitted: u,
196
+ isCorrect: f,
197
+ attempts: b,
198
+ submitQuestion: C,
199
+ resetQuestion: S
200
+ } = M(), [o, l] = x([]), [h, I] = x(null), v = T(() => {
201
+ const r = new Set(o.map((e) => e.itemId));
201
202
  return t.options.answers.filter(
202
- (e) => !n.has(String(e.id))
203
+ (e) => !r.has(String(e.id))
203
204
  );
204
- }, [s, t.options.answers]);
205
- function C(n, e) {
206
- f((u) => [
207
- ...u.filter(
208
- (d) => d.blankIndex !== e && d.itemId !== n
205
+ }, [o, t.options.answers]);
206
+ function w(r, e) {
207
+ l((c) => [
208
+ ...c.filter(
209
+ (g) => g.blankIndex !== e && g.itemId !== r
209
210
  ),
210
211
  {
211
- itemId: n,
212
+ itemId: r,
212
213
  blankIndex: e
213
214
  }
214
215
  ]);
215
216
  }
216
- function m(n) {
217
- f((e) => e.filter((u) => u.itemId !== n));
217
+ function m(r) {
218
+ l((e) => e.filter((c) => c.itemId !== r));
218
219
  }
219
- function I(n, e) {
220
- C(n, e);
220
+ function p(r, e) {
221
+ w(r, e);
221
222
  }
222
- function b() {
223
- let n = 0, e = !0, u = 0;
224
- const l = t.correct_answers.list, d = new Map(s.map((Q) => [Q.blankIndex, Q.itemId]));
225
- return Object.entries(l).forEach(([Q, v]) => {
226
- const O = Q, B = d.get(O);
227
- if (!B) {
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);
228
+ if (!L) {
228
229
  e = !1;
229
230
  return;
230
231
  }
231
- const L = t.options.answers.find((D) => D.id === B);
232
- L && String(L.group_position) === String(v) ? (n++, u += L.point) : e = !1;
232
+ const O = t.options.answers.find((_) => _.id === L);
233
+ O && String(O.group_position) === String(U) ? (r++, c += O.point) : e = !1;
233
234
  }), {
234
235
  isCorrect: e,
235
- correctCount: n,
236
- totalCount: Object.keys(l).length,
236
+ correctCount: r,
237
+ totalCount: Object.keys(d).length,
237
238
  maxScore: t.metadata.points,
238
- score: u
239
+ score: c
239
240
  };
240
241
  }
241
242
  function a() {
242
- const n = b();
243
- return w(n.isCorrect), n;
243
+ const r = A();
244
+ return C(r.isCorrect), r;
244
245
  }
245
- function o() {
246
- f([]), h();
246
+ function i() {
247
+ l([]), S();
247
248
  }
248
- function r(n) {
249
- const e = s.find((u) => u.blankIndex === n)?.itemId;
250
- return t.options.answers.find((u) => u.id === e);
249
+ function s(r) {
250
+ const e = o.find((c) => c.blankIndex === r)?.itemId;
251
+ return t.options.answers.find((c) => c.id === e);
251
252
  }
252
253
  return {
253
254
  // data
254
255
  items: t.options.answers,
255
256
  groups: t.options.groups,
256
- answers: s,
257
- availableItems: x,
257
+ answers: o,
258
+ availableItems: v,
258
259
  question: t,
259
- draggingItemId: A,
260
+ draggingItemId: h,
260
261
  // base
261
- submitted: c,
262
- isCorrect: p,
263
- attempts: g,
264
- canAnswer: i,
262
+ submitted: u,
263
+ isCorrect: f,
264
+ attempts: b,
265
+ canAnswer: n,
265
266
  // actions
266
- dropItem: C,
267
+ dropItem: w,
267
268
  removeItem: m,
268
- moveItem: I,
269
- setDraggingItemId: S,
270
- getItemByBlankId: r,
269
+ moveItem: p,
270
+ setDraggingItemId: I,
271
+ getItemByBlankId: s,
271
272
  submit: a,
272
- reset: o
273
+ reset: i
273
274
  };
274
275
  }
275
- function R(t) {
276
+ function X(t) {
276
277
  const {
277
- canAnswer: i,
278
- submitted: c,
279
- isCorrect: p,
280
- attempts: g,
281
- submitQuestion: w,
282
- resetQuestion: h
283
- } = M(), [s, f] = k(() => j(
284
- t.options.answers.map((o) => String(o.id))
285
- )), A = y(() => s.map(
286
- (o) => t.options.answers.find((r) => String(r.id) === o)
287
- ).filter((o) => o !== void 0), [s, t.options.answers]);
288
- function S(o, r) {
289
- f((n) => {
290
- const e = [...n], [u] = e.splice(o, 1);
291
- return e.splice(r, 0, u), e;
278
+ canAnswer: n,
279
+ submitted: u,
280
+ isCorrect: f,
281
+ attempts: b,
282
+ submitQuestion: C,
283
+ resetQuestion: S
284
+ } = M(), [o, l] = x(() => W(
285
+ t.options.answers.map((i) => String(i.id))
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;
292
293
  });
293
294
  }
294
- function x(o) {
295
- const r = s.indexOf(o);
296
- r > 0 && S(r, r - 1);
295
+ function v(i) {
296
+ const s = o.indexOf(i);
297
+ s > 0 && I(s, s - 1);
297
298
  }
298
- function C(o) {
299
- const r = s.indexOf(o);
300
- r < s.length - 1 && S(r, r + 1);
299
+ function w(i) {
300
+ const s = o.indexOf(i);
301
+ s < o.length - 1 && I(s, s + 1);
301
302
  }
302
- function m(o, r) {
303
- const n = s.indexOf(o);
304
- n !== -1 && r >= 0 && r < s.length && S(n, r);
303
+ function m(i, s) {
304
+ const r = o.indexOf(i);
305
+ r !== -1 && s >= 0 && s < o.length && I(r, s);
305
306
  }
306
- function I() {
307
- let o = 0, r = !0;
308
- return t.options.answers.forEach((n, e) => {
309
- const u = s.indexOf(String(n.id));
310
- u !== -1 && u + 1 === n.correct_position ? o += n.point : r = !1;
307
+ function p() {
308
+ let i = 0, s = !0;
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;
311
312
  }), {
312
- isCorrect: r,
313
- score: o,
313
+ isCorrect: s,
314
+ score: i,
314
315
  maxScore: t.options.answers.reduce(
315
- (n, e) => n + e.point,
316
+ (r, e) => r + e.point,
316
317
  0
317
318
  )
318
319
  };
319
320
  }
320
- function b() {
321
- const o = I();
322
- return w(o.isCorrect), o;
321
+ function A() {
322
+ const i = p();
323
+ return C(i.isCorrect), i;
323
324
  }
324
325
  function a() {
325
- f(t.options.answers.map((o) => String(o.id))), h();
326
+ l(t.options.answers.map((i) => String(i.id))), S();
326
327
  }
327
328
  return {
328
329
  // data
329
330
  items: t.options.answers,
330
331
  groups: t.options.groups,
331
- orderedItems: A,
332
- orderedItemIds: s,
332
+ orderedItems: h,
333
+ orderedItemIds: o,
333
334
  question: t,
334
335
  // base
335
- submitted: c,
336
- isCorrect: p,
337
- attempts: g,
338
- canAnswer: i,
336
+ submitted: u,
337
+ isCorrect: f,
338
+ attempts: b,
339
+ canAnswer: n,
339
340
  // actions
340
- setOrderedItemIds: f,
341
- moveItem: S,
342
- moveUp: x,
343
- moveDown: C,
341
+ setOrderedItemIds: l,
342
+ moveItem: I,
343
+ moveUp: v,
344
+ moveDown: w,
344
345
  moveToPosition: m,
345
- submit: b,
346
+ submit: A,
346
347
  reset: a
347
348
  };
348
349
  }
349
- function W(t) {
350
+ function Y(t) {
350
351
  const {
351
- canAnswer: i,
352
- submitted: c,
353
- isCorrect: p,
354
- attempts: g,
355
- submitQuestion: w,
356
- resetQuestion: h
357
- } = M(), [s, f] = k([]), A = y(() => {
358
- const r = new Set(s.map((n) => n.labelId));
352
+ canAnswer: n,
353
+ submitted: u,
354
+ isCorrect: f,
355
+ attempts: b,
356
+ submitQuestion: C,
357
+ resetQuestion: S
358
+ } = M(), [o, l] = x([]), h = T(() => {
359
+ const s = new Set(o.map((r) => r.labelId));
359
360
  return t.options.labels.filter(
360
- (n) => !r.has(String(n.id))
361
+ (r) => !s.has(String(r.id))
361
362
  );
362
- }, [s, t.options.labels]);
363
- function S(r, n, e, u) {
364
- const l = t.options.blanks.find((d) => String(d.id) === n);
365
- l && f((d) => [
366
- ...d.filter(
367
- (v) => v.labelId !== r && v.blankId !== n
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) => [
367
+ ...g.filter(
368
+ (U) => U.labelId !== s && U.blankId !== r
368
369
  ),
369
370
  {
370
- labelId: r,
371
- blankId: n,
372
- x: e ?? l.coordinates.x,
373
- y: u ?? l.coordinates.y
371
+ labelId: s,
372
+ blankId: r,
373
+ x: e ?? d.coordinates.x,
374
+ y: c ?? d.coordinates.y
374
375
  }
375
376
  ]);
376
377
  }
377
- function x(r) {
378
- f((n) => n.filter((e) => e.labelId !== r));
378
+ function v(s) {
379
+ l((r) => r.filter((e) => e.labelId !== s));
379
380
  }
380
- function C(r, n, e, u) {
381
- S(r, n, e, u);
381
+ function w(s, r, e, c) {
382
+ I(s, r, e, c);
382
383
  }
383
- function m(r) {
384
- const n = s.find((e) => e.blankId === r);
385
- return n && t.options.labels.find(
386
- (e) => String(e.id) === n.labelId
384
+ function m(s) {
385
+ const r = o.find((e) => e.blankId === s);
386
+ return r && t.options.labels.find(
387
+ (e) => String(e.id) === r.labelId
387
388
  ) || null;
388
389
  }
389
- function I(r) {
390
- const n = s.find((e) => e.labelId === r);
391
- return n ? n.blankId : null;
390
+ function p(s) {
391
+ const r = o.find((e) => e.labelId === s);
392
+ return r ? r.blankId : null;
392
393
  }
393
- function b() {
394
- let r = 0, n = !0;
394
+ function A() {
395
+ let s = 0, r = !0;
395
396
  return t.options.labels.forEach((e) => {
396
- const u = s.find(
397
- (d) => String(d.labelId) === String(e.id)
398
- ), l = t.options.blanks.find(
399
- (d, Q) => Q + 1 === e.correct_position
397
+ const c = o.find(
398
+ (g) => String(g.labelId) === String(e.id)
399
+ ), d = t.options.blanks.find(
400
+ (g, y) => y + 1 === e.correct_position
400
401
  );
401
- u && l && u.blankId === String(l.id) ? r += e.point : n = !1;
402
+ c && d && c.blankId === String(d.id) ? s += e.point : r = !1;
402
403
  }), {
403
- isCorrect: n,
404
- score: r,
404
+ isCorrect: r,
405
+ score: s,
405
406
  maxScore: t.options.labels.reduce(
406
- (e, u) => e + u.point,
407
+ (e, c) => e + c.point,
407
408
  0
408
409
  )
409
410
  };
410
411
  }
411
412
  function a() {
412
- const r = b();
413
- return w(r.isCorrect), r;
413
+ const s = A();
414
+ return C(s.isCorrect), s;
414
415
  }
415
- function o() {
416
- f([]), h();
416
+ function i() {
417
+ l([]), S();
417
418
  }
418
419
  return {
419
420
  // data
@@ -422,174 +423,174 @@ function W(t) {
422
423
  groups: t.options.groups,
423
424
  imageWidth: t.image_width,
424
425
  imageHeight: t.image_height,
425
- answers: s,
426
- availableLabels: A,
426
+ answers: o,
427
+ availableLabels: h,
427
428
  question: t,
428
429
  // base
429
- submitted: c,
430
- isCorrect: p,
431
- attempts: g,
432
- canAnswer: i,
430
+ submitted: u,
431
+ isCorrect: f,
432
+ attempts: b,
433
+ canAnswer: n,
433
434
  // actions
434
- attachLabel: S,
435
- removeLabel: x,
436
- moveLabel: C,
435
+ attachLabel: I,
436
+ removeLabel: v,
437
+ moveLabel: w,
437
438
  getLabelAtBlank: m,
438
- getBlankForLabel: I,
439
+ getBlankForLabel: p,
439
440
  submit: a,
440
- reset: o
441
+ reset: i
441
442
  };
442
443
  }
443
- function H(t) {
444
+ function Z(t) {
444
445
  const {
445
- canAnswer: i,
446
- submitted: c,
447
- isCorrect: p,
448
- attempts: g,
449
- submitQuestion: w,
450
- resetQuestion: h
451
- } = M(), [s, f] = k([]);
452
- function A(m, I) {
453
- f((b) => {
454
- const a = b.findIndex((o) => o.blankId === m);
446
+ canAnswer: n,
447
+ submitted: u,
448
+ isCorrect: f,
449
+ attempts: b,
450
+ submitQuestion: C,
451
+ resetQuestion: S
452
+ } = M(), [o, l] = x([]);
453
+ function h(m, p) {
454
+ l((A) => {
455
+ const a = A.findIndex((i) => i.blankId === m);
455
456
  if (a >= 0) {
456
- const o = [...b];
457
- return o[a] = { blankId: m, value: I }, o;
457
+ const i = [...A];
458
+ return i[a] = { blankId: m, value: p }, i;
458
459
  }
459
- return [...b, { blankId: m, value: I }];
460
+ return [...A, { blankId: m, value: p }];
460
461
  });
461
462
  }
462
- function S() {
463
- let m = 0, I = 0, b = 0;
464
- const a = t.correct_answers.list || {}, o = Object.keys(a).length;
465
- Object.entries(a).forEach(([n, e]) => {
466
- const u = String(e).trim().toLowerCase(), l = t.options.answers.find(
467
- (O) => O.correct_position === Number(n)
468
- ), d = l && l.point || 1;
469
- b += d;
470
- const Q = s.find((O) => O.blankId === n);
471
- (Q ? String(Q.value).trim().toLowerCase() : "") === u && (m += d, I++);
463
+ function I() {
464
+ let m = 0, p = 0, A = 0;
465
+ const a = t.correct_answers.list || {}, i = Object.keys(a).length;
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++);
472
473
  });
473
- const r = I === o && o > 0;
474
- return b === 0 && o > 0 && (b = o), {
475
- isCorrect: r,
474
+ const s = p === i && i > 0;
475
+ return A === 0 && i > 0 && (A = i), {
476
+ isCorrect: s,
476
477
  score: Math.round(m * 100) / 100,
477
- maxScore: Math.round(b * 100) / 100
478
+ maxScore: Math.round(A * 100) / 100
478
479
  };
479
480
  }
480
- function x() {
481
- const m = S();
482
- return w(m.isCorrect), m;
481
+ function v() {
482
+ const m = I();
483
+ return C(m.isCorrect), m;
483
484
  }
484
- function C() {
485
- f([]), h();
485
+ function w() {
486
+ l([]), S();
486
487
  }
487
488
  return {
488
489
  // data
489
490
  groups: t.options.groups,
490
- answers: s,
491
+ answers: o,
491
492
  question: t,
492
493
  // base
493
- submitted: c,
494
- isCorrect: p,
495
- attempts: g,
496
- canAnswer: i,
494
+ submitted: u,
495
+ isCorrect: f,
496
+ attempts: b,
497
+ canAnswer: n,
497
498
  // actions
498
- answer: A,
499
- submit: x,
500
- reset: C
499
+ answer: h,
500
+ submit: v,
501
+ reset: w
501
502
  };
502
503
  }
503
- function N(t) {
504
+ function K(t) {
504
505
  const {
505
- canAnswer: i,
506
- submitted: c,
507
- isCorrect: p,
508
- attempts: g,
509
- submitQuestion: w,
510
- resetQuestion: h
511
- } = M(), [s, f] = k([]);
512
- function A(a, o) {
513
- f((r) => {
514
- const n = r.findIndex((e) => e.itemId === a);
515
- if (n >= 0) {
516
- const e = [...r];
517
- return e[n] = { itemId: a, categoryId: o }, e;
506
+ canAnswer: n,
507
+ submitted: u,
508
+ isCorrect: f,
509
+ attempts: b,
510
+ submitQuestion: C,
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);
516
+ if (r >= 0) {
517
+ const e = [...s];
518
+ return e[r] = { itemId: a, categoryId: i }, e;
518
519
  }
519
- return [...r, { itemId: a, categoryId: o }];
520
+ return [...s, { itemId: a, categoryId: i }];
520
521
  });
521
522
  }
522
- function S(a) {
523
- f((o) => o.filter((r) => r.itemId !== a));
524
- }
525
- function x() {
526
- let a = 0, o = 0;
527
- const n = t.correct_answers.list || {}, e = Object.keys(n).length;
528
- let u = 0;
529
- return Object.entries(n).forEach(([d, Q]) => {
530
- const v = t.options.items.find((L) => L.id === d), O = v ? v.point : 0;
531
- u += O;
532
- const B = s.find((L) => L.itemId === d);
533
- B && B.categoryId === Q && (a += O, o++);
534
- }), a = Math.round(a * 100) / 100, u = Math.round(u * 100) / 100, {
535
- isCorrect: o === e && e > 0,
523
+ function I(a) {
524
+ l((i) => i.filter((s) => s.itemId !== a));
525
+ }
526
+ function v() {
527
+ let a = 0, i = 0;
528
+ const r = t.correct_answers.list || {}, e = Object.keys(r).length;
529
+ let c = 0;
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,
536
537
  score: a,
537
- maxScore: u
538
+ maxScore: c
538
539
  };
539
540
  }
540
- function C() {
541
- const a = x();
542
- return w(a.isCorrect), a;
541
+ function w() {
542
+ const a = v();
543
+ return C(a.isCorrect), a;
543
544
  }
544
545
  function m() {
545
- f([]), h();
546
+ l([]), S();
546
547
  }
547
- const I = y(() => t.options.items.filter(
548
- (a) => !s.some((o) => o.itemId === a.id)
549
- ), [t.options.items, s]), b = y(() => t.options.categories.map((a) => {
550
- const o = s.filter((r) => r.categoryId === a.id).map((r) => ({
551
- ...t.options.items.find((e) => e.id === r.itemId)
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)
552
553
  }));
553
554
  return {
554
555
  ...a,
555
- items: o
556
+ items: i
556
557
  };
557
- }), [t.options.categories, t.options.items, s]);
558
+ }), [t.options.categories, t.options.items, o]);
558
559
  return {
559
560
  // data
560
561
  categories: t.options.categories,
561
562
  allItems: t.options.items,
562
563
  question: t,
563
- categoriesWithItems: b,
564
+ categoriesWithItems: A,
564
565
  // state
565
- answers: s,
566
- unassignedItems: I,
566
+ answers: o,
567
+ unassignedItems: p,
567
568
  // base
568
- submitted: c,
569
- isCorrect: p,
570
- attempts: g,
571
- canAnswer: i,
569
+ submitted: u,
570
+ isCorrect: f,
571
+ attempts: b,
572
+ canAnswer: n,
572
573
  // actions
573
- move: A,
574
- remove: S,
575
- submit: C,
574
+ move: h,
575
+ remove: I,
576
+ submit: w,
576
577
  reset: m
577
578
  };
578
579
  }
579
- function P(t) {
580
+ function H(t) {
580
581
  const {
581
- canAnswer: i,
582
- submitted: c,
583
- isCorrect: p,
584
- attempts: g,
585
- resetQuestion: w,
586
- submitQuestion: h
582
+ canAnswer: n,
583
+ submitted: u,
584
+ isCorrect: f,
585
+ attempts: b,
586
+ resetQuestion: C,
587
+ submitQuestion: S
587
588
  } = M();
588
- function s() {
589
- c || h(!0);
589
+ function o() {
590
+ u || S(!0);
590
591
  }
591
- function f() {
592
- w();
592
+ function l() {
593
+ C();
593
594
  }
594
595
  return {
595
596
  // data
@@ -597,98 +598,269 @@ function P(t) {
597
598
  url: t.options.url,
598
599
  type: t.options.urlType,
599
600
  // actions
600
- submit: s,
601
- reset: f,
601
+ submit: o,
602
+ reset: l,
602
603
  // base
603
- submitted: c,
604
- isCorrect: p,
605
- attempts: g,
606
- canAnswer: i
604
+ submitted: u,
605
+ isCorrect: f,
606
+ attempts: b,
607
+ canAnswer: n
608
+ };
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(
612
+ async (e) => {
613
+ if (n) {
614
+ w(!0), p(void 0);
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"
621
+ );
622
+ } finally {
623
+ w(!1);
624
+ }
625
+ }
626
+ },
627
+ [n]
628
+ ), a = B(async () => {
629
+ if (!(!n || !o)) {
630
+ w(!0), p(void 0);
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");
634
+ } catch (e) {
635
+ console.error("Text upload failed:", e), p(
636
+ e instanceof Error ? e.message : "Text upload failed"
637
+ );
638
+ } finally {
639
+ w(!1);
640
+ }
641
+ }
642
+ }, [o, t.id, n]), i = T(
643
+ () => ({
644
+ questionId: t.id || "",
645
+ type: "writing",
646
+ text: o,
647
+ fileUrl: h
648
+ }),
649
+ [t.id, o, h]
650
+ ), s = B(() => (C(), i), [C, i]), r = B(() => {
651
+ l(""), I(void 0), p(void 0), S();
652
+ }, [S]);
653
+ return {
654
+ question: t,
655
+ canAnswer: u,
656
+ submitted: f,
657
+ attempts: b,
658
+ text: o,
659
+ setText: l,
660
+ fileUrl: h,
661
+ setFileUrl: I,
662
+ isUploading: v,
663
+ uploadError: m,
664
+ uploadFile: A,
665
+ uploadText: a,
666
+ submit: s,
667
+ reset: r,
668
+ payload: i
669
+ };
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 () => {
673
+ try {
674
+ const Q = await navigator.mediaDevices.getUserMedia({ audio: !0 });
675
+ e.current = Q;
676
+ const k = new MediaRecorder(Q);
677
+ i.current = k, s.current = [], k.ondataavailable = (E) => {
678
+ E.data.size > 0 && s.current.push(E.data);
679
+ }, k.onstop = () => {
680
+ const E = new Blob(s.current, {
681
+ type: "audio/webm"
682
+ }), $ = URL.createObjectURL(E);
683
+ l($);
684
+ }, k.start(), I("recording"), w(0), r.current = setInterval(() => {
685
+ w((E) => E + 1);
686
+ }, 1e3);
687
+ } catch (Q) {
688
+ console.error("Failed to start recording:", Q), a("Failed to access microphone");
689
+ }
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(() => {
694
+ w((Q) => Q + 1);
695
+ }, 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)) {
700
+ p(!0), a(void 0);
701
+ try {
702
+ const Q = new Blob(s.current, {
703
+ 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");
706
+ } catch (Q) {
707
+ console.error("Upload failed:", Q), a(Q instanceof Error ? Q.message : "Upload failed");
708
+ } finally {
709
+ p(!1);
710
+ }
711
+ }
712
+ }, [t.id, n]), R = B(
713
+ async (Q) => {
714
+ if (n) {
715
+ p(!0), a(void 0);
716
+ try {
717
+ const k = await n(Q, Q.name);
718
+ k.success && k.url ? l(k.url) : a(k.error || "Upload failed");
719
+ } catch (k) {
720
+ console.error("File upload failed:", k), a(
721
+ k instanceof Error ? k.message : "File upload failed"
722
+ );
723
+ } finally {
724
+ p(!1);
725
+ }
726
+ }
727
+ },
728
+ [n]
729
+ ), L = T(
730
+ () => ({
731
+ questionId: t.id || "",
732
+ type: "speaking",
733
+ audioUrl: o
734
+ }),
735
+ [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();
738
+ }, [S]);
739
+ return {
740
+ question: t,
741
+ canAnswer: u,
742
+ submitted: f,
743
+ attempts: b,
744
+ audioUrl: o,
745
+ setAudioUrl: l,
746
+ recordingState: h,
747
+ recordingTime: v,
748
+ 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
607
759
  };
608
760
  }
609
- function J({
761
+ function nt({
762
+ getData: t,
763
+ children: n
764
+ }) {
765
+ const u = G(t());
766
+ return n(u);
767
+ }
768
+ function st({
769
+ getData: t,
770
+ children: n
771
+ }) {
772
+ const u = N(t());
773
+ return n(u);
774
+ }
775
+ function ot({
610
776
  getData: t,
611
- children: i
777
+ children: n
612
778
  }) {
613
- const c = V(t());
614
- return i(c);
779
+ const u = P(t());
780
+ return n(u);
615
781
  }
616
- function X({
782
+ function it({
617
783
  getData: t,
618
- children: i
784
+ children: n
619
785
  }) {
620
- const c = F(t());
621
- return i(c);
786
+ const u = J(t());
787
+ return n(u);
622
788
  }
623
- function Y({
789
+ function ct({
624
790
  getData: t,
625
- children: i
791
+ children: n
626
792
  }) {
627
- const c = z(t());
628
- return i(c);
793
+ const u = X(t());
794
+ return n(u);
629
795
  }
630
- function Z({
796
+ function ut({
631
797
  getData: t,
632
- children: i
798
+ children: n
633
799
  }) {
634
- const c = G(t());
635
- return i(c);
800
+ const u = Y(t());
801
+ return n(u);
636
802
  }
637
- function $({
803
+ function at({
638
804
  getData: t,
639
- children: i
805
+ children: n
640
806
  }) {
641
- const c = R(t());
642
- return i(c);
807
+ const u = Z(t());
808
+ return n(u);
643
809
  }
644
- function K({
810
+ function lt({
645
811
  getData: t,
646
- children: i
812
+ children: n
647
813
  }) {
648
- const c = W(t());
649
- return i(c);
814
+ const u = K(t());
815
+ return n(u);
650
816
  }
651
- function q({
817
+ function dt({
652
818
  getData: t,
653
- children: i
819
+ children: n
654
820
  }) {
655
- const c = H(t());
656
- return i(c);
821
+ const u = H(t());
822
+ return n(u);
657
823
  }
658
- function tt({
824
+ function ft({
659
825
  getData: t,
660
- children: i
826
+ children: n,
827
+ uploadHandler: u
661
828
  }) {
662
- const c = N(t());
663
- return i(c);
829
+ const f = t(), b = q(f, u);
830
+ return /* @__PURE__ */ j(V, { children: n(b) });
664
831
  }
665
- function et({
832
+ function pt({
666
833
  getData: t,
667
- children: i
834
+ children: n,
835
+ uploadHandler: u
668
836
  }) {
669
- const c = P(t());
670
- return i(c);
837
+ const f = t(), b = tt(f, u);
838
+ return /* @__PURE__ */ j(V, { children: n(b) });
671
839
  }
672
840
  export {
673
- Z as DragDropQuestion,
674
- q as FillInBlankQuestion,
675
- tt as GroupingQuestion,
676
- K as LabelingQuestion,
677
- X as MatchingQuestion,
678
- J as MultipleChoicesQuestion,
679
- $ as OrderingQuestion,
680
- et as PowerpointQuestion,
681
- Y as VideoQuestion,
682
- T as isSameSet,
683
- j as shuffleArray,
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,
684
854
  M as useBaseQuestion,
685
- G as useDragDrop,
686
- H as useFillInBlank,
687
- N as useGrouping,
688
- W as useLabeling,
689
- F as useMatching,
690
- V as useMultipleChoice,
691
- R as useOrdering,
692
- P as usePowerpoint,
693
- z as useVideo
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
694
866
  };