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