@enspiredigital/xlms-headless 0.0.20 → 0.0.22

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