@enspiredigital/xlms-headless 0.0.6 → 0.0.7

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 +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;iBAa9B,MAAM;;;;;;;EAoF3B"}
package/dist/index.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import { useState as b, 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] = b(null), [s, c] = b(null), [a, p] = b(0);
4
+ function g(u) {
5
+ t || (e(!0), c(u), p((C) => C + 1));
6
6
  }
7
7
  function r() {
8
- e(!1), u(null);
8
+ e(!1), c(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
@@ -21,34 +21,34 @@ function S() {
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), c = new Set(e);
25
+ if (s.size !== c.size) return !1;
26
+ for (const a of s)
27
+ if (!c.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,
34
+ isCorrect: c,
35
+ attempts: a,
36
36
  resetQuestion: p,
37
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]);
38
+ } = S(), [r, u] = b([]);
39
+ function C(d) {
40
+ u((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);
47
+ ), n = k(r, d);
48
48
  g(n);
49
49
  }
50
- function h() {
51
- l([]), p();
50
+ function I() {
51
+ u([]), p();
52
52
  }
53
53
  return {
54
54
  // data
@@ -56,12 +56,12 @@ function V(t) {
56
56
  selectedIds: r,
57
57
  // actions
58
58
  select: C,
59
- submit: Q,
60
- reset: h,
59
+ submit: h,
60
+ reset: I,
61
61
  // base
62
62
  submitted: s,
63
- isCorrect: u,
64
- attempts: f,
63
+ isCorrect: c,
64
+ attempts: a,
65
65
  canAnswer: e
66
66
  };
67
67
  }
@@ -69,63 +69,59 @@ function v(t) {
69
69
  const {
70
70
  canAnswer: e,
71
71
  submitted: s,
72
- isCorrect: u,
73
- attempts: f,
72
+ isCorrect: c,
73
+ attempts: a,
74
74
  submitQuestion: p,
75
75
  resetQuestion: g
76
- } = S(), [r, l] = b([]), [C, Q] = b(
76
+ } = S(), [r, u] = b([]), [C, h] = b(
77
77
  []
78
- ), [h, m] = b(
78
+ ), [I, d] = b(
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
+ u((i) => [
83
+ ...i.filter(
84
+ (A) => A.targetId !== o && A.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) {
90
+ u(
91
+ (m) => m.filter((i) => i.targetId !== o && i.sourceId !== o)
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((i) => {
97
+ const A = r.find((M) => M.targetId === i.id), x = t.options.sources[i.content.correct_position - 1];
98
+ A && x && A.sourceId === x.id ? o += i.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
+ (i, A) => i + A.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 p(o.isCorrect), o;
111
111
  }
112
112
  function w() {
113
- l([]), g();
113
+ u([]), g();
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((i) => i.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((i) => i.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,
@@ -133,16 +129,16 @@ function v(t) {
133
129
  answers: r,
134
130
  question: t,
135
131
  availableSources: C,
136
- availableTargets: h,
132
+ availableTargets: I,
137
133
  // base
138
134
  submitted: s,
139
- isCorrect: u,
140
- attempts: f,
135
+ isCorrect: c,
136
+ attempts: a,
141
137
  canAnswer: e,
142
138
  // actions
143
139
  select: n,
144
- remove: a,
145
- submit: A,
140
+ remove: l,
141
+ submit: Q,
146
142
  reset: w
147
143
  };
148
144
  }
@@ -150,15 +146,15 @@ function T(t) {
150
146
  const {
151
147
  canAnswer: e,
152
148
  submitted: s,
153
- isCorrect: u,
154
- attempts: f,
149
+ isCorrect: c,
150
+ attempts: a,
155
151
  resetQuestion: p,
156
152
  submitQuestion: g
157
153
  } = S();
158
154
  function r() {
159
155
  g(!0);
160
156
  }
161
- function l() {
157
+ function u() {
162
158
  p();
163
159
  }
164
160
  return {
@@ -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: u,
172
168
  // base
173
169
  submitted: s,
174
- isCorrect: u,
175
- attempts: f,
170
+ isCorrect: c,
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,
179
+ isCorrect: c,
180
+ attempts: a,
185
181
  submitQuestion: p,
186
182
  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;
183
+ } = S(), [r, u] = b([]);
184
+ function C(n, l) {
185
+ e && u((f) => {
186
+ const Q = f.findIndex((w) => w.targetId === n);
187
+ if (Q >= 0) {
188
+ const w = [...f];
189
+ return w[Q] = { targetId: n, value: l }, w;
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() : "", w = l.content.correct_answer.trim();
201
+ if (Q.toLowerCase() !== w.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();
212
+ function I() {
213
+ const n = h();
218
214
  return p(n.isCorrect), n;
219
215
  }
220
- function m() {
221
- l([]), g();
216
+ function d() {
217
+ u([]), g();
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: c,
227
+ attempts: a,
232
228
  canAnswer: e,
233
229
  // actions
234
230
  answer: C,
235
- submit: h,
236
- reset: m
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.7",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",