@enspiredigital/xlms-headless 0.0.4 → 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.
- package/dist/hooks/useMatching.d.ts +4 -3
- package/dist/hooks/useMatching.d.ts.map +1 -1
- package/dist/index.js +134 -120
- package/package.json +1 -1
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { MatchingAnswer, MatchingQuestionType, MatchingSource } from '../types';
|
|
1
|
+
import { MatchingAnswer, MatchingQuestionType, MatchingSource, MatchingTarget } from '../types';
|
|
2
2
|
export declare function useMatching(question: MatchingQuestionType): {
|
|
3
3
|
sources: MatchingSource[];
|
|
4
|
-
targets:
|
|
4
|
+
targets: MatchingTarget[];
|
|
5
5
|
answers: MatchingAnswer[];
|
|
6
6
|
question: MatchingQuestionType;
|
|
7
7
|
availableSources: MatchingSource[];
|
|
8
|
+
availableTargets: MatchingTarget[];
|
|
8
9
|
submitted: boolean | null;
|
|
9
10
|
isCorrect: boolean | null;
|
|
10
11
|
attempts: number;
|
|
11
12
|
canAnswer: boolean;
|
|
12
13
|
select: (targetId: string, sourceId: string) => void;
|
|
13
|
-
remove: (
|
|
14
|
+
remove: (id: string) => void;
|
|
14
15
|
submit: () => {
|
|
15
16
|
isCorrect: boolean;
|
|
16
17
|
score: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMatching.d.ts","sourceRoot":"","sources":["../../src/hooks/useMatching.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
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,150 +1,164 @@
|
|
|
1
|
-
import { useState as b, useEffect as
|
|
2
|
-
function
|
|
3
|
-
const [t, e] = b(null), [s,
|
|
4
|
-
function
|
|
5
|
-
t || (e(!0),
|
|
1
|
+
import { useState as b, useEffect as B } from "react";
|
|
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));
|
|
6
6
|
}
|
|
7
|
-
function
|
|
8
|
-
e(!1),
|
|
7
|
+
function r() {
|
|
8
|
+
e(!1), u(null);
|
|
9
9
|
}
|
|
10
10
|
return {
|
|
11
11
|
// state
|
|
12
12
|
submitted: t,
|
|
13
13
|
isCorrect: s,
|
|
14
|
-
attempts:
|
|
14
|
+
attempts: f,
|
|
15
15
|
// derived
|
|
16
16
|
canAnswer: !t,
|
|
17
17
|
// actions
|
|
18
|
-
submitQuestion:
|
|
19
|
-
resetQuestion:
|
|
18
|
+
submitQuestion: g,
|
|
19
|
+
resetQuestion: r
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
function
|
|
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), 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
|
-
function
|
|
30
|
+
function V(t) {
|
|
31
31
|
const {
|
|
32
32
|
canAnswer: e,
|
|
33
33
|
submitted: s,
|
|
34
|
-
isCorrect:
|
|
35
|
-
attempts:
|
|
34
|
+
isCorrect: u,
|
|
35
|
+
attempts: f,
|
|
36
36
|
resetQuestion: p,
|
|
37
|
-
submitQuestion:
|
|
38
|
-
} =
|
|
39
|
-
function
|
|
40
|
-
|
|
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]);
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
if (
|
|
44
|
-
const
|
|
45
|
-
(
|
|
42
|
+
function Q() {
|
|
43
|
+
if (r.length === 0) return;
|
|
44
|
+
const m = t.options.answers.reduce(
|
|
45
|
+
(a, d) => (d.is_correct && a.push(d.id), a),
|
|
46
46
|
[]
|
|
47
|
-
), n =
|
|
48
|
-
|
|
47
|
+
), n = k(r, m);
|
|
48
|
+
g(n);
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
50
|
+
function h() {
|
|
51
|
+
l([]), p();
|
|
52
52
|
}
|
|
53
53
|
return {
|
|
54
54
|
// data
|
|
55
55
|
question: t,
|
|
56
|
-
selectedIds:
|
|
56
|
+
selectedIds: r,
|
|
57
57
|
// actions
|
|
58
|
-
select:
|
|
59
|
-
submit:
|
|
60
|
-
reset:
|
|
58
|
+
select: C,
|
|
59
|
+
submit: Q,
|
|
60
|
+
reset: h,
|
|
61
61
|
// base
|
|
62
62
|
submitted: s,
|
|
63
|
-
isCorrect:
|
|
64
|
-
attempts:
|
|
63
|
+
isCorrect: u,
|
|
64
|
+
attempts: f,
|
|
65
65
|
canAnswer: e
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
|
-
function
|
|
68
|
+
function v(t) {
|
|
69
69
|
const {
|
|
70
70
|
canAnswer: e,
|
|
71
71
|
submitted: s,
|
|
72
|
-
isCorrect:
|
|
73
|
-
attempts:
|
|
72
|
+
isCorrect: u,
|
|
73
|
+
attempts: f,
|
|
74
74
|
submitQuestion: p,
|
|
75
|
-
resetQuestion:
|
|
76
|
-
} =
|
|
75
|
+
resetQuestion: g
|
|
76
|
+
} = S(), [r, l] = b([]), [C, Q] = b(
|
|
77
|
+
[]
|
|
78
|
+
), [h, m] = b(
|
|
77
79
|
[]
|
|
78
80
|
);
|
|
79
|
-
function
|
|
80
|
-
|
|
81
|
-
...
|
|
82
|
-
(
|
|
81
|
+
function n(i, c) {
|
|
82
|
+
l((o) => [
|
|
83
|
+
...o.filter(
|
|
84
|
+
(I) => I.targetId !== i && I.sourceId !== c
|
|
83
85
|
),
|
|
84
|
-
{ targetId:
|
|
86
|
+
{ targetId: i, sourceId: c }
|
|
85
87
|
]);
|
|
86
88
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
+
function a(i) {
|
|
90
|
+
l(
|
|
91
|
+
(c) => c.filter((o) => o.targetId !== i || o.sourceId !== i)
|
|
92
|
+
);
|
|
89
93
|
}
|
|
90
|
-
function
|
|
91
|
-
let
|
|
92
|
-
return t.options.targets.forEach((
|
|
93
|
-
const
|
|
94
|
-
|
|
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;
|
|
95
99
|
}), {
|
|
96
|
-
isCorrect:
|
|
97
|
-
score:
|
|
100
|
+
isCorrect: c,
|
|
101
|
+
score: i,
|
|
98
102
|
maxScore: t.options.targets.reduce(
|
|
99
|
-
(
|
|
103
|
+
(o, I) => o + I.content.point,
|
|
100
104
|
0
|
|
101
105
|
)
|
|
102
106
|
};
|
|
103
107
|
}
|
|
104
|
-
function
|
|
105
|
-
const
|
|
106
|
-
return p(
|
|
108
|
+
function A() {
|
|
109
|
+
const i = d();
|
|
110
|
+
return p(i.isCorrect), i;
|
|
107
111
|
}
|
|
108
|
-
function
|
|
109
|
-
|
|
112
|
+
function w() {
|
|
113
|
+
l([]), g();
|
|
110
114
|
}
|
|
111
|
-
return
|
|
112
|
-
const
|
|
113
|
-
(
|
|
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
|
+
)
|
|
120
|
+
);
|
|
121
|
+
Q(i);
|
|
122
|
+
}, [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
|
+
)
|
|
114
127
|
);
|
|
115
|
-
|
|
116
|
-
}, [
|
|
128
|
+
m(i);
|
|
129
|
+
}, [r, t.options.targets]), {
|
|
117
130
|
// data
|
|
118
131
|
sources: t.options.sources,
|
|
119
132
|
targets: t.options.targets,
|
|
120
|
-
answers:
|
|
133
|
+
answers: r,
|
|
121
134
|
question: t,
|
|
122
|
-
availableSources:
|
|
135
|
+
availableSources: C,
|
|
136
|
+
availableTargets: h,
|
|
123
137
|
// base
|
|
124
138
|
submitted: s,
|
|
125
|
-
isCorrect:
|
|
126
|
-
attempts:
|
|
139
|
+
isCorrect: u,
|
|
140
|
+
attempts: f,
|
|
127
141
|
canAnswer: e,
|
|
128
142
|
// actions
|
|
129
|
-
select:
|
|
130
|
-
remove:
|
|
131
|
-
submit:
|
|
132
|
-
reset:
|
|
143
|
+
select: n,
|
|
144
|
+
remove: a,
|
|
145
|
+
submit: A,
|
|
146
|
+
reset: w
|
|
133
147
|
};
|
|
134
148
|
}
|
|
135
|
-
function
|
|
149
|
+
function T(t) {
|
|
136
150
|
const {
|
|
137
151
|
canAnswer: e,
|
|
138
152
|
submitted: s,
|
|
139
|
-
isCorrect:
|
|
140
|
-
attempts:
|
|
153
|
+
isCorrect: u,
|
|
154
|
+
attempts: f,
|
|
141
155
|
resetQuestion: p,
|
|
142
|
-
submitQuestion:
|
|
143
|
-
} =
|
|
144
|
-
function
|
|
145
|
-
|
|
156
|
+
submitQuestion: g
|
|
157
|
+
} = S();
|
|
158
|
+
function r() {
|
|
159
|
+
g(!0);
|
|
146
160
|
}
|
|
147
|
-
function
|
|
161
|
+
function l() {
|
|
148
162
|
p();
|
|
149
163
|
}
|
|
150
164
|
return {
|
|
@@ -153,12 +167,12 @@ function V(t) {
|
|
|
153
167
|
url: t.options.url,
|
|
154
168
|
type: t.options.urlType,
|
|
155
169
|
// actions
|
|
156
|
-
submit:
|
|
157
|
-
reset:
|
|
170
|
+
submit: r,
|
|
171
|
+
reset: l,
|
|
158
172
|
// base
|
|
159
173
|
submitted: s,
|
|
160
|
-
isCorrect:
|
|
161
|
-
attempts:
|
|
174
|
+
isCorrect: u,
|
|
175
|
+
attempts: f,
|
|
162
176
|
canAnswer: e
|
|
163
177
|
};
|
|
164
178
|
}
|
|
@@ -166,29 +180,29 @@ function _(t) {
|
|
|
166
180
|
const {
|
|
167
181
|
canAnswer: e,
|
|
168
182
|
submitted: s,
|
|
169
|
-
isCorrect:
|
|
170
|
-
attempts:
|
|
183
|
+
isCorrect: u,
|
|
184
|
+
attempts: f,
|
|
171
185
|
submitQuestion: p,
|
|
172
|
-
resetQuestion:
|
|
173
|
-
} =
|
|
174
|
-
function
|
|
175
|
-
e &&
|
|
176
|
-
const
|
|
177
|
-
if (
|
|
178
|
-
const
|
|
179
|
-
return
|
|
186
|
+
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;
|
|
180
194
|
}
|
|
181
|
-
return [...
|
|
195
|
+
return [...d, { targetId: n, value: a }];
|
|
182
196
|
});
|
|
183
197
|
}
|
|
184
|
-
function
|
|
198
|
+
function Q() {
|
|
185
199
|
let n = !0;
|
|
186
|
-
if (
|
|
200
|
+
if (r.length < t.options.targets.length)
|
|
187
201
|
n = !1;
|
|
188
202
|
else
|
|
189
|
-
for (const
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
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()) {
|
|
192
206
|
n = !1;
|
|
193
207
|
break;
|
|
194
208
|
}
|
|
@@ -199,48 +213,48 @@ function _(t) {
|
|
|
199
213
|
maxScore: 1
|
|
200
214
|
};
|
|
201
215
|
}
|
|
202
|
-
function
|
|
203
|
-
const n =
|
|
216
|
+
function h() {
|
|
217
|
+
const n = Q();
|
|
204
218
|
return p(n.isCorrect), n;
|
|
205
219
|
}
|
|
206
|
-
function
|
|
207
|
-
|
|
220
|
+
function m() {
|
|
221
|
+
l([]), g();
|
|
208
222
|
}
|
|
209
223
|
return {
|
|
210
224
|
// data
|
|
211
225
|
targets: t.options.targets,
|
|
212
|
-
answers:
|
|
226
|
+
answers: r,
|
|
213
227
|
question: t,
|
|
214
228
|
// base
|
|
215
229
|
submitted: s,
|
|
216
|
-
isCorrect:
|
|
217
|
-
attempts:
|
|
230
|
+
isCorrect: u,
|
|
231
|
+
attempts: f,
|
|
218
232
|
canAnswer: e,
|
|
219
233
|
// actions
|
|
220
|
-
answer:
|
|
221
|
-
submit:
|
|
222
|
-
reset:
|
|
234
|
+
answer: C,
|
|
235
|
+
submit: h,
|
|
236
|
+
reset: m
|
|
223
237
|
};
|
|
224
238
|
}
|
|
225
239
|
function z({
|
|
226
240
|
getData: t,
|
|
227
241
|
children: e
|
|
228
242
|
}) {
|
|
229
|
-
const s =
|
|
243
|
+
const s = V(t());
|
|
230
244
|
return e(s);
|
|
231
245
|
}
|
|
232
246
|
function E({
|
|
233
247
|
getData: t,
|
|
234
248
|
children: e
|
|
235
249
|
}) {
|
|
236
|
-
const s =
|
|
250
|
+
const s = v(t());
|
|
237
251
|
return e(s);
|
|
238
252
|
}
|
|
239
253
|
function F({
|
|
240
254
|
getData: t,
|
|
241
255
|
children: e
|
|
242
256
|
}) {
|
|
243
|
-
const s =
|
|
257
|
+
const s = T(t());
|
|
244
258
|
return e(s);
|
|
245
259
|
}
|
|
246
260
|
function L({
|
|
@@ -255,10 +269,10 @@ export {
|
|
|
255
269
|
E as MatchingQuestion,
|
|
256
270
|
z as MultipleChoicesQuestion,
|
|
257
271
|
F as VideoQuestion,
|
|
258
|
-
|
|
259
|
-
|
|
272
|
+
k as isSameSet,
|
|
273
|
+
S as useBaseQuestion,
|
|
260
274
|
_ as useFillInBlank,
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
275
|
+
v as useMatching,
|
|
276
|
+
V as useMultipleChoice,
|
|
277
|
+
T as useVideo
|
|
264
278
|
};
|