@enspiredigital/xlms-headless 0.0.5 → 0.0.6

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