@enspiredigital/xlms-headless 0.0.16 → 0.0.18

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