@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.
- package/dist/hooks/useMatching.d.ts.map +1 -1
- package/dist/index.js +87 -91
- package/package.json +1 -1
|
@@ -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;;;;;;;
|
|
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,
|
|
4
|
-
function g(
|
|
5
|
-
t || (e(!0), u
|
|
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),
|
|
8
|
+
e(!1), c(null);
|
|
9
9
|
}
|
|
10
10
|
return {
|
|
11
11
|
// state
|
|
12
12
|
submitted: t,
|
|
13
13
|
isCorrect: s,
|
|
14
|
-
attempts:
|
|
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),
|
|
25
|
-
if (s.size !==
|
|
26
|
-
for (const
|
|
27
|
-
if (!
|
|
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:
|
|
35
|
-
attempts:
|
|
34
|
+
isCorrect: c,
|
|
35
|
+
attempts: a,
|
|
36
36
|
resetQuestion: p,
|
|
37
37
|
submitQuestion: g
|
|
38
|
-
} = S(), [r,
|
|
39
|
-
function C(
|
|
40
|
-
|
|
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
|
|
42
|
+
function h() {
|
|
43
43
|
if (r.length === 0) return;
|
|
44
|
-
const
|
|
45
|
-
(
|
|
44
|
+
const d = t.options.answers.reduce(
|
|
45
|
+
(l, f) => (f.is_correct && l.push(f.id), l),
|
|
46
46
|
[]
|
|
47
|
-
), n = k(r,
|
|
47
|
+
), n = k(r, d);
|
|
48
48
|
g(n);
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
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:
|
|
60
|
-
reset:
|
|
59
|
+
submit: h,
|
|
60
|
+
reset: I,
|
|
61
61
|
// base
|
|
62
62
|
submitted: s,
|
|
63
|
-
isCorrect:
|
|
64
|
-
attempts:
|
|
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:
|
|
73
|
-
attempts:
|
|
72
|
+
isCorrect: c,
|
|
73
|
+
attempts: a,
|
|
74
74
|
submitQuestion: p,
|
|
75
75
|
resetQuestion: g
|
|
76
|
-
} = S(), [r,
|
|
76
|
+
} = S(), [r, u] = b([]), [C, h] = b(
|
|
77
77
|
[]
|
|
78
|
-
), [
|
|
78
|
+
), [I, d] = b(
|
|
79
79
|
[]
|
|
80
80
|
);
|
|
81
|
-
function n(
|
|
82
|
-
|
|
83
|
-
...
|
|
84
|
-
(
|
|
81
|
+
function n(o, m) {
|
|
82
|
+
u((i) => [
|
|
83
|
+
...i.filter(
|
|
84
|
+
(A) => A.targetId !== o && A.sourceId !== m
|
|
85
85
|
),
|
|
86
|
-
{ targetId:
|
|
86
|
+
{ targetId: o, sourceId: m }
|
|
87
87
|
]);
|
|
88
88
|
}
|
|
89
|
-
function
|
|
90
|
-
|
|
91
|
-
(
|
|
89
|
+
function l(o) {
|
|
90
|
+
u(
|
|
91
|
+
(m) => m.filter((i) => i.targetId !== o && i.sourceId !== o)
|
|
92
92
|
);
|
|
93
93
|
}
|
|
94
|
-
function
|
|
95
|
-
let
|
|
96
|
-
return t.options.targets.forEach((
|
|
97
|
-
const
|
|
98
|
-
|
|
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:
|
|
101
|
-
score:
|
|
100
|
+
isCorrect: m,
|
|
101
|
+
score: o,
|
|
102
102
|
maxScore: t.options.targets.reduce(
|
|
103
|
-
(
|
|
103
|
+
(i, A) => i + A.content.point,
|
|
104
104
|
0
|
|
105
105
|
)
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
|
-
function
|
|
109
|
-
const
|
|
110
|
-
return p(
|
|
108
|
+
function Q() {
|
|
109
|
+
const o = f();
|
|
110
|
+
return p(o.isCorrect), o;
|
|
111
111
|
}
|
|
112
112
|
function w() {
|
|
113
|
-
|
|
113
|
+
u([]), g();
|
|
114
114
|
}
|
|
115
115
|
return B(() => {
|
|
116
|
-
const
|
|
117
|
-
(
|
|
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
|
-
|
|
119
|
+
h(o);
|
|
122
120
|
}, [r, t.options.sources]), B(() => {
|
|
123
|
-
const
|
|
124
|
-
(
|
|
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
|
-
|
|
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:
|
|
132
|
+
availableTargets: I,
|
|
137
133
|
// base
|
|
138
134
|
submitted: s,
|
|
139
|
-
isCorrect:
|
|
140
|
-
attempts:
|
|
135
|
+
isCorrect: c,
|
|
136
|
+
attempts: a,
|
|
141
137
|
canAnswer: e,
|
|
142
138
|
// actions
|
|
143
139
|
select: n,
|
|
144
|
-
remove:
|
|
145
|
-
submit:
|
|
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:
|
|
154
|
-
attempts:
|
|
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
|
|
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:
|
|
167
|
+
reset: u,
|
|
172
168
|
// base
|
|
173
169
|
submitted: s,
|
|
174
|
-
isCorrect:
|
|
175
|
-
attempts:
|
|
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:
|
|
184
|
-
attempts:
|
|
179
|
+
isCorrect: c,
|
|
180
|
+
attempts: a,
|
|
185
181
|
submitQuestion: p,
|
|
186
182
|
resetQuestion: g
|
|
187
|
-
} = S(), [r,
|
|
188
|
-
function C(n,
|
|
189
|
-
e &&
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
192
|
-
const w = [...
|
|
193
|
-
return 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 [...
|
|
191
|
+
return [...f, { targetId: n, value: l }];
|
|
196
192
|
});
|
|
197
193
|
}
|
|
198
|
-
function
|
|
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
|
|
204
|
-
const
|
|
205
|
-
if (
|
|
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
|
|
217
|
-
const n =
|
|
212
|
+
function I() {
|
|
213
|
+
const n = h();
|
|
218
214
|
return p(n.isCorrect), n;
|
|
219
215
|
}
|
|
220
|
-
function
|
|
221
|
-
|
|
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:
|
|
231
|
-
attempts:
|
|
226
|
+
isCorrect: c,
|
|
227
|
+
attempts: a,
|
|
232
228
|
canAnswer: e,
|
|
233
229
|
// actions
|
|
234
230
|
answer: C,
|
|
235
|
-
submit:
|
|
236
|
-
reset:
|
|
231
|
+
submit: I,
|
|
232
|
+
reset: d
|
|
237
233
|
};
|
|
238
234
|
}
|
|
239
235
|
function z({
|