@enspiredigital/xlms-headless 0.0.26 → 0.0.28

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,6 +1,5 @@
1
1
  import { SpeakingQuestionType } from '../types/speaking';
2
2
  export type SpeakingSubmitPayload = {
3
- questionId: string | number;
4
3
  type: 'speaking';
5
4
  audioUrl?: string;
6
5
  };
@@ -27,7 +26,7 @@ export declare function useSpeaking(question: SpeakingQuestionType, uploadHandle
27
26
  pauseRecording: () => void;
28
27
  resumeRecording: () => void;
29
28
  stopRecording: () => void;
30
- toggleRecording: () => void | Promise<void>;
29
+ toggleRecording: () => void;
31
30
  uploadAudio: () => Promise<void>;
32
31
  uploadFile: (file: File) => Promise<void>;
33
32
  submit: () => SpeakingSubmitPayload;
@@ -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,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,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;;;;;;;;;;;;;;;;;;;uBAiItB,IAAI;;;EAmFpB"}
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;;;;;;;;;;;;;;;;;;;uBAiItB,IAAI;;;EAkFpB"}
@@ -1,6 +1,5 @@
1
1
  import { WritingQuestionType } from '../types/writing';
2
2
  export type WritingSubmitPayload = {
3
- questionId: string | number;
4
3
  type: 'writing';
5
4
  text: string;
6
5
  fileUrl?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"useWriting.d.ts","sourceRoot":"","sources":["../../src/hooks/useWriting.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,MAAM,oBAAoB,GAAG;IACjC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,CACjC,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,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,UAAU,CACxB,QAAQ,EAAE,mBAAmB,EAC7B,aAAa,CAAC,EAAE,oBAAoB;;;;;;;;;;;uBAWrB,IAAI;;;;;EAgGpB"}
1
+ {"version":3,"file":"useWriting.d.ts","sourceRoot":"","sources":["../../src/hooks/useWriting.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,CACjC,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,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,UAAU,CACxB,QAAQ,EAAE,mBAAmB,EAC7B,aAAa,CAAC,EAAE,oBAAoB;;;;;;;;;;;uBAWrB,IAAI;;;;;EA+FpB"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { useState as A, useRef as _, useEffect as V, useMemo as T, useCallback as R } from "react";
2
- import { jsx as W, Fragment as $ } from "react/jsx-runtime";
1
+ import { useState as A, useRef as F, useEffect as V, useMemo as T, useCallback as R } from "react";
2
+ import { jsx as W, Fragment as z } from "react/jsx-runtime";
3
3
  function E() {
4
4
  const [t, n] = A(null), [u, f] = A(null), [b, C] = A(0);
5
5
  function S(d) {
@@ -28,7 +28,7 @@ function J(t, n) {
28
28
  if (!f.has(b)) return !1;
29
29
  return !0;
30
30
  }
31
- function z(t) {
31
+ function G(t) {
32
32
  const n = [...t];
33
33
  for (let u = n.length - 1; u > 0; u--) {
34
34
  const f = Math.floor(Math.random() * (u + 1));
@@ -86,7 +86,7 @@ function Y(t) {
86
86
  []
87
87
  ), [v, w] = A(
88
88
  []
89
- ), m = _([]);
89
+ ), m = F([]);
90
90
  function p(e, s) {
91
91
  d((l) => [
92
92
  ...l.filter(
@@ -137,7 +137,7 @@ function Y(t) {
137
137
  );
138
138
  w(e);
139
139
  }, [o]), V(() => {
140
- m.current = z(t.options.targets);
140
+ m.current = G(t.options.targets);
141
141
  }, [t.options.targets]), {
142
142
  // data
143
143
  sources: t.options.sources,
@@ -224,12 +224,12 @@ function K(t) {
224
224
  let r = 0, e = !0, s = 0;
225
225
  const l = t.correct_answers.list, g = new Map(o.map((y) => [y.blankIndex, y.itemId]));
226
226
  return Object.entries(l).forEach(([y, U]) => {
227
- const B = y, L = g.get(B);
228
- if (!L) {
227
+ const B = y, O = g.get(B);
228
+ if (!O) {
229
229
  e = !1;
230
230
  return;
231
231
  }
232
- const M = t.options.answers.find((D) => D.id === L);
232
+ const M = t.options.answers.find((D) => D.id === O);
233
233
  M && String(M.group_position) === String(U) ? (r++, s += M.point) : e = !1;
234
234
  }), {
235
235
  isCorrect: e,
@@ -281,7 +281,7 @@ function H(t) {
281
281
  attempts: b,
282
282
  submitQuestion: C,
283
283
  resetQuestion: S
284
- } = E(), [o, d] = A(() => z(
284
+ } = E(), [o, d] = A(() => G(
285
285
  t.options.answers.map((c) => String(c.id))
286
286
  )), h = T(() => o.map(
287
287
  (c) => t.options.answers.find((i) => String(i.id) === c)
@@ -530,8 +530,8 @@ function et(t) {
530
530
  return Object.entries(r).forEach(([g, y]) => {
531
531
  const U = t.options.items.find((M) => M.id === g), B = U ? U.point : 0;
532
532
  s += B;
533
- const L = o.find((M) => M.itemId === g);
534
- L && L.categoryId === y && (a += B, c++);
533
+ const O = o.find((M) => M.itemId === g);
534
+ O && O.categoryId === y && (a += B, c++);
535
535
  }), a = Math.round(a * 100) / 100, s = Math.round(s * 100) / 100, {
536
536
  isCorrect: c === e && e > 0,
537
537
  score: a,
@@ -629,7 +629,7 @@ function nt(t, n) {
629
629
  if (!(!n || !o)) {
630
630
  w(!0), p(void 0);
631
631
  try {
632
- const e = new Blob([o], { type: "text/plain; charset=utf-8" }), s = `writing-${t.id}-${Date.now()}.txt`, l = await n(e, s);
632
+ const e = new Blob([o], { type: "text/plain; charset=utf-8" }), s = `writing-${Date.now()}.txt`, l = await n(e, s);
633
633
  l.success && l.url ? I(l.url) : p(l.error || "Upload failed");
634
634
  } catch (e) {
635
635
  console.error("Text upload failed:", e), p(
@@ -639,14 +639,13 @@ function nt(t, n) {
639
639
  w(!1);
640
640
  }
641
641
  }
642
- }, [o, t.id, n]), c = T(
642
+ }, [o, n]), c = T(
643
643
  () => ({
644
- questionId: t.id || "",
645
644
  type: "writing",
646
645
  text: o,
647
646
  fileUrl: h
648
647
  }),
649
- [t.id, o, h]
648
+ [o, h]
650
649
  ), i = R(() => (C(), c), [C, c]), r = R(() => {
651
650
  d(""), I(void 0), p(void 0), S();
652
651
  }, [S]);
@@ -669,23 +668,23 @@ function nt(t, n) {
669
668
  };
670
669
  }
671
670
  function st(t, n) {
672
- 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), [m, p] = A(!1), [x, a] = A(void 0), [c, i] = A(!1), r = _(null), e = _([]), s = _(null), l = _(null), g = R(async () => {
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), [m, p] = A(!1), [x, a] = A(void 0), [c, i] = A(!1), r = F(null), e = F([]), s = F(null), l = F(null), g = R(async () => {
673
672
  i(!0);
674
673
  try {
675
674
  const Q = await navigator.mediaDevices.getUserMedia({ audio: !0 });
676
675
  l.current = Q;
677
676
  const k = new MediaRecorder(Q);
678
- r.current = k, e.current = [], k.ondataavailable = (F) => {
679
- F.data.size > 0 && e.current.push(F.data);
677
+ r.current = k, e.current = [], k.ondataavailable = (_) => {
678
+ _.data.size > 0 && e.current.push(_.data);
680
679
  }, k.onstop = () => {
681
- const F = new Blob(e.current, {
680
+ const _ = new Blob(e.current, {
682
681
  type: "audio/webm"
683
- }), P = URL.createObjectURL(F);
682
+ }), P = URL.createObjectURL(_);
684
683
  d(P);
685
684
  }, k.start(), I("recording"), w(0);
686
- let O = 0;
685
+ let L = 0;
687
686
  s.current = setInterval(() => {
688
- O++, w((F) => F + 1), O >= (t.metadata?.max_recording_time || 300) && B();
687
+ L++, w(L), L >= (t.metadata?.max_recording_time || 300) && B();
689
688
  }, 1e3);
690
689
  } catch (Q) {
691
690
  console.error("Failed to start recording:", Q), a("Failed to access microphone");
@@ -697,22 +696,24 @@ function st(t, n) {
697
696
  w((Q) => Q + 1);
698
697
  }, 1e3));
699
698
  }, [h]), B = R(() => {
700
- r.current && h !== "idle" && (r.current.stop(), I("stopped"), s.current && clearInterval(s.current), l.current && l.current.getTracks().forEach((Q) => Q.stop()), i(!1));
701
- }, [h]), L = R(() => c ? B() : g(), []), M = R(async () => {
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 = R(() => {
701
+ c ? B() : g();
702
+ }, [c]), M = R(async () => {
702
703
  if (!(!e.current.length || !n)) {
703
704
  p(!0), a(void 0);
704
705
  try {
705
706
  const Q = new Blob(e.current, {
706
707
  type: "audio/webm"
707
- }), k = `speaking-${t.id}-${Date.now()}.webm`, O = await n(Q, k);
708
- O.success && O.url ? d(O.url) : a(O.error || "Upload failed");
708
+ }), k = `speaking-${Date.now()}.webm`, L = await n(Q, k);
709
+ L.success && L.url ? d(L.url) : a(L.error || "Upload failed");
709
710
  } catch (Q) {
710
711
  console.error("Upload failed:", Q), a(Q instanceof Error ? Q.message : "Upload failed");
711
712
  } finally {
712
713
  p(!1);
713
714
  }
714
715
  }
715
- }, [t.id, n]), D = R(
716
+ }, [t, n]), D = R(
716
717
  async (Q) => {
717
718
  if (n) {
718
719
  p(!0), a(void 0);
@@ -731,12 +732,11 @@ function st(t, n) {
731
732
  [n]
732
733
  ), j = T(
733
734
  () => ({
734
- questionId: t.id || "",
735
735
  type: "speaking",
736
736
  audioUrl: o
737
737
  }),
738
- [t.id, o]
739
- ), G = R(() => (C(), j), [C, j]), N = R(() => {
738
+ [t, o]
739
+ ), $ = R(() => (C(), j), [C, j]), N = R(() => {
740
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
741
  }, [S]);
742
742
  return {
@@ -756,10 +756,10 @@ function st(t, n) {
756
756
  pauseRecording: y,
757
757
  resumeRecording: U,
758
758
  stopRecording: B,
759
- toggleRecording: L,
759
+ toggleRecording: O,
760
760
  uploadAudio: M,
761
761
  uploadFile: D,
762
- submit: G,
762
+ submit: $,
763
763
  reset: N
764
764
  };
765
765
  }
@@ -832,7 +832,7 @@ function bt({
832
832
  uploadHandler: u
833
833
  }) {
834
834
  const f = t(), b = nt(f, u);
835
- return /* @__PURE__ */ W($, { children: n(b) });
835
+ return /* @__PURE__ */ W(z, { children: n(b) });
836
836
  }
837
837
  function wt({
838
838
  getData: t,
@@ -840,7 +840,7 @@ function wt({
840
840
  uploadHandler: u
841
841
  }) {
842
842
  const f = t(), b = st(f, u);
843
- return /* @__PURE__ */ W($, { children: n(b) });
843
+ return /* @__PURE__ */ W(z, { children: n(b) });
844
844
  }
845
845
  export {
846
846
  lt as DragDropQuestion,
@@ -855,7 +855,7 @@ export {
855
855
  at as VideoQuestion,
856
856
  bt as WritingQuestion,
857
857
  J as isSameSet,
858
- z as shuffleArray,
858
+ G as shuffleArray,
859
859
  E as useBaseQuestion,
860
860
  K as useDragDrop,
861
861
  tt as useFillInBlank,
@@ -4,7 +4,6 @@ export interface Media {
4
4
  url?: string;
5
5
  }
6
6
  export interface BaseQuestion {
7
- id?: string | number;
8
7
  type: string;
9
8
  content: {
10
9
  text?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,MAAM,WAAW,KAAK;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QACP,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,KAAK,CAAC;QACd,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;KAClB,CAAC;IACF,eAAe,EACb;QACA,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;KACxB,GACC;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC;IACnC,QAAQ,EAAE;QACR,YAAY,EAAE,MAAM,CAAC;QACrB,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED,MAAM,WAAW,cAAc,CAAC,IAAI,EAAE,GAAG;IACvC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,SAAS,CAAC;CACnC"}
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/types/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,MAAM,WAAW,KAAK;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QACP,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,KAAK,CAAC;QACd,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;KAClB,CAAC;IACF,eAAe,EACX;QACE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;KACxB,GACD;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC;IACrC,QAAQ,EAAE;QACR,YAAY,EAAE,MAAM,CAAC;QACrB,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED,MAAM,WAAW,cAAc,CAAC,IAAI,EAAE,GAAG;IACvC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,SAAS,CAAC;CACnC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enspiredigital/xlms-headless",
3
- "version": "0.0.26",
3
+ "version": "0.0.28",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",