@enspiredigital/xlms-headless 0.0.6 → 0.0.8

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.
@@ -11,7 +11,7 @@ export declare function useMatching(question: MatchingQuestionType): {
11
11
  attempts: number;
12
12
  canAnswer: boolean;
13
13
  select: (targetId: string, sourceId: string) => void;
14
- remove: (id: string) => void;
14
+ remove: (targetId: string, sourceId: string) => void;
15
15
  submit: () => {
16
16
  isCorrect: boolean;
17
17
  score: number;
@@ -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;iBAa9B,MAAM;;;;;;;EAgG3B"}
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"}
package/dist/index.js CHANGED
@@ -1,67 +1,67 @@
1
- import { useState as b, useEffect as B } from "react";
1
+ import { useState as C, useEffect as B } from "react";
2
2
  function S() {
3
- const [t, e] = b(null), [s, u] = b(null), [f, p] = b(0);
4
- function g(l) {
5
- t || (e(!0), u(l), p((C) => C + 1));
3
+ const [t, e] = C(null), [s, i] = C(null), [a, g] = C(0);
4
+ function w(c) {
5
+ t || (e(!0), i(c), g((A) => A + 1));
6
6
  }
7
7
  function r() {
8
- e(!1), u(null);
8
+ e(!1), i(null);
9
9
  }
10
10
  return {
11
11
  // state
12
12
  submitted: t,
13
13
  isCorrect: s,
14
- attempts: f,
14
+ attempts: a,
15
15
  // derived
16
16
  canAnswer: !t,
17
17
  // actions
18
- submitQuestion: g,
18
+ submitQuestion: w,
19
19
  resetQuestion: r
20
20
  };
21
21
  }
22
22
  function k(t, e) {
23
23
  if (t.length !== e.length) return !1;
24
- const s = new Set(t), u = new Set(e);
25
- if (s.size !== u.size) return !1;
26
- for (const f of s)
27
- if (!u.has(f)) return !1;
24
+ const s = new Set(t), i = new Set(e);
25
+ if (s.size !== i.size) return !1;
26
+ for (const a of s)
27
+ if (!i.has(a)) return !1;
28
28
  return !0;
29
29
  }
30
30
  function V(t) {
31
31
  const {
32
32
  canAnswer: e,
33
33
  submitted: s,
34
- isCorrect: u,
35
- attempts: f,
36
- resetQuestion: p,
37
- submitQuestion: g
38
- } = S(), [r, l] = b([]);
39
- function C(m) {
40
- l((n) => t.options.allowMultipleAnswers ? n.includes(m) ? n.filter((a) => a !== m) : [...n, m] : [m]);
34
+ isCorrect: i,
35
+ attempts: a,
36
+ resetQuestion: g,
37
+ submitQuestion: w
38
+ } = S(), [r, c] = C([]);
39
+ function A(d) {
40
+ c((n) => t.options.allowMultipleAnswers ? n.includes(d) ? n.filter((l) => l !== d) : [...n, d] : [d]);
41
41
  }
42
- function Q() {
42
+ function h() {
43
43
  if (r.length === 0) return;
44
- const m = t.options.answers.reduce(
45
- (a, d) => (d.is_correct && a.push(d.id), a),
44
+ const d = t.options.answers.reduce(
45
+ (l, f) => (f.is_correct && l.push(f.id), l),
46
46
  []
47
- ), n = k(r, m);
48
- g(n);
47
+ ), n = k(r, d);
48
+ w(n);
49
49
  }
50
- function h() {
51
- l([]), p();
50
+ function I() {
51
+ c([]), g();
52
52
  }
53
53
  return {
54
54
  // data
55
55
  question: t,
56
56
  selectedIds: r,
57
57
  // actions
58
- select: C,
59
- submit: Q,
60
- reset: h,
58
+ select: A,
59
+ submit: h,
60
+ reset: I,
61
61
  // base
62
62
  submitted: s,
63
- isCorrect: u,
64
- attempts: f,
63
+ isCorrect: i,
64
+ attempts: a,
65
65
  canAnswer: e
66
66
  };
67
67
  }
@@ -69,97 +69,93 @@ function v(t) {
69
69
  const {
70
70
  canAnswer: e,
71
71
  submitted: s,
72
- isCorrect: u,
73
- attempts: f,
74
- submitQuestion: p,
75
- resetQuestion: g
76
- } = S(), [r, l] = b([]), [C, Q] = b(
72
+ isCorrect: i,
73
+ attempts: a,
74
+ submitQuestion: g,
75
+ resetQuestion: w
76
+ } = S(), [r, c] = C([]), [A, h] = C(
77
77
  []
78
- ), [h, m] = b(
78
+ ), [I, d] = C(
79
79
  []
80
80
  );
81
- function n(i, c) {
82
- l((o) => [
83
- ...o.filter(
84
- (I) => I.targetId !== i && I.sourceId !== c
81
+ function n(o, m) {
82
+ c((u) => [
83
+ ...u.filter(
84
+ (p) => p.targetId !== o && p.sourceId !== m
85
85
  ),
86
- { targetId: i, sourceId: c }
86
+ { targetId: o, sourceId: m }
87
87
  ]);
88
88
  }
89
- function a(i) {
90
- l(
91
- (c) => c.filter((o) => o.targetId !== i || o.sourceId !== i)
89
+ function l(o, m) {
90
+ c(
91
+ (u) => u.filter((p) => p.targetId !== o || p.sourceId !== m)
92
92
  );
93
93
  }
94
- function d() {
95
- let i = 0, c = !0;
96
- return t.options.targets.forEach((o) => {
97
- const I = r.find((M) => M.targetId === o.id), x = t.options.sources[o.content.correct_position - 1];
98
- I && x && I.sourceId === x.id ? i += o.content.point : c = !1;
94
+ function f() {
95
+ let o = 0, m = !0;
96
+ return t.options.targets.forEach((u) => {
97
+ const p = r.find((M) => M.targetId === u.id), x = t.options.sources[u.content.correct_position - 1];
98
+ p && x && p.sourceId === x.id ? o += u.content.point : m = !1;
99
99
  }), {
100
- isCorrect: c,
101
- score: i,
100
+ isCorrect: m,
101
+ score: o,
102
102
  maxScore: t.options.targets.reduce(
103
- (o, I) => o + I.content.point,
103
+ (u, p) => u + p.content.point,
104
104
  0
105
105
  )
106
106
  };
107
107
  }
108
- function A() {
109
- const i = d();
110
- return p(i.isCorrect), i;
108
+ function Q() {
109
+ const o = f();
110
+ return g(o.isCorrect), o;
111
111
  }
112
- function w() {
113
- l([]), g();
112
+ function b() {
113
+ c([]), w();
114
114
  }
115
115
  return B(() => {
116
- const i = t.options.sources.filter(
117
- (c) => !r.some(
118
- (o) => o.sourceId === c.id || o.sourceId.includes(c.id) || c.id.includes(o.sourceId)
119
- )
116
+ const o = t.options.sources.filter(
117
+ (m) => !r.some((u) => u.sourceId === m.id)
120
118
  );
121
- Q(i);
119
+ h(o);
122
120
  }, [r, t.options.sources]), B(() => {
123
- const i = t.options.targets.filter(
124
- (c) => !r.some(
125
- (o) => o.targetId === c.id || o.targetId.includes(c.id) || c.id.includes(o.targetId)
126
- )
121
+ const o = t.options.targets.filter(
122
+ (m) => !r.some((u) => u.targetId === m.id)
127
123
  );
128
- m(i);
124
+ d(o);
129
125
  }, [r, t.options.targets]), {
130
126
  // data
131
127
  sources: t.options.sources,
132
128
  targets: t.options.targets,
133
129
  answers: r,
134
130
  question: t,
135
- availableSources: C,
136
- availableTargets: h,
131
+ availableSources: A,
132
+ availableTargets: I,
137
133
  // base
138
134
  submitted: s,
139
- isCorrect: u,
140
- attempts: f,
135
+ isCorrect: i,
136
+ attempts: a,
141
137
  canAnswer: e,
142
138
  // actions
143
139
  select: n,
144
- remove: a,
145
- submit: A,
146
- reset: w
140
+ remove: l,
141
+ submit: Q,
142
+ reset: b
147
143
  };
148
144
  }
149
145
  function T(t) {
150
146
  const {
151
147
  canAnswer: e,
152
148
  submitted: s,
153
- isCorrect: u,
154
- attempts: f,
155
- resetQuestion: p,
156
- submitQuestion: g
149
+ isCorrect: i,
150
+ attempts: a,
151
+ resetQuestion: g,
152
+ submitQuestion: w
157
153
  } = S();
158
154
  function r() {
159
- g(!0);
155
+ w(!0);
160
156
  }
161
- function l() {
162
- p();
157
+ function c() {
158
+ g();
163
159
  }
164
160
  return {
165
161
  // data
@@ -168,11 +164,11 @@ function T(t) {
168
164
  type: t.options.urlType,
169
165
  // actions
170
166
  submit: r,
171
- reset: l,
167
+ reset: c,
172
168
  // base
173
169
  submitted: s,
174
- isCorrect: u,
175
- attempts: f,
170
+ isCorrect: i,
171
+ attempts: a,
176
172
  canAnswer: e
177
173
  };
178
174
  }
@@ -180,29 +176,29 @@ function _(t) {
180
176
  const {
181
177
  canAnswer: e,
182
178
  submitted: s,
183
- isCorrect: u,
184
- attempts: f,
185
- submitQuestion: p,
186
- resetQuestion: g
187
- } = S(), [r, l] = b([]);
188
- function C(n, a) {
189
- e && l((d) => {
190
- const A = d.findIndex((w) => w.targetId === n);
191
- if (A >= 0) {
192
- const w = [...d];
193
- return w[A] = { targetId: n, value: a }, w;
179
+ isCorrect: i,
180
+ attempts: a,
181
+ submitQuestion: g,
182
+ resetQuestion: w
183
+ } = S(), [r, c] = C([]);
184
+ function A(n, l) {
185
+ e && c((f) => {
186
+ const Q = f.findIndex((b) => b.targetId === n);
187
+ if (Q >= 0) {
188
+ const b = [...f];
189
+ return b[Q] = { targetId: n, value: l }, b;
194
190
  }
195
- return [...d, { targetId: n, value: a }];
191
+ return [...f, { targetId: n, value: l }];
196
192
  });
197
193
  }
198
- function Q() {
194
+ function h() {
199
195
  let n = !0;
200
196
  if (r.length < t.options.targets.length)
201
197
  n = !1;
202
198
  else
203
- for (const a of t.options.targets) {
204
- const d = r.find((i) => i.targetId === a.id), A = d ? d.value.trim() : "", w = a.content.correct_answer.trim();
205
- if (A.toLowerCase() !== w.toLowerCase()) {
199
+ for (const l of t.options.targets) {
200
+ const f = r.find((o) => o.targetId === l.id), Q = f ? f.value.trim() : "", b = l.content.correct_answer.trim();
201
+ if (Q.toLowerCase() !== b.toLowerCase()) {
206
202
  n = !1;
207
203
  break;
208
204
  }
@@ -213,12 +209,12 @@ function _(t) {
213
209
  maxScore: 1
214
210
  };
215
211
  }
216
- function h() {
217
- const n = Q();
218
- return p(n.isCorrect), n;
212
+ function I() {
213
+ const n = h();
214
+ return g(n.isCorrect), n;
219
215
  }
220
- function m() {
221
- l([]), g();
216
+ function d() {
217
+ c([]), w();
222
218
  }
223
219
  return {
224
220
  // data
@@ -227,13 +223,13 @@ function _(t) {
227
223
  question: t,
228
224
  // base
229
225
  submitted: s,
230
- isCorrect: u,
231
- attempts: f,
226
+ isCorrect: i,
227
+ attempts: a,
232
228
  canAnswer: e,
233
229
  // actions
234
- answer: C,
235
- submit: h,
236
- reset: m
230
+ answer: A,
231
+ submit: I,
232
+ reset: d
237
233
  };
238
234
  }
239
235
  function z({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enspiredigital/xlms-headless",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",