@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.
- package/dist/hooks/useMatching.d.ts +1 -1
- package/dist/hooks/useMatching.d.ts.map +1 -1
- package/dist/index.js +106 -110
- package/package.json +1 -1
|
@@ -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: (
|
|
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;
|
|
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
|
|
1
|
+
import { useState as C, useEffect as B } from "react";
|
|
2
2
|
function S() {
|
|
3
|
-
const [t, e] =
|
|
4
|
-
function
|
|
5
|
-
t || (e(!0),
|
|
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),
|
|
8
|
+
e(!1), i(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
|
|
18
|
-
submitQuestion:
|
|
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),
|
|
25
|
-
if (s.size !==
|
|
26
|
-
for (const
|
|
27
|
-
if (!
|
|
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:
|
|
35
|
-
attempts:
|
|
36
|
-
resetQuestion:
|
|
37
|
-
submitQuestion:
|
|
38
|
-
} = S(), [r,
|
|
39
|
-
function
|
|
40
|
-
|
|
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
|
|
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,
|
|
48
|
-
|
|
47
|
+
), n = k(r, d);
|
|
48
|
+
w(n);
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
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:
|
|
59
|
-
submit:
|
|
60
|
-
reset:
|
|
58
|
+
select: A,
|
|
59
|
+
submit: h,
|
|
60
|
+
reset: I,
|
|
61
61
|
// base
|
|
62
62
|
submitted: s,
|
|
63
|
-
isCorrect:
|
|
64
|
-
attempts:
|
|
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:
|
|
73
|
-
attempts:
|
|
74
|
-
submitQuestion:
|
|
75
|
-
resetQuestion:
|
|
76
|
-
} = S(), [r,
|
|
72
|
+
isCorrect: i,
|
|
73
|
+
attempts: a,
|
|
74
|
+
submitQuestion: g,
|
|
75
|
+
resetQuestion: w
|
|
76
|
+
} = S(), [r, c] = C([]), [A, h] = C(
|
|
77
77
|
[]
|
|
78
|
-
), [
|
|
78
|
+
), [I, d] = C(
|
|
79
79
|
[]
|
|
80
80
|
);
|
|
81
|
-
function n(
|
|
82
|
-
|
|
83
|
-
...
|
|
84
|
-
(
|
|
81
|
+
function n(o, m) {
|
|
82
|
+
c((u) => [
|
|
83
|
+
...u.filter(
|
|
84
|
+
(p) => p.targetId !== o && p.sourceId !== m
|
|
85
85
|
),
|
|
86
|
-
{ targetId:
|
|
86
|
+
{ targetId: o, sourceId: m }
|
|
87
87
|
]);
|
|
88
88
|
}
|
|
89
|
-
function
|
|
90
|
-
|
|
91
|
-
(
|
|
89
|
+
function l(o, m) {
|
|
90
|
+
c(
|
|
91
|
+
(u) => u.filter((p) => p.targetId !== o || p.sourceId !== m)
|
|
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((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:
|
|
101
|
-
score:
|
|
100
|
+
isCorrect: m,
|
|
101
|
+
score: o,
|
|
102
102
|
maxScore: t.options.targets.reduce(
|
|
103
|
-
(
|
|
103
|
+
(u, p) => u + p.content.point,
|
|
104
104
|
0
|
|
105
105
|
)
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
|
-
function
|
|
109
|
-
const
|
|
110
|
-
return
|
|
108
|
+
function Q() {
|
|
109
|
+
const o = f();
|
|
110
|
+
return g(o.isCorrect), o;
|
|
111
111
|
}
|
|
112
|
-
function
|
|
113
|
-
|
|
112
|
+
function b() {
|
|
113
|
+
c([]), w();
|
|
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((u) => u.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((u) => u.targetId === m.id)
|
|
127
123
|
);
|
|
128
|
-
|
|
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:
|
|
136
|
-
availableTargets:
|
|
131
|
+
availableSources: A,
|
|
132
|
+
availableTargets: I,
|
|
137
133
|
// base
|
|
138
134
|
submitted: s,
|
|
139
|
-
isCorrect:
|
|
140
|
-
attempts:
|
|
135
|
+
isCorrect: i,
|
|
136
|
+
attempts: a,
|
|
141
137
|
canAnswer: e,
|
|
142
138
|
// actions
|
|
143
139
|
select: n,
|
|
144
|
-
remove:
|
|
145
|
-
submit:
|
|
146
|
-
reset:
|
|
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:
|
|
154
|
-
attempts:
|
|
155
|
-
resetQuestion:
|
|
156
|
-
submitQuestion:
|
|
149
|
+
isCorrect: i,
|
|
150
|
+
attempts: a,
|
|
151
|
+
resetQuestion: g,
|
|
152
|
+
submitQuestion: w
|
|
157
153
|
} = S();
|
|
158
154
|
function r() {
|
|
159
|
-
|
|
155
|
+
w(!0);
|
|
160
156
|
}
|
|
161
|
-
function
|
|
162
|
-
|
|
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:
|
|
167
|
+
reset: c,
|
|
172
168
|
// base
|
|
173
169
|
submitted: s,
|
|
174
|
-
isCorrect:
|
|
175
|
-
attempts:
|
|
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:
|
|
184
|
-
attempts:
|
|
185
|
-
submitQuestion:
|
|
186
|
-
resetQuestion:
|
|
187
|
-
} = S(), [r,
|
|
188
|
-
function
|
|
189
|
-
e &&
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
192
|
-
const
|
|
193
|
-
return
|
|
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 [...
|
|
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() : "", 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
|
|
217
|
-
const n =
|
|
218
|
-
return
|
|
212
|
+
function I() {
|
|
213
|
+
const n = h();
|
|
214
|
+
return g(n.isCorrect), n;
|
|
219
215
|
}
|
|
220
|
-
function
|
|
221
|
-
|
|
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:
|
|
231
|
-
attempts:
|
|
226
|
+
isCorrect: i,
|
|
227
|
+
attempts: a,
|
|
232
228
|
canAnswer: e,
|
|
233
229
|
// actions
|
|
234
|
-
answer:
|
|
235
|
-
submit:
|
|
236
|
-
reset:
|
|
230
|
+
answer: A,
|
|
231
|
+
submit: I,
|
|
232
|
+
reset: d
|
|
237
233
|
};
|
|
238
234
|
}
|
|
239
235
|
function z({
|