@enspiredigital/xlms-headless 0.0.29 → 0.0.30

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 +1 @@
1
- {"version":3,"file":"useSpeaking.d.ts","sourceRoot":"","sources":["../../src/hooks/useSpeaking.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEzE,MAAM,MAAM,qBAAqB,GAAG,CAClC,SAAS,EAAE,IAAI,EACf,QAAQ,CAAC,EAAE,MAAM,KACd,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAEjE,wBAAgB,WAAW,CACzB,QAAQ,EAAE,oBAAoB,EAC9B,aAAa,CAAC,EAAE,qBAAqB;;;;;;;;;;;;;;;;;;;uBAqItB,IAAI;;;EAkFpB"}
1
+ {"version":3,"file":"useSpeaking.d.ts","sourceRoot":"","sources":["../../src/hooks/useSpeaking.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEzE,MAAM,MAAM,qBAAqB,GAAG,CAClC,SAAS,EAAE,IAAI,EACf,QAAQ,CAAC,EAAE,MAAM,KACd,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAEjE,wBAAgB,WAAW,CACzB,QAAQ,EAAE,oBAAoB,EAC9B,aAAa,CAAC,EAAE,qBAAqB;;;;;;;;;;;;;;;;;;;uBAwItB,IAAI;;;EAkFpB"}
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { useState as A, useRef as F, useEffect as V, useMemo as T, useCallback as U } from "react";
2
2
  import { jsx as W, Fragment as z } from "react/jsx-runtime";
3
3
  function E() {
4
- const [t, n] = A(null), [u, f] = A(null), [b, C] = A(0);
5
- function S(d) {
6
- n(!0), d !== void 0 && f(d), C((h) => h + 1);
4
+ const [t, n] = A(null), [u, f] = A(null), [b, h] = A(0);
5
+ function C(d) {
6
+ n(!0), d !== void 0 && f(d), h((S) => S + 1);
7
7
  }
8
8
  function o() {
9
9
  n(!1), f(null);
@@ -16,7 +16,7 @@ function E() {
16
16
  // derived
17
17
  canAnswer: !t,
18
18
  // actions
19
- submitQuestion: S,
19
+ submitQuestion: C,
20
20
  resetQuestion: o
21
21
  };
22
22
  }
@@ -42,10 +42,10 @@ function X(t) {
42
42
  submitted: u,
43
43
  isCorrect: f,
44
44
  attempts: b,
45
- resetQuestion: C,
46
- submitQuestion: S
45
+ resetQuestion: h,
46
+ submitQuestion: C
47
47
  } = E(), [o, d] = A([]);
48
- function h(w) {
48
+ function S(w) {
49
49
  d((g) => t.options.allowMultipleAnswers ? g.includes(w) ? g.filter((p) => p !== w) : [...g, w] : [w]);
50
50
  }
51
51
  function I() {
@@ -54,19 +54,19 @@ function X(t) {
54
54
  (p, x) => (x.is_correct && p.push(x.id), p),
55
55
  []
56
56
  ), g = J(o, w);
57
- S(g);
57
+ C(g);
58
58
  }
59
- function v() {
60
- d([]), C();
59
+ function Q() {
60
+ d([]), h();
61
61
  }
62
62
  return {
63
63
  // data
64
64
  question: t,
65
65
  selectedIds: o,
66
66
  // actions
67
- select: h,
67
+ select: S,
68
68
  submit: I,
69
- reset: v,
69
+ reset: Q,
70
70
  // base
71
71
  submitted: u,
72
72
  isCorrect: f,
@@ -80,11 +80,11 @@ function Y(t) {
80
80
  submitted: u,
81
81
  isCorrect: f,
82
82
  attempts: b,
83
- submitQuestion: C,
84
- resetQuestion: S
85
- } = E(), [o, d] = A([]), [h, I] = A(
83
+ submitQuestion: h,
84
+ resetQuestion: C
85
+ } = E(), [o, d] = A([]), [S, I] = A(
86
86
  []
87
- ), [v, w] = A(
87
+ ), [Q, w] = A(
88
88
  []
89
89
  ), g = F([]);
90
90
  function p(e, s) {
@@ -116,10 +116,10 @@ function Y(t) {
116
116
  }
117
117
  function c() {
118
118
  const e = a();
119
- return C(e.isCorrect), e;
119
+ return h(e.isCorrect), e;
120
120
  }
121
121
  function i() {
122
- d([]), S();
122
+ d([]), C();
123
123
  }
124
124
  function r(e) {
125
125
  const s = o.find((l) => l.sourceId === e)?.targetId;
@@ -144,8 +144,8 @@ function Y(t) {
144
144
  targets: t.options.targets,
145
145
  answers: o,
146
146
  question: t,
147
- availableSources: h,
148
- availableTargets: v,
147
+ availableSources: S,
148
+ availableTargets: Q,
149
149
  // base
150
150
  submitted: u,
151
151
  isCorrect: f,
@@ -165,14 +165,14 @@ function Z(t) {
165
165
  submitted: u,
166
166
  isCorrect: f,
167
167
  attempts: b,
168
- resetQuestion: C,
169
- submitQuestion: S
168
+ resetQuestion: h,
169
+ submitQuestion: C
170
170
  } = E();
171
171
  function o() {
172
- S(!0);
172
+ C(!0);
173
173
  }
174
174
  function d() {
175
- C();
175
+ h();
176
176
  }
177
177
  return {
178
178
  // data
@@ -195,9 +195,9 @@ function K(t) {
195
195
  submitted: u,
196
196
  isCorrect: f,
197
197
  attempts: b,
198
- submitQuestion: C,
199
- resetQuestion: S
200
- } = E(), [o, d] = A([]), [h, I] = A(null), v = T(() => {
198
+ submitQuestion: h,
199
+ resetQuestion: C
200
+ } = E(), [o, d] = A([]), [S, I] = A(null), Q = T(() => {
201
201
  const r = new Set(o.map((e) => e.itemId));
202
202
  return t.options.answers.filter(
203
203
  (e) => !r.has(String(e.id))
@@ -241,10 +241,10 @@ function K(t) {
241
241
  }
242
242
  function a() {
243
243
  const r = x();
244
- return C(r.isCorrect), r;
244
+ return h(r.isCorrect), r;
245
245
  }
246
246
  function c() {
247
- d([]), S();
247
+ d([]), C();
248
248
  }
249
249
  function i(r) {
250
250
  const e = o.find((s) => s.blankIndex === r)?.itemId;
@@ -255,9 +255,9 @@ function K(t) {
255
255
  items: t.options.answers,
256
256
  groups: t.options.groups,
257
257
  answers: o,
258
- availableItems: v,
258
+ availableItems: Q,
259
259
  question: t,
260
- draggingItemId: h,
260
+ draggingItemId: S,
261
261
  // base
262
262
  submitted: u,
263
263
  isCorrect: f,
@@ -279,11 +279,11 @@ function H(t) {
279
279
  submitted: u,
280
280
  isCorrect: f,
281
281
  attempts: b,
282
- submitQuestion: C,
283
- resetQuestion: S
282
+ submitQuestion: h,
283
+ resetQuestion: C
284
284
  } = E(), [o, d] = A(() => G(
285
285
  t.options.answers.map((c) => String(c.id))
286
- )), h = T(() => o.map(
286
+ )), S = T(() => o.map(
287
287
  (c) => t.options.answers.find((i) => String(i.id) === c)
288
288
  ).filter((c) => c !== void 0), [o, t.options.answers]);
289
289
  function I(c, i) {
@@ -292,7 +292,7 @@ function H(t) {
292
292
  return e.splice(i, 0, s), e;
293
293
  });
294
294
  }
295
- function v(c) {
295
+ function Q(c) {
296
296
  const i = o.indexOf(c);
297
297
  i > 0 && I(i, i - 1);
298
298
  }
@@ -320,16 +320,16 @@ function H(t) {
320
320
  }
321
321
  function x() {
322
322
  const c = p();
323
- return C(c.isCorrect), c;
323
+ return h(c.isCorrect), c;
324
324
  }
325
325
  function a() {
326
- d(t.options.answers.map((c) => String(c.id))), S();
326
+ d(t.options.answers.map((c) => String(c.id))), C();
327
327
  }
328
328
  return {
329
329
  // data
330
330
  items: t.options.answers,
331
331
  groups: t.options.groups,
332
- orderedItems: h,
332
+ orderedItems: S,
333
333
  orderedItemIds: o,
334
334
  question: t,
335
335
  // base
@@ -340,7 +340,7 @@ function H(t) {
340
340
  // actions
341
341
  setOrderedItemIds: d,
342
342
  moveItem: I,
343
- moveUp: v,
343
+ moveUp: Q,
344
344
  moveDown: w,
345
345
  moveToPosition: g,
346
346
  submit: x,
@@ -353,9 +353,9 @@ function q(t) {
353
353
  submitted: u,
354
354
  isCorrect: f,
355
355
  attempts: b,
356
- submitQuestion: C,
357
- resetQuestion: S
358
- } = E(), [o, d] = A([]), h = T(() => {
356
+ submitQuestion: h,
357
+ resetQuestion: C
358
+ } = E(), [o, d] = A([]), S = T(() => {
359
359
  const i = new Set(o.map((r) => r.labelId));
360
360
  return t.options.labels.filter(
361
361
  (r) => !i.has(String(r.id))
@@ -375,7 +375,7 @@ function q(t) {
375
375
  }
376
376
  ]);
377
377
  }
378
- function v(i) {
378
+ function Q(i) {
379
379
  d((r) => r.filter((e) => e.labelId !== i));
380
380
  }
381
381
  function w(i, r, e, s) {
@@ -411,10 +411,10 @@ function q(t) {
411
411
  }
412
412
  function a() {
413
413
  const i = x();
414
- return C(i.isCorrect), i;
414
+ return h(i.isCorrect), i;
415
415
  }
416
416
  function c() {
417
- d([]), S();
417
+ d([]), C();
418
418
  }
419
419
  return {
420
420
  // data
@@ -424,7 +424,7 @@ function q(t) {
424
424
  imageWidth: t.image_width,
425
425
  imageHeight: t.image_height,
426
426
  answers: o,
427
- availableLabels: h,
427
+ availableLabels: S,
428
428
  question: t,
429
429
  // base
430
430
  submitted: u,
@@ -433,7 +433,7 @@ function q(t) {
433
433
  canAnswer: n,
434
434
  // actions
435
435
  attachLabel: I,
436
- removeLabel: v,
436
+ removeLabel: Q,
437
437
  moveLabel: w,
438
438
  getLabelAtBlank: g,
439
439
  getBlankForLabel: p,
@@ -447,10 +447,10 @@ function tt(t) {
447
447
  submitted: u,
448
448
  isCorrect: f,
449
449
  attempts: b,
450
- submitQuestion: C,
451
- resetQuestion: S
450
+ submitQuestion: h,
451
+ resetQuestion: C
452
452
  } = E(), [o, d] = A([]);
453
- function h(g, p) {
453
+ function S(g, p) {
454
454
  d((x) => {
455
455
  const a = x.findIndex((c) => c.blankId === g);
456
456
  if (a >= 0) {
@@ -478,12 +478,12 @@ function tt(t) {
478
478
  maxScore: Math.round(x * 100) / 100
479
479
  };
480
480
  }
481
- function v() {
481
+ function Q() {
482
482
  const g = I();
483
- return C(g.isCorrect), g;
483
+ return h(g.isCorrect), g;
484
484
  }
485
485
  function w() {
486
- d([]), S();
486
+ d([]), C();
487
487
  }
488
488
  return {
489
489
  // data
@@ -496,8 +496,8 @@ function tt(t) {
496
496
  attempts: b,
497
497
  canAnswer: n,
498
498
  // actions
499
- answer: h,
500
- submit: v,
499
+ answer: S,
500
+ submit: Q,
501
501
  reset: w
502
502
  };
503
503
  }
@@ -507,10 +507,10 @@ function et(t) {
507
507
  submitted: u,
508
508
  isCorrect: f,
509
509
  attempts: b,
510
- submitQuestion: C,
511
- resetQuestion: S
510
+ submitQuestion: h,
511
+ resetQuestion: C
512
512
  } = E(), [o, d] = A([]);
513
- function h(a, c) {
513
+ function S(a, c) {
514
514
  d((i) => {
515
515
  const r = i.findIndex((e) => e.itemId === a);
516
516
  if (r >= 0) {
@@ -523,7 +523,7 @@ function et(t) {
523
523
  function I(a) {
524
524
  d((c) => c.filter((i) => i.itemId !== a));
525
525
  }
526
- function v() {
526
+ function Q() {
527
527
  let a = 0, c = 0;
528
528
  const r = t.correct_answers.list || {}, e = Object.keys(r).length;
529
529
  let s = 0;
@@ -539,11 +539,11 @@ function et(t) {
539
539
  };
540
540
  }
541
541
  function w() {
542
- const a = v();
543
- return C(a.isCorrect), a;
542
+ const a = Q();
543
+ return h(a.isCorrect), a;
544
544
  }
545
545
  function g() {
546
- d([]), S();
546
+ d([]), C();
547
547
  }
548
548
  const p = T(() => t.options.items.filter(
549
549
  (a) => !o.some((c) => c.itemId === a.id)
@@ -571,7 +571,7 @@ function et(t) {
571
571
  attempts: b,
572
572
  canAnswer: n,
573
573
  // actions
574
- move: h,
574
+ move: S,
575
575
  remove: I,
576
576
  submit: w,
577
577
  reset: g
@@ -583,14 +583,14 @@ function rt(t) {
583
583
  submitted: u,
584
584
  isCorrect: f,
585
585
  attempts: b,
586
- resetQuestion: C,
587
- submitQuestion: S
586
+ resetQuestion: h,
587
+ submitQuestion: C
588
588
  } = E();
589
589
  function o() {
590
- u || S(!0);
590
+ u || C(!0);
591
591
  }
592
592
  function d() {
593
- C();
593
+ h();
594
594
  }
595
595
  return {
596
596
  // data
@@ -608,7 +608,7 @@ function rt(t) {
608
608
  };
609
609
  }
610
610
  function nt(t, n) {
611
- const { canAnswer: u, submitted: f, attempts: b, submitQuestion: C, resetQuestion: S } = E(), [o, d] = A(""), [h, I] = A(void 0), [v, w] = A(!1), [g, p] = A(void 0), x = U(
611
+ const { canAnswer: u, submitted: f, attempts: b, submitQuestion: h, resetQuestion: C } = E(), [o, d] = A(""), [S, I] = A(void 0), [Q, w] = A(!1), [g, p] = A(void 0), x = U(
612
612
  async (e) => {
613
613
  if (n) {
614
614
  w(!0), p(void 0);
@@ -643,12 +643,12 @@ function nt(t, n) {
643
643
  () => ({
644
644
  type: "writing",
645
645
  text: o,
646
- fileUrl: h
646
+ fileUrl: S
647
647
  }),
648
- [o, h]
649
- ), i = U(() => (C(), c), [C, c]), r = U(() => {
650
- d(""), I(void 0), p(void 0), S();
651
- }, [S]);
648
+ [o, S]
649
+ ), i = U(() => (h(), c), [h, c]), r = U(() => {
650
+ d(""), I(void 0), p(void 0), C();
651
+ }, [C]);
652
652
  return {
653
653
  question: t,
654
654
  canAnswer: u,
@@ -656,9 +656,9 @@ function nt(t, n) {
656
656
  attempts: b,
657
657
  text: o,
658
658
  setText: d,
659
- fileUrl: h,
659
+ fileUrl: S,
660
660
  setFileUrl: I,
661
- isUploading: v,
661
+ isUploading: Q,
662
662
  uploadError: g,
663
663
  uploadFile: x,
664
664
  uploadText: a,
@@ -668,12 +668,12 @@ function nt(t, n) {
668
668
  };
669
669
  }
670
670
  function st(t, n) {
671
- const { canAnswer: u, submitted: f, attempts: b, submitQuestion: C, resetQuestion: S } = E(), [o, d] = A(void 0), [h, I] = A("idle"), [v, w] = A(0), [g, p] = A(!1), [x, a] = A(void 0), [c, i] = A(!1), r = F(null), e = F([]), s = F(null), l = F(null), m = U(async () => {
671
+ const { canAnswer: u, submitted: f, attempts: b, submitQuestion: h, resetQuestion: C } = E(), [o, d] = A(void 0), [S, I] = A("idle"), [Q, w] = A(0), [g, p] = A(!1), [x, a] = A(void 0), [c, i] = A(!1), r = F(null), e = F([]), s = F(null), l = F(null), m = U(async () => {
672
672
  i(!0);
673
673
  try {
674
- const Q = await navigator.mediaDevices.getUserMedia({ audio: !0 });
675
- l.current = Q;
676
- const k = new MediaRecorder(Q);
674
+ const v = await navigator.mediaDevices.getUserMedia({ audio: !0 });
675
+ l.current = v;
676
+ const k = new MediaRecorder(v);
677
677
  r.current = k, e.current = [], k.ondataavailable = (_) => {
678
678
  _.data.size > 0 && e.current.push(_.data);
679
679
  }, k.onstop = () => {
@@ -686,39 +686,39 @@ function st(t, n) {
686
686
  s.current = setInterval(() => {
687
687
  L++, w(L), L >= (t.metadata?.max_recording_time || 300) && R();
688
688
  }, 1e3);
689
- } catch (Q) {
690
- console.error("Failed to start recording:", Q), a("Failed to access microphone");
689
+ } catch (v) {
690
+ console.error("Failed to start recording:", v), a("Failed to access microphone");
691
691
  }
692
692
  }, []), y = U(() => {
693
- r.current && h === "recording" && (r.current.pause(), I("paused"), s.current && clearInterval(s.current));
694
- }, [h]), B = U(() => {
695
- r.current && h === "paused" && (r.current.resume(), I("recording"), s.current = setInterval(() => {
696
- w((Q) => Q + 1);
693
+ r.current && S === "recording" && (r.current.pause(), I("paused"), s.current && clearInterval(s.current));
694
+ }, [S]), B = U(() => {
695
+ r.current && S === "paused" && (r.current.resume(), I("recording"), s.current = setInterval(() => {
696
+ w((v) => v + 1);
697
697
  }, 1e3));
698
- }, [h]), R = U(() => {
699
- r.current && h !== "idle" && (r.current.stop(), i(!1), I("stopped"), s.current && clearInterval(s.current), l.current && l.current.getTracks().forEach((Q) => Q.stop()));
700
- }, [h]), O = U(() => {
698
+ }, [S]), R = U(() => {
699
+ r.current && r.current.state !== "inactive" && (r.current.stop(), i(!1), I("stopped"), s.current && clearInterval(s.current), l.current && l.current.getTracks().forEach((v) => v.stop()));
700
+ }, []), O = U(() => {
701
701
  c ? R() : m();
702
702
  }, [c, m, R]), M = U(async () => {
703
703
  if (!(!e.current.length || !n)) {
704
704
  p(!0), a(void 0);
705
705
  try {
706
- const Q = new Blob(e.current, {
706
+ const v = new Blob(e.current, {
707
707
  type: "audio/webm"
708
- }), k = `speaking-${Date.now()}.webm`, L = await n(Q, k);
708
+ }), k = `speaking-${Date.now()}.webm`, L = await n(v, k);
709
709
  L.success && L.url ? d(L.url) : a(L.error || "Upload failed");
710
- } catch (Q) {
711
- console.error("Upload failed:", Q), a(Q instanceof Error ? Q.message : "Upload failed");
710
+ } catch (v) {
711
+ console.error("Upload failed:", v), a(v instanceof Error ? v.message : "Upload failed");
712
712
  } finally {
713
713
  p(!1);
714
714
  }
715
715
  }
716
716
  }, [t, n]), D = U(
717
- async (Q) => {
717
+ async (v) => {
718
718
  if (n) {
719
719
  p(!0), a(void 0);
720
720
  try {
721
- const k = await n(Q, Q.name);
721
+ const k = await n(v, v.name);
722
722
  k.success && k.url ? d(k.url) : a(k.error || "Upload failed");
723
723
  } catch (k) {
724
724
  console.error("File upload failed:", k), a(
@@ -736,17 +736,17 @@ function st(t, n) {
736
736
  audioUrl: o
737
737
  }),
738
738
  [t, o]
739
- ), $ = U(() => (C(), j), [C, j]), N = U(() => {
740
- d(void 0), I("idle"), w(0), a(void 0), e.current = [], s.current && clearInterval(s.current), l.current && l.current.getTracks().forEach((Q) => Q.stop()), S();
741
- }, [S]);
739
+ ), $ = U(() => (h(), j), [h, j]), N = U(() => {
740
+ d(void 0), I("idle"), w(0), a(void 0), e.current = [], s.current && clearInterval(s.current), l.current && l.current.getTracks().forEach((v) => v.stop()), C();
741
+ }, [C]);
742
742
  return {
743
743
  question: t,
744
744
  canAnswer: u,
745
745
  submitted: f,
746
746
  attempts: b,
747
747
  audioUrl: o,
748
- recordingState: h,
749
- recordingTime: v,
748
+ recordingState: S,
749
+ recordingTime: Q,
750
750
  isUploading: g,
751
751
  uploadError: x,
752
752
  isRecording: c,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enspiredigital/xlms-headless",
3
- "version": "0.0.29",
3
+ "version": "0.0.30",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",