@enspiredigital/xlms-headless 0.0.4 → 0.0.5

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