@enspiredigital/xlms-headless 0.0.12 → 0.0.13

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,161 +1,161 @@
1
- import { useState as S, useEffect as y, useMemo as B } from "react";
2
- function M() {
3
- const [t, c] = S(null), [u, g] = S(null), [w, h] = S(0);
4
- function Q(d) {
5
- c(!0), g(d), h((v) => v + 1);
1
+ import { useState as Q, useEffect as D, useMemo as _ } from "react";
2
+ function O() {
3
+ const [t, o] = Q(null), [i, m] = Q(null), [b, C] = Q(0);
4
+ function h(a) {
5
+ o(!0), m(a), C((S) => S + 1);
6
6
  }
7
- function n() {
8
- c(!1), g(null);
7
+ function s() {
8
+ o(!1), m(null);
9
9
  }
10
10
  return {
11
11
  // state
12
12
  submitted: t,
13
- isCorrect: u,
14
- attempts: w,
13
+ isCorrect: i,
14
+ attempts: b,
15
15
  // derived
16
16
  canAnswer: !t,
17
17
  // actions
18
- submitQuestion: Q,
19
- resetQuestion: n
18
+ submitQuestion: h,
19
+ resetQuestion: s
20
20
  };
21
21
  }
22
- function k(t, c) {
23
- if (t.length !== c.length) return !1;
24
- const u = new Set(t), g = new Set(c);
25
- if (u.size !== g.size) return !1;
26
- for (const w of u)
27
- if (!g.has(w)) return !1;
22
+ function y(t, o) {
23
+ if (t.length !== o.length) return !1;
24
+ const i = new Set(t), m = new Set(o);
25
+ if (i.size !== m.size) return !1;
26
+ for (const b of i)
27
+ if (!m.has(b)) return !1;
28
28
  return !0;
29
29
  }
30
- function V(t) {
30
+ function E(t) {
31
31
  const {
32
- canAnswer: c,
33
- submitted: u,
34
- isCorrect: g,
35
- attempts: w,
36
- resetQuestion: h,
37
- submitQuestion: Q
38
- } = M(), [n, d] = S([]);
39
- function v(C) {
40
- d((p) => t.options.allowMultipleAnswers ? p.includes(C) ? p.filter((I) => I !== C) : [...p, C] : [C]);
41
- }
42
- function O() {
43
- if (n.length === 0) return;
44
- const C = t.options.answers.reduce(
45
- (I, A) => (A.is_correct && I.push(A.id), I),
32
+ canAnswer: o,
33
+ submitted: i,
34
+ isCorrect: m,
35
+ attempts: b,
36
+ resetQuestion: C,
37
+ submitQuestion: h
38
+ } = O(), [s, a] = Q([]);
39
+ function S(g) {
40
+ a((p) => t.options.allowMultipleAnswers ? p.includes(g) ? p.filter((w) => w !== g) : [...p, g] : [g]);
41
+ }
42
+ function x() {
43
+ if (s.length === 0) return;
44
+ const g = t.options.answers.reduce(
45
+ (w, I) => (I.is_correct && w.push(I.id), w),
46
46
  []
47
- ), p = k(n, C);
48
- Q(p);
47
+ ), p = y(s, g);
48
+ h(p);
49
49
  }
50
- function L() {
51
- d([]), h();
50
+ function k() {
51
+ a([]), C();
52
52
  }
53
53
  return {
54
54
  // data
55
55
  question: t,
56
- selectedIds: n,
56
+ selectedIds: s,
57
57
  // actions
58
- select: v,
59
- submit: O,
60
- reset: L,
58
+ select: S,
59
+ submit: x,
60
+ reset: k,
61
61
  // base
62
- submitted: u,
63
- isCorrect: g,
64
- attempts: w,
65
- canAnswer: c
62
+ submitted: i,
63
+ isCorrect: m,
64
+ attempts: b,
65
+ canAnswer: o
66
66
  };
67
67
  }
68
- function z(t) {
68
+ function G(t) {
69
69
  const {
70
- canAnswer: c,
71
- submitted: u,
72
- isCorrect: g,
73
- attempts: w,
74
- submitQuestion: h,
75
- resetQuestion: Q
76
- } = M(), [n, d] = S([]), [v, O] = S(
70
+ canAnswer: o,
71
+ submitted: i,
72
+ isCorrect: m,
73
+ attempts: b,
74
+ submitQuestion: C,
75
+ resetQuestion: h
76
+ } = O(), [s, a] = Q([]), [S, x] = Q(
77
77
  []
78
- ), [L, C] = S(
78
+ ), [k, g] = Q(
79
79
  []
80
80
  );
81
- function p(l, r) {
82
- d((s) => [
83
- ...s.filter(
84
- (o) => o.targetId !== l && o.sourceId !== r
81
+ function p(u, n) {
82
+ a((e) => [
83
+ ...e.filter(
84
+ (r) => r.targetId !== u && r.sourceId !== n
85
85
  ),
86
- { targetId: l, sourceId: r }
86
+ { targetId: u, sourceId: n }
87
87
  ]);
88
88
  }
89
- function I(l, r) {
90
- d(
91
- (s) => s.filter((o) => o.targetId !== l || o.sourceId !== r)
89
+ function w(u, n) {
90
+ a(
91
+ (e) => e.filter((r) => r.targetId !== u || r.sourceId !== n)
92
92
  );
93
93
  }
94
- function A() {
95
- let l = 0, r = !0;
96
- return t.options.targets.forEach((s) => {
97
- const o = n.find((i) => i.targetId === s.id), e = t.options.sources[s.content.correct_position - 1];
98
- o && e && o.sourceId === e.id ? l += s.content.point : r = !1;
94
+ function I() {
95
+ let u = 0, n = !0;
96
+ return t.options.targets.forEach((e) => {
97
+ const r = s.find((d) => d.targetId === e.id), c = t.options.sources[e.content.correct_position - 1];
98
+ r && c && r.sourceId === c.id ? u += e.content.point : n = !1;
99
99
  }), {
100
- isCorrect: r,
101
- score: l,
100
+ isCorrect: n,
101
+ score: u,
102
102
  maxScore: t.options.targets.reduce(
103
- (s, o) => s + o.content.point,
103
+ (e, r) => e + r.content.point,
104
104
  0
105
105
  )
106
106
  };
107
107
  }
108
- function a() {
109
- const l = A();
110
- return h(l.isCorrect), l;
108
+ function l() {
109
+ const u = I();
110
+ return C(u.isCorrect), u;
111
111
  }
112
- function m() {
113
- d([]), Q();
112
+ function f() {
113
+ a([]), h();
114
114
  }
115
- return y(() => {
116
- const l = t.options.sources.filter(
117
- (r) => !n.some((s) => s.sourceId === r.id)
115
+ return D(() => {
116
+ const u = t.options.sources.filter(
117
+ (n) => !s.some((e) => e.sourceId === n.id)
118
118
  );
119
- O(l);
120
- }, [n, t.options.sources]), y(() => {
121
- const l = t.options.targets.filter(
122
- (r) => !n.some((s) => s.targetId === r.id)
119
+ x(u);
120
+ }, [s, t.options.sources]), D(() => {
121
+ const u = t.options.targets.filter(
122
+ (n) => !s.some((e) => e.targetId === n.id)
123
123
  );
124
- C(l);
125
- }, [n, t.options.targets]), {
124
+ g(u);
125
+ }, [s, t.options.targets]), {
126
126
  // data
127
127
  sources: t.options.sources,
128
128
  targets: t.options.targets,
129
- answers: n,
129
+ answers: s,
130
130
  question: t,
131
- availableSources: v,
132
- availableTargets: L,
131
+ availableSources: S,
132
+ availableTargets: k,
133
133
  // base
134
- submitted: u,
135
- isCorrect: g,
136
- attempts: w,
137
- canAnswer: c,
134
+ submitted: i,
135
+ isCorrect: m,
136
+ attempts: b,
137
+ canAnswer: o,
138
138
  // actions
139
139
  select: p,
140
- remove: I,
141
- submit: a,
142
- reset: m
140
+ remove: w,
141
+ submit: l,
142
+ reset: f
143
143
  };
144
144
  }
145
- function P(t) {
145
+ function V(t) {
146
146
  const {
147
- canAnswer: c,
148
- submitted: u,
149
- isCorrect: g,
150
- attempts: w,
151
- resetQuestion: h,
152
- submitQuestion: Q
153
- } = M();
154
- function n() {
155
- Q(!0);
147
+ canAnswer: o,
148
+ submitted: i,
149
+ isCorrect: m,
150
+ attempts: b,
151
+ resetQuestion: C,
152
+ submitQuestion: h
153
+ } = O();
154
+ function s() {
155
+ h(!0);
156
156
  }
157
- function d() {
158
- h();
157
+ function a() {
158
+ C();
159
159
  }
160
160
  return {
161
161
  // data
@@ -163,413 +163,410 @@ function P(t) {
163
163
  url: t.options.url,
164
164
  type: t.options.urlType,
165
165
  // actions
166
- submit: n,
167
- reset: d,
166
+ submit: s,
167
+ reset: a,
168
168
  // base
169
- submitted: u,
170
- isCorrect: g,
171
- attempts: w,
172
- canAnswer: c
169
+ submitted: i,
170
+ isCorrect: m,
171
+ attempts: b,
172
+ canAnswer: o
173
173
  };
174
174
  }
175
175
  function T(t) {
176
176
  const {
177
- canAnswer: c,
178
- submitted: u,
179
- isCorrect: g,
180
- attempts: w,
181
- submitQuestion: h,
182
- resetQuestion: Q
183
- } = M(), [n, d] = S([]), [v, O] = S(null), L = () => {
184
- const o = new Set(n.map((e) => e.itemId));
185
- return t.options.items.filter((e) => !o.has(e.id));
186
- }, [C, p] = S(
187
- L()
188
- );
189
- function I(o, e) {
190
- if (!t.options.dropZones.find((b) => b.id === e)) return;
191
- const x = n.filter((b) => b.zoneId === e).length;
192
- d((b) => [
193
- ...b.filter((Z) => Z.itemId !== o),
177
+ canAnswer: o,
178
+ submitted: i,
179
+ isCorrect: m,
180
+ attempts: b,
181
+ submitQuestion: C,
182
+ resetQuestion: h
183
+ } = O(), [s, a] = Q([]), [S, x] = Q(null), k = _(() => {
184
+ const n = new Set(s.map((e) => e.itemId));
185
+ return t.options.answers.filter((e) => !n.has(String(e.id)));
186
+ }, [s, t.options.answers]);
187
+ function g(n, e) {
188
+ if (!t.options.groups.find((A) => A.id === e)) return;
189
+ const d = s.filter((A) => A.groupId === e).length;
190
+ a((A) => [
191
+ ...A.filter((L) => L.itemId !== n),
194
192
  {
195
- itemId: o,
196
- zoneId: e,
197
- position: x
193
+ itemId: n,
194
+ groupId: e,
195
+ position: d
198
196
  }
199
197
  ]);
200
198
  }
201
- function A(o) {
202
- d((e) => e.filter((i) => i.itemId !== o));
199
+ function p(n) {
200
+ a((e) => e.filter((r) => r.itemId !== n));
203
201
  }
204
- function a(o, e) {
205
- I(o, e);
202
+ function w(n, e) {
203
+ g(n, e);
206
204
  }
207
- function m(o) {
208
- return n.filter((e) => e.zoneId === o).sort((e, i) => e.position - i.position).map((e) => t.options.items.find(
209
- (f) => f.id === e.itemId
205
+ function I(n) {
206
+ return s.filter((e) => e.groupId === n).sort((e, r) => e.position - r.position).map((e) => t.options.answers.find(
207
+ (c) => c.id === e.itemId
210
208
  )).filter(Boolean);
211
209
  }
212
210
  function l() {
213
- let o = 0, e = !0;
214
- return t.options.items.forEach((i) => {
215
- const f = n.find((b) => b.itemId === i.id), x = t.options.dropZones.find(
216
- (b) => b.position === i.correctPosition
217
- );
218
- f && x && f.zoneId === x.id ? o += i.point : e = !1;
211
+ let n = 0, e = !0;
212
+ return t.options.answers.forEach((r) => {
213
+ const c = s.find((d) => d.itemId === r.id);
214
+ if (r.correct_position !== void 0 && r.correct_position !== null) {
215
+ const d = t.options.groups.find(
216
+ (A) => A.position === r.correct_position
217
+ );
218
+ c && d && c.groupId === d.id ? n += r.point : e = !1;
219
+ }
219
220
  }), {
220
221
  isCorrect: e,
221
- score: o,
222
- maxScore: t.options.items.reduce(
223
- (i, f) => i + f.point,
222
+ score: n,
223
+ maxScore: t.options.answers.reduce(
224
+ (r, c) => r + c.point,
224
225
  0
225
226
  )
226
227
  };
227
228
  }
228
- function r() {
229
- const o = l();
230
- return h(o.isCorrect), o;
229
+ function f() {
230
+ const n = l();
231
+ return C(n.isCorrect), n;
231
232
  }
232
- function s() {
233
- d([]), Q();
233
+ function u() {
234
+ a([]), h();
234
235
  }
235
- return y(() => {
236
- p(L());
237
- }, [n]), {
236
+ return {
238
237
  // data
239
- items: t.options.items,
240
- dropZones: t.options.dropZones,
241
- answers: n,
242
- availableItems: C,
238
+ items: t.options.answers,
239
+ groups: t.options.groups,
240
+ answers: s,
241
+ availableItems: k,
243
242
  question: t,
244
- draggingItemId: v,
243
+ draggingItemId: S,
245
244
  // base
246
- submitted: u,
247
- isCorrect: g,
248
- attempts: w,
249
- canAnswer: c,
245
+ submitted: i,
246
+ isCorrect: m,
247
+ attempts: b,
248
+ canAnswer: o,
250
249
  // actions
251
- dropItem: I,
252
- removeItem: A,
253
- moveItem: a,
254
- getItemsInZone: m,
255
- setDraggingItemId: O,
256
- submit: r,
257
- reset: s
250
+ dropItem: g,
251
+ removeItem: p,
252
+ moveItem: w,
253
+ getItemsInGroup: I,
254
+ setDraggingItemId: x,
255
+ submit: f,
256
+ reset: u
258
257
  };
259
258
  }
260
- function _(t) {
259
+ function j(t) {
261
260
  const {
262
- canAnswer: c,
263
- submitted: u,
264
- isCorrect: g,
265
- attempts: w,
266
- submitQuestion: h,
267
- resetQuestion: Q
268
- } = M(), [n, d] = S(() => t.options.items.map((r) => r.id)), [v, O] = S(null);
269
- function L() {
270
- return n.map((r) => t.options.items.find((s) => s.id === r)).filter((r) => r !== void 0);
271
- }
272
- function C(r, s) {
273
- d((o) => {
274
- const e = [...o], [i] = e.splice(r, 1);
275
- return e.splice(s, 0, i), e;
261
+ canAnswer: o,
262
+ submitted: i,
263
+ isCorrect: m,
264
+ attempts: b,
265
+ submitQuestion: C,
266
+ resetQuestion: h
267
+ } = O(), [s, a] = Q(() => t.options.answers.map((n) => String(n.id))), [S, x] = Q(null), k = _(() => s.map((n) => t.options.answers.find((e) => String(e.id) === n)).filter((n) => n !== void 0), [s, t.options.answers]);
268
+ function g(n, e) {
269
+ a((r) => {
270
+ const c = [...r], [d] = c.splice(n, 1);
271
+ return c.splice(e, 0, d), c;
276
272
  });
277
273
  }
278
- function p(r) {
279
- const s = n.indexOf(r);
280
- s > 0 && C(s, s - 1);
274
+ function p(n) {
275
+ const e = s.indexOf(n);
276
+ e > 0 && g(e, e - 1);
281
277
  }
282
- function I(r) {
283
- const s = n.indexOf(r);
284
- s < n.length - 1 && C(s, s + 1);
278
+ function w(n) {
279
+ const e = s.indexOf(n);
280
+ e < s.length - 1 && g(e, e + 1);
285
281
  }
286
- function A(r, s) {
287
- const o = n.indexOf(r);
288
- o !== -1 && s >= 0 && s < n.length && C(o, s);
282
+ function I(n, e) {
283
+ const r = s.indexOf(n);
284
+ r !== -1 && e >= 0 && e < s.length && g(r, e);
289
285
  }
290
- function a() {
291
- let r = 0, s = !0;
292
- return n.forEach((o, e) => {
293
- const i = t.options.items.find((f) => f.id === o);
294
- i && (e === i.correctOrder ? r += i.point : s = !1);
286
+ function l() {
287
+ let n = 0, e = !0;
288
+ return t.options.answers.forEach((r, c) => {
289
+ const d = s.indexOf(String(r.id));
290
+ d !== -1 && d + 1 === r.correct_position ? n += r.point : e = !1;
295
291
  }), {
296
- isCorrect: s,
297
- score: r,
298
- maxScore: t.options.items.reduce(
299
- (o, e) => o + e.point,
292
+ isCorrect: e,
293
+ score: n,
294
+ maxScore: t.options.answers.reduce(
295
+ (r, c) => r + c.point,
300
296
  0
301
297
  )
302
298
  };
303
299
  }
304
- function m() {
305
- const r = a();
306
- return h(r.isCorrect), r;
300
+ function f() {
301
+ const n = l();
302
+ return C(n.isCorrect), n;
307
303
  }
308
- function l() {
309
- d(t.options.items.map((r) => r.id)), Q();
304
+ function u() {
305
+ a(t.options.answers.map((n) => String(n.id))), h();
310
306
  }
311
307
  return {
312
308
  // data
313
- items: t.options.items,
314
- orderedItems: L(),
315
- orderedItemIds: n,
309
+ items: t.options.answers,
310
+ groups: t.options.groups,
311
+ orderedItems: k,
312
+ orderedItemIds: s,
316
313
  question: t,
317
- draggingItemId: v,
314
+ draggingItemId: S,
318
315
  // base
319
- submitted: u,
320
- isCorrect: g,
321
- attempts: w,
322
- canAnswer: c,
316
+ submitted: i,
317
+ isCorrect: m,
318
+ attempts: b,
319
+ canAnswer: o,
323
320
  // actions
324
- moveItem: C,
321
+ moveItem: g,
325
322
  moveUp: p,
326
- moveDown: I,
327
- moveToPosition: A,
328
- setDraggingItemId: O,
329
- submit: m,
330
- reset: l
323
+ moveDown: w,
324
+ moveToPosition: I,
325
+ setDraggingItemId: x,
326
+ submit: f,
327
+ reset: u
331
328
  };
332
329
  }
333
- function j(t) {
330
+ function F(t) {
334
331
  const {
335
- canAnswer: c,
336
- submitted: u,
337
- isCorrect: g,
338
- attempts: w,
339
- submitQuestion: h,
340
- resetQuestion: Q
341
- } = M(), [n, d] = S([]), [v, O] = S(null), L = () => {
342
- const e = new Set(n.map((i) => i.labelId));
332
+ canAnswer: o,
333
+ submitted: i,
334
+ isCorrect: m,
335
+ attempts: b,
336
+ submitQuestion: C,
337
+ resetQuestion: h
338
+ } = O(), [s, a] = Q([]), [S, x] = Q(null), k = _(() => {
339
+ const e = new Set(s.map((r) => r.labelId));
343
340
  return t.options.labels.filter(
344
- (i) => !e.has(i.id)
341
+ (r) => !e.has(String(r.id))
345
342
  );
346
- }, [C, p] = S(
347
- L()
348
- );
349
- function I(e, i, f, x) {
350
- const b = t.options.points.find((D) => D.id === i);
351
- b && d((D) => [
352
- ...D.filter((E) => E.labelId !== e),
343
+ }, [s, t.options.labels]);
344
+ function g(e, r, c, d) {
345
+ const A = t.options.blanks.find((v) => String(v.id) === r);
346
+ A && a((v) => [
347
+ ...v.filter((B) => B.labelId !== e),
353
348
  {
354
349
  labelId: e,
355
- pointId: i,
356
- x: f ?? b.x,
357
- y: x ?? b.y
350
+ blankId: r,
351
+ x: c ?? A.coordinates.x,
352
+ y: d ?? A.coordinates.y
358
353
  }
359
354
  ]);
360
355
  }
361
- function A(e) {
362
- d((i) => i.filter((f) => f.labelId !== e));
356
+ function p(e) {
357
+ a((r) => r.filter((c) => c.labelId !== e));
363
358
  }
364
- function a(e, i, f, x) {
365
- I(e, i, f, x);
359
+ function w(e, r, c, d) {
360
+ g(e, r, c, d);
366
361
  }
367
- function m(e) {
368
- const i = n.find((f) => f.pointId === e);
369
- return i && t.options.labels.find((f) => f.id === i.labelId) || null;
362
+ function I(e) {
363
+ const r = s.find((c) => c.blankId === e);
364
+ return r && t.options.labels.find((c) => String(c.id) === r.labelId) || null;
370
365
  }
371
366
  function l(e) {
372
- const i = n.find((f) => f.labelId === e);
373
- return i ? i.pointId : null;
374
- }
375
- function r() {
376
- let e = 0, i = !0;
377
- return t.options.labels.forEach((f) => {
378
- const x = n.find((b) => b.labelId === f.id);
379
- x && x.pointId === f.correctPointId ? e += f.point : i = !1;
367
+ const r = s.find((c) => c.labelId === e);
368
+ return r ? r.blankId : null;
369
+ }
370
+ function f() {
371
+ let e = 0, r = !0;
372
+ return t.options.labels.forEach((c) => {
373
+ const d = s.find((v) => String(v.labelId) === String(c.id)), A = t.options.blanks.find(
374
+ (v, L) => L + 1 === c.correct_position
375
+ );
376
+ d && A && d.blankId === String(A.id) ? e += c.point : r = !1;
380
377
  }), {
381
- isCorrect: i,
378
+ isCorrect: r,
382
379
  score: e,
383
380
  maxScore: t.options.labels.reduce(
384
- (f, x) => f + x.point,
381
+ (c, d) => c + d.point,
385
382
  0
386
383
  )
387
384
  };
388
385
  }
389
- function s() {
390
- const e = r();
391
- return h(e.isCorrect), e;
386
+ function u() {
387
+ const e = f();
388
+ return C(e.isCorrect), e;
392
389
  }
393
- function o() {
394
- d([]), Q();
390
+ function n() {
391
+ a([]), h();
395
392
  }
396
- return y(() => {
397
- p(L());
398
- }, [n]), {
393
+ return {
399
394
  // data
400
- image: t.options.image,
401
395
  labels: t.options.labels,
402
- points: t.options.points,
403
- answers: n,
404
- availableLabels: C,
396
+ blanks: t.options.blanks,
397
+ groups: t.options.groups,
398
+ imageWidth: t.image_width,
399
+ imageHeight: t.image_height,
400
+ answers: s,
401
+ availableLabels: k,
405
402
  question: t,
406
- draggingLabelId: v,
403
+ draggingLabelId: S,
407
404
  // base
408
- submitted: u,
409
- isCorrect: g,
410
- attempts: w,
411
- canAnswer: c,
405
+ submitted: i,
406
+ isCorrect: m,
407
+ attempts: b,
408
+ canAnswer: o,
412
409
  // actions
413
- attachLabel: I,
414
- removeLabel: A,
415
- moveLabel: a,
416
- getLabelAtPoint: m,
417
- getPointForLabel: l,
418
- setDraggingLabelId: O,
419
- submit: s,
420
- reset: o
410
+ attachLabel: g,
411
+ removeLabel: p,
412
+ moveLabel: w,
413
+ getLabelAtBlank: I,
414
+ getBlankForLabel: l,
415
+ setDraggingLabelId: x,
416
+ submit: u,
417
+ reset: n
421
418
  };
422
419
  }
423
- function F(t) {
420
+ function z(t) {
424
421
  const {
425
- canAnswer: c,
426
- submitted: u,
427
- isCorrect: g,
428
- attempts: w,
429
- submitQuestion: h,
430
- resetQuestion: Q
431
- } = M(), [n, d] = S([]);
432
- function v(p, I) {
433
- d((A) => {
434
- const a = A.findIndex((m) => m.blankId === p);
435
- if (a >= 0) {
436
- const m = [...A];
437
- return m[a] = { blankId: p, value: I }, m;
422
+ canAnswer: o,
423
+ submitted: i,
424
+ isCorrect: m,
425
+ attempts: b,
426
+ submitQuestion: C,
427
+ resetQuestion: h
428
+ } = O(), [s, a] = Q([]);
429
+ function S(p, w) {
430
+ a((I) => {
431
+ const l = I.findIndex((f) => f.blankId === p);
432
+ if (l >= 0) {
433
+ const f = [...I];
434
+ return f[l] = { blankId: p, value: w }, f;
438
435
  }
439
- return [...A, { blankId: p, value: I }];
436
+ return [...I, { blankId: p, value: w }];
440
437
  });
441
438
  }
442
- function O() {
443
- let p = 0, I = 0, A = 0;
444
- const a = t.correct_answers.list || {}, m = Object.keys(a).length;
445
- Object.entries(a).forEach(([r, s]) => {
446
- const o = String(s).trim().toLowerCase(), e = t.options.answers.find(
447
- (b) => b.correct_position === Number(r)
448
- ), i = e && e.point || 1;
449
- A += i;
450
- const f = n.find((b) => b.blankId === r);
451
- (f ? String(f.value).trim().toLowerCase() : "") === o && (p += i, I++);
439
+ function x() {
440
+ let p = 0, w = 0, I = 0;
441
+ const l = t.correct_answers.list || {}, f = Object.keys(l).length;
442
+ Object.entries(l).forEach(([n, e]) => {
443
+ const r = String(e).trim().toLowerCase(), c = t.options.answers.find(
444
+ (L) => L.correct_position === Number(n)
445
+ ), d = c && c.point || 1;
446
+ I += d;
447
+ const A = s.find((L) => L.blankId === n);
448
+ (A ? String(A.value).trim().toLowerCase() : "") === r && (p += d, w++);
452
449
  });
453
- const l = I === m && m > 0;
454
- return A === 0 && m > 0 && (A = m), {
455
- isCorrect: l,
450
+ const u = w === f && f > 0;
451
+ return I === 0 && f > 0 && (I = f), {
452
+ isCorrect: u,
456
453
  score: Math.round(p * 100) / 100,
457
- maxScore: Math.round(A * 100) / 100
454
+ maxScore: Math.round(I * 100) / 100
458
455
  };
459
456
  }
460
- function L() {
461
- const p = O();
462
- return h(p.isCorrect), p;
457
+ function k() {
458
+ const p = x();
459
+ return C(p.isCorrect), p;
463
460
  }
464
- function C() {
465
- d([]), Q();
461
+ function g() {
462
+ a([]), h();
466
463
  }
467
464
  return {
468
465
  // data
469
466
  groups: t.options.groups,
470
- answers: n,
467
+ answers: s,
471
468
  question: t,
472
469
  // base
473
- submitted: u,
474
- isCorrect: g,
475
- attempts: w,
476
- canAnswer: c,
470
+ submitted: i,
471
+ isCorrect: m,
472
+ attempts: b,
473
+ canAnswer: o,
477
474
  // actions
478
- answer: v,
479
- submit: L,
480
- reset: C
475
+ answer: S,
476
+ submit: k,
477
+ reset: g
481
478
  };
482
479
  }
483
- function G(t) {
480
+ function W(t) {
484
481
  const {
485
- canAnswer: c,
486
- submitted: u,
487
- isCorrect: g,
488
- attempts: w,
489
- submitQuestion: h,
490
- resetQuestion: Q
491
- } = M(), [n, d] = S([]);
492
- function v(a, m) {
493
- d((l) => {
494
- const r = l.findIndex((s) => s.itemId === a);
495
- if (r >= 0) {
496
- const s = [...l];
497
- return s[r] = { itemId: a, categoryId: m }, s;
482
+ canAnswer: o,
483
+ submitted: i,
484
+ isCorrect: m,
485
+ attempts: b,
486
+ submitQuestion: C,
487
+ resetQuestion: h
488
+ } = O(), [s, a] = Q([]);
489
+ function S(l, f) {
490
+ a((u) => {
491
+ const n = u.findIndex((e) => e.itemId === l);
492
+ if (n >= 0) {
493
+ const e = [...u];
494
+ return e[n] = { itemId: l, categoryId: f }, e;
498
495
  }
499
- return [...l, { itemId: a, categoryId: m }];
496
+ return [...u, { itemId: l, categoryId: f }];
500
497
  });
501
498
  }
502
- function O(a) {
503
- d((m) => m.filter((l) => l.itemId !== a));
504
- }
505
- function L() {
506
- let a = 0, m = 0;
507
- const r = t.correct_answers.list || {}, s = Object.keys(r).length;
508
- let o = 0;
509
- return Object.entries(r).forEach(([i, f]) => {
510
- const x = t.options.items.find((Z) => Z.id === i), b = x ? x.point : 0;
511
- o += b;
512
- const D = n.find((Z) => Z.itemId === i);
513
- D && D.categoryId === f && (a += b, m++);
514
- }), a = Math.round(a * 100) / 100, o = Math.round(o * 100) / 100, {
515
- isCorrect: m === s && s > 0,
516
- score: a,
517
- maxScore: o
499
+ function x(l) {
500
+ a((f) => f.filter((u) => u.itemId !== l));
501
+ }
502
+ function k() {
503
+ let l = 0, f = 0;
504
+ const n = t.correct_answers.list || {}, e = Object.keys(n).length;
505
+ let r = 0;
506
+ return Object.entries(n).forEach(([d, A]) => {
507
+ const v = t.options.items.find((M) => M.id === d), L = v ? v.point : 0;
508
+ r += L;
509
+ const B = s.find((M) => M.itemId === d);
510
+ B && B.categoryId === A && (l += L, f++);
511
+ }), l = Math.round(l * 100) / 100, r = Math.round(r * 100) / 100, {
512
+ isCorrect: f === e && e > 0,
513
+ score: l,
514
+ maxScore: r
518
515
  };
519
516
  }
520
- function C() {
521
- const a = L();
522
- return h(a.isCorrect), a;
517
+ function g() {
518
+ const l = k();
519
+ return C(l.isCorrect), l;
523
520
  }
524
521
  function p() {
525
- d([]), Q();
522
+ a([]), h();
526
523
  }
527
- const I = B(() => t.options.items.filter(
528
- (a) => !n.some((m) => m.itemId === a.id)
529
- ), [t.options.items, n]), A = B(() => t.options.categories.map((a) => {
530
- const m = n.filter((l) => l.categoryId === a.id).map((l) => ({
531
- ...t.options.items.find((s) => s.id === l.itemId)
524
+ const w = _(() => t.options.items.filter(
525
+ (l) => !s.some((f) => f.itemId === l.id)
526
+ ), [t.options.items, s]), I = _(() => t.options.categories.map((l) => {
527
+ const f = s.filter((u) => u.categoryId === l.id).map((u) => ({
528
+ ...t.options.items.find((e) => e.id === u.itemId)
532
529
  }));
533
530
  return {
534
- ...a,
535
- items: m
531
+ ...l,
532
+ items: f
536
533
  };
537
- }), [t.options.categories, t.options.items, n]);
534
+ }), [t.options.categories, t.options.items, s]);
538
535
  return {
539
536
  // data
540
537
  categories: t.options.categories,
541
538
  allItems: t.options.items,
542
539
  question: t,
543
- categoriesWithItems: A,
540
+ categoriesWithItems: I,
544
541
  // state
545
- answers: n,
546
- unassignedItems: I,
542
+ answers: s,
543
+ unassignedItems: w,
547
544
  // base
548
- submitted: u,
549
- isCorrect: g,
550
- attempts: w,
551
- canAnswer: c,
545
+ submitted: i,
546
+ isCorrect: m,
547
+ attempts: b,
548
+ canAnswer: o,
552
549
  // actions
553
- move: v,
554
- remove: O,
555
- submit: C,
550
+ move: S,
551
+ remove: x,
552
+ submit: g,
556
553
  reset: p
557
554
  };
558
555
  }
559
- function N(t) {
556
+ function H(t) {
560
557
  const {
561
- canAnswer: c,
562
- submitted: u,
563
- isCorrect: g,
564
- attempts: w,
565
- resetQuestion: h,
566
- submitQuestion: Q
567
- } = M();
568
- function n() {
569
- u || Q(!0);
558
+ canAnswer: o,
559
+ submitted: i,
560
+ isCorrect: m,
561
+ attempts: b,
562
+ resetQuestion: C,
563
+ submitQuestion: h
564
+ } = O();
565
+ function s() {
566
+ i || h(!0);
570
567
  }
571
- function d() {
572
- h();
568
+ function a() {
569
+ C();
573
570
  }
574
571
  return {
575
572
  // data
@@ -577,97 +574,97 @@ function N(t) {
577
574
  url: t.options.url,
578
575
  type: t.options.urlType,
579
576
  // actions
580
- submit: n,
581
- reset: d,
577
+ submit: s,
578
+ reset: a,
582
579
  // base
583
- submitted: u,
584
- isCorrect: g,
585
- attempts: w,
586
- canAnswer: c
580
+ submitted: i,
581
+ isCorrect: m,
582
+ attempts: b,
583
+ canAnswer: o
587
584
  };
588
585
  }
589
- function W({
586
+ function P({
590
587
  getData: t,
591
- children: c
588
+ children: o
592
589
  }) {
593
- const u = V(t());
594
- return c(u);
590
+ const i = E(t());
591
+ return o(i);
595
592
  }
596
- function H({
593
+ function U({
597
594
  getData: t,
598
- children: c
595
+ children: o
599
596
  }) {
600
- const u = z(t());
601
- return c(u);
597
+ const i = G(t());
598
+ return o(i);
602
599
  }
603
600
  function J({
604
601
  getData: t,
605
- children: c
602
+ children: o
606
603
  }) {
607
- const u = P(t());
608
- return c(u);
604
+ const i = V(t());
605
+ return o(i);
609
606
  }
610
607
  function R({
611
608
  getData: t,
612
- children: c
609
+ children: o
613
610
  }) {
614
- const u = T(t());
615
- return c(u);
611
+ const i = T(t());
612
+ return o(i);
616
613
  }
617
614
  function X({
618
615
  getData: t,
619
- children: c
616
+ children: o
620
617
  }) {
621
- const u = _(t());
622
- return c(u);
618
+ const i = j(t());
619
+ return o(i);
623
620
  }
624
621
  function Y({
625
622
  getData: t,
626
- children: c
623
+ children: o
627
624
  }) {
628
- const u = j(t());
629
- return c(u);
625
+ const i = F(t());
626
+ return o(i);
630
627
  }
631
- function $({
628
+ function Z({
632
629
  getData: t,
633
- children: c
630
+ children: o
634
631
  }) {
635
- const u = F(t());
636
- return c(u);
632
+ const i = z(t());
633
+ return o(i);
637
634
  }
638
- function K({
635
+ function $({
639
636
  getData: t,
640
- children: c
637
+ children: o
641
638
  }) {
642
- const u = G(t());
643
- return c(u);
639
+ const i = W(t());
640
+ return o(i);
644
641
  }
645
- function q({
642
+ function K({
646
643
  getData: t,
647
- children: c
644
+ children: o
648
645
  }) {
649
- const u = N(t());
650
- return c(u);
646
+ const i = H(t());
647
+ return o(i);
651
648
  }
652
649
  export {
653
650
  R as DragDropQuestion,
654
- $ as FillInBlankQuestion,
655
- K as GroupingQuestion,
651
+ Z as FillInBlankQuestion,
652
+ $ as GroupingQuestion,
656
653
  Y as LabelingQuestion,
657
- H as MatchingQuestion,
658
- W as MultipleChoicesQuestion,
654
+ U as MatchingQuestion,
655
+ P as MultipleChoicesQuestion,
659
656
  X as OrderingQuestion,
660
- q as PowerpointQuestion,
657
+ K as PowerpointQuestion,
661
658
  J as VideoQuestion,
662
- k as isSameSet,
663
- M as useBaseQuestion,
659
+ y as isSameSet,
660
+ O as useBaseQuestion,
664
661
  T as useDragDrop,
665
- F as useFillInBlank,
666
- G as useGrouping,
667
- j as useLabeling,
668
- z as useMatching,
669
- V as useMultipleChoice,
670
- _ as useOrdering,
671
- N as usePowerpoint,
672
- P as useVideo
662
+ z as useFillInBlank,
663
+ W as useGrouping,
664
+ F as useLabeling,
665
+ G as useMatching,
666
+ E as useMultipleChoice,
667
+ j as useOrdering,
668
+ H as usePowerpoint,
669
+ V as useVideo
673
670
  };