@enspiredigital/xlms-headless 0.0.19 → 0.0.20

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