@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.
@@ -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: 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;
11
12
  canAnswer: boolean;
12
13
  select: (targetId: string, sourceId: string) => void;
13
- remove: (targetId: string) => void;
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,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;iBAa9B,MAAM;;;;;;;EAgG3B"}
package/dist/index.js CHANGED
@@ -1,150 +1,164 @@
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, 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 o() {
8
- e(!1), c(null);
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: a,
14
+ attempts: f,
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;
26
- for (const a of s)
27
- if (!c.has(a)) return !1;
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 M(t) {
30
+ function V(t) {
31
31
  const {
32
32
  canAnswer: e,
33
33
  submitted: s,
34
- isCorrect: c,
35
- attempts: a,
34
+ isCorrect: u,
35
+ attempts: f,
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, 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 A() {
43
- if (o.length === 0) return;
44
- const d = t.options.answers.reduce(
45
- (f, m) => (m.is_correct && f.push(m.id), f),
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 = B(o, d);
48
- w(n);
47
+ ), n = k(r, m);
48
+ g(n);
49
49
  }
50
- function Q() {
51
- u([]), p();
50
+ function h() {
51
+ l([]), 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: Q,
60
+ reset: h,
61
61
  // base
62
62
  submitted: s,
63
- isCorrect: c,
64
- attempts: a,
63
+ isCorrect: u,
64
+ attempts: f,
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,
73
- attempts: a,
72
+ isCorrect: u,
73
+ attempts: f,
74
74
  submitQuestion: p,
75
- resetQuestion: w
76
- } = h(), [o, u] = b([]), [g, A] = b(
75
+ resetQuestion: g
76
+ } = S(), [r, l] = b([]), [C, Q] = b(
77
+ []
78
+ ), [h, m] = 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(i, c) {
82
+ l((o) => [
83
+ ...o.filter(
84
+ (I) => I.targetId !== i && I.sourceId !== c
83
85
  ),
84
- { targetId: r, sourceId: i }
86
+ { targetId: i, sourceId: c }
85
87
  ]);
86
88
  }
87
- function d(r) {
88
- u((i) => i.filter((l) => l.targetId !== r));
89
+ function a(i) {
90
+ l(
91
+ (c) => c.filter((o) => o.targetId !== i || o.sourceId !== i)
92
+ );
89
93
  }
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;
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: i,
97
- score: r,
100
+ isCorrect: c,
101
+ score: i,
98
102
  maxScore: t.options.targets.reduce(
99
- (l, C) => l + C.content.point,
103
+ (o, I) => o + I.content.point,
100
104
  0
101
105
  )
102
106
  };
103
107
  }
104
- function f() {
105
- const r = n();
106
- return p(r.isCorrect), r;
108
+ function A() {
109
+ const i = d();
110
+ return p(i.isCorrect), i;
107
111
  }
108
- function m() {
109
- u([]), w();
112
+ function w() {
113
+ l([]), g();
110
114
  }
111
- return x(() => {
112
- const r = t.options.sources.filter(
113
- (i) => !o.some((l) => l.sourceId === i.id)
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
- A(r);
116
- }, [o, t.options.sources]), {
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: o,
133
+ answers: r,
121
134
  question: t,
122
- availableSources: g,
135
+ availableSources: C,
136
+ availableTargets: h,
123
137
  // base
124
138
  submitted: s,
125
- isCorrect: c,
126
- attempts: a,
139
+ isCorrect: u,
140
+ attempts: f,
127
141
  canAnswer: e,
128
142
  // actions
129
- select: Q,
130
- remove: d,
131
- submit: f,
132
- reset: m
143
+ select: n,
144
+ remove: a,
145
+ submit: A,
146
+ reset: w
133
147
  };
134
148
  }
135
- function V(t) {
149
+ function T(t) {
136
150
  const {
137
151
  canAnswer: e,
138
152
  submitted: s,
139
- isCorrect: c,
140
- attempts: a,
153
+ isCorrect: u,
154
+ attempts: f,
141
155
  resetQuestion: p,
142
- submitQuestion: w
143
- } = h();
144
- function o() {
145
- w(!0);
156
+ submitQuestion: g
157
+ } = S();
158
+ function r() {
159
+ g(!0);
146
160
  }
147
- function u() {
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: o,
157
- reset: u,
170
+ submit: r,
171
+ reset: l,
158
172
  // base
159
173
  submitted: s,
160
- isCorrect: c,
161
- attempts: a,
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: c,
170
- attempts: a,
183
+ isCorrect: u,
184
+ attempts: f,
171
185
  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;
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 [...m, { targetId: n, value: f }];
195
+ return [...d, { targetId: n, value: a }];
182
196
  });
183
197
  }
184
- function A() {
198
+ function Q() {
185
199
  let n = !0;
186
- if (o.length < t.options.targets.length)
200
+ if (r.length < t.options.targets.length)
187
201
  n = !1;
188
202
  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()) {
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 Q() {
203
- const n = A();
216
+ function h() {
217
+ const n = Q();
204
218
  return p(n.isCorrect), n;
205
219
  }
206
- function d() {
207
- u([]), w();
220
+ function m() {
221
+ l([]), g();
208
222
  }
209
223
  return {
210
224
  // data
211
225
  targets: t.options.targets,
212
- answers: o,
226
+ answers: r,
213
227
  question: t,
214
228
  // base
215
229
  submitted: s,
216
- isCorrect: c,
217
- attempts: a,
230
+ isCorrect: u,
231
+ attempts: f,
218
232
  canAnswer: e,
219
233
  // actions
220
- answer: g,
221
- submit: Q,
222
- reset: d
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 = M(t());
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 = k(t());
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 = V(t());
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
- B as isSameSet,
259
- h as useBaseQuestion,
272
+ k as isSameSet,
273
+ S as useBaseQuestion,
260
274
  _ as useFillInBlank,
261
- k as useMatching,
262
- M as useMultipleChoice,
263
- V as useVideo
275
+ v as useMatching,
276
+ V as useMultipleChoice,
277
+ T as useVideo
264
278
  };
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.6",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",