@enspiredigital/xlms-headless 0.0.7 → 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;;;;;;;EAoF3B"}
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,11 +1,11 @@
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, c] = b(null), [a, p] = b(0);
4
- function g(u) {
5
- t || (e(!0), c(u), 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), c(null);
8
+ e(!1), i(null);
9
9
  }
10
10
  return {
11
11
  // state
@@ -15,29 +15,29 @@ function S() {
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), c = new Set(e);
25
- if (s.size !== c.size) return !1;
24
+ const s = new Set(t), i = new Set(e);
25
+ if (s.size !== i.size) return !1;
26
26
  for (const a of s)
27
- if (!c.has(a)) return !1;
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: c,
34
+ isCorrect: i,
35
35
  attempts: a,
36
- resetQuestion: p,
37
- submitQuestion: g
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]);
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
42
  function h() {
43
43
  if (r.length === 0) return;
@@ -45,22 +45,22 @@ function V(t) {
45
45
  (l, f) => (f.is_correct && l.push(f.id), l),
46
46
  []
47
47
  ), n = k(r, d);
48
- g(n);
48
+ w(n);
49
49
  }
50
50
  function I() {
51
- u([]), p();
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,
58
+ select: A,
59
59
  submit: h,
60
60
  reset: I,
61
61
  // base
62
62
  submitted: s,
63
- isCorrect: c,
63
+ isCorrect: i,
64
64
  attempts: a,
65
65
  canAnswer: e
66
66
  };
@@ -69,57 +69,57 @@ function v(t) {
69
69
  const {
70
70
  canAnswer: e,
71
71
  submitted: s,
72
- isCorrect: c,
72
+ isCorrect: i,
73
73
  attempts: a,
74
- submitQuestion: p,
75
- resetQuestion: g
76
- } = S(), [r, u] = b([]), [C, h] = b(
74
+ submitQuestion: g,
75
+ resetQuestion: w
76
+ } = S(), [r, c] = C([]), [A, h] = C(
77
77
  []
78
- ), [I, d] = b(
78
+ ), [I, d] = C(
79
79
  []
80
80
  );
81
81
  function n(o, m) {
82
- u((i) => [
83
- ...i.filter(
84
- (A) => A.targetId !== o && A.sourceId !== m
82
+ c((u) => [
83
+ ...u.filter(
84
+ (p) => p.targetId !== o && p.sourceId !== m
85
85
  ),
86
86
  { targetId: o, sourceId: m }
87
87
  ]);
88
88
  }
89
- function l(o) {
90
- u(
91
- (m) => m.filter((i) => i.targetId !== o && i.sourceId !== o)
89
+ function l(o, m) {
90
+ c(
91
+ (u) => u.filter((p) => p.targetId !== o || p.sourceId !== m)
92
92
  );
93
93
  }
94
94
  function f() {
95
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;
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
100
  isCorrect: m,
101
101
  score: o,
102
102
  maxScore: t.options.targets.reduce(
103
- (i, A) => i + A.content.point,
103
+ (u, p) => u + p.content.point,
104
104
  0
105
105
  )
106
106
  };
107
107
  }
108
108
  function Q() {
109
109
  const o = f();
110
- return p(o.isCorrect), o;
110
+ return g(o.isCorrect), o;
111
111
  }
112
- function w() {
113
- u([]), g();
112
+ function b() {
113
+ c([]), w();
114
114
  }
115
115
  return B(() => {
116
116
  const o = t.options.sources.filter(
117
- (m) => !r.some((i) => i.sourceId === m.id)
117
+ (m) => !r.some((u) => u.sourceId === m.id)
118
118
  );
119
119
  h(o);
120
120
  }, [r, t.options.sources]), B(() => {
121
121
  const o = t.options.targets.filter(
122
- (m) => !r.some((i) => i.targetId === m.id)
122
+ (m) => !r.some((u) => u.targetId === m.id)
123
123
  );
124
124
  d(o);
125
125
  }, [r, t.options.targets]), {
@@ -128,34 +128,34 @@ function v(t) {
128
128
  targets: t.options.targets,
129
129
  answers: r,
130
130
  question: t,
131
- availableSources: C,
131
+ availableSources: A,
132
132
  availableTargets: I,
133
133
  // base
134
134
  submitted: s,
135
- isCorrect: c,
135
+ isCorrect: i,
136
136
  attempts: a,
137
137
  canAnswer: e,
138
138
  // actions
139
139
  select: n,
140
140
  remove: l,
141
141
  submit: Q,
142
- reset: w
142
+ reset: b
143
143
  };
144
144
  }
145
145
  function T(t) {
146
146
  const {
147
147
  canAnswer: e,
148
148
  submitted: s,
149
- isCorrect: c,
149
+ isCorrect: i,
150
150
  attempts: a,
151
- resetQuestion: p,
152
- submitQuestion: g
151
+ resetQuestion: g,
152
+ submitQuestion: w
153
153
  } = S();
154
154
  function r() {
155
- g(!0);
155
+ w(!0);
156
156
  }
157
- function u() {
158
- p();
157
+ function c() {
158
+ g();
159
159
  }
160
160
  return {
161
161
  // data
@@ -164,10 +164,10 @@ function T(t) {
164
164
  type: t.options.urlType,
165
165
  // actions
166
166
  submit: r,
167
- reset: u,
167
+ reset: c,
168
168
  // base
169
169
  submitted: s,
170
- isCorrect: c,
170
+ isCorrect: i,
171
171
  attempts: a,
172
172
  canAnswer: e
173
173
  };
@@ -176,17 +176,17 @@ function _(t) {
176
176
  const {
177
177
  canAnswer: e,
178
178
  submitted: s,
179
- isCorrect: c,
179
+ isCorrect: i,
180
180
  attempts: a,
181
- submitQuestion: p,
182
- resetQuestion: g
183
- } = S(), [r, u] = b([]);
184
- function C(n, l) {
185
- e && u((f) => {
186
- const Q = f.findIndex((w) => w.targetId === n);
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
187
  if (Q >= 0) {
188
- const w = [...f];
189
- return w[Q] = { targetId: n, value: l }, w;
188
+ const b = [...f];
189
+ return b[Q] = { targetId: n, value: l }, b;
190
190
  }
191
191
  return [...f, { targetId: n, value: l }];
192
192
  });
@@ -197,8 +197,8 @@ function _(t) {
197
197
  n = !1;
198
198
  else
199
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()) {
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()) {
202
202
  n = !1;
203
203
  break;
204
204
  }
@@ -211,10 +211,10 @@ function _(t) {
211
211
  }
212
212
  function I() {
213
213
  const n = h();
214
- return p(n.isCorrect), n;
214
+ return g(n.isCorrect), n;
215
215
  }
216
216
  function d() {
217
- u([]), g();
217
+ c([]), w();
218
218
  }
219
219
  return {
220
220
  // data
@@ -223,11 +223,11 @@ function _(t) {
223
223
  question: t,
224
224
  // base
225
225
  submitted: s,
226
- isCorrect: c,
226
+ isCorrect: i,
227
227
  attempts: a,
228
228
  canAnswer: e,
229
229
  // actions
230
- answer: C,
230
+ answer: A,
231
231
  submit: I,
232
232
  reset: d
233
233
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enspiredigital/xlms-headless",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",