@lessonkit/react 0.9.2 → 0.9.3

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/README.md CHANGED
@@ -59,7 +59,7 @@ export default function App() {
59
59
  }
60
60
  ```
61
61
 
62
- ## API (0.9.2)
62
+ ## API (0.9.3)
63
63
 
64
64
  ### Block catalog
65
65
 
package/dist/index.cjs CHANGED
@@ -541,10 +541,7 @@ function LessonkitProvider(props) {
541
541
  useIsoLayoutEffect(() => {
542
542
  const prev = trackingRef.current;
543
543
  const baseSink = config.tracking?.sink;
544
- const sink = pluginHostRef.current && baseSink ? (event) => {
545
- const composed = pluginHostRef.current.composeTrackingSink(baseSink, buildCurrentPluginCtx()) ?? baseSink;
546
- return composed(event);
547
- } : baseSink;
544
+ const sink = pluginHostRef.current && baseSink ? pluginHostRef.current.composeTrackingSink(baseSink, buildCurrentPluginCtx) ?? baseSink : baseSink;
548
545
  const batchSink = pluginHostRef.current && config.tracking?.batchSink ? (events) => {
549
546
  const delivered = pluginHostRef.current.deliverTelemetryBatch(
550
547
  events,
@@ -675,9 +672,10 @@ function LessonkitProvider(props) {
675
672
  (0, import_react.useEffect)(() => {
676
673
  return () => {
677
674
  const client = trackingClientForUnmountRef.current;
675
+ const xapi2 = xapiRef.current;
678
676
  void (async () => {
679
677
  try {
680
- await xapiRef.current?.flush();
678
+ await xapi2?.flush();
681
679
  } catch {
682
680
  }
683
681
  try {
@@ -710,12 +708,19 @@ function LessonkitProvider(props) {
710
708
  [track, syncProgress, emitLessonCompleted]
711
709
  );
712
710
  const completeCourse = (0, import_react.useCallback)(() => {
711
+ const current = progressRef.current.getState();
712
+ if (current.activeLessonId) {
713
+ const lessonResult = progressRef.current.completeLesson(current.activeLessonId, Date.now());
714
+ if (lessonResult.didComplete) {
715
+ emitLessonCompleted(current.activeLessonId, lessonResult.durationMs);
716
+ }
717
+ }
713
718
  const result = progressRef.current.completeCourse();
714
719
  if (!result.didComplete) return;
715
720
  syncProgress();
716
721
  track("course_completed");
717
722
  void trackingRef.current?.flush?.();
718
- }, [track, syncProgress]);
723
+ }, [track, syncProgress, emitLessonCompleted]);
719
724
  const sessionUser = config.session?.user;
720
725
  const sessionAttemptId = config.session?.attemptId;
721
726
  const sessionConfiguredId = config.session?.sessionId;
@@ -898,7 +903,8 @@ function KnowledgeCheck(props) {
898
903
  checkId: props.checkId,
899
904
  question: props.question,
900
905
  choices: props.choices,
901
- answer: props.answer
906
+ answer: props.answer,
907
+ passingScore: props.passingScore
902
908
  }
903
909
  );
904
910
  }
@@ -914,7 +920,7 @@ function Quiz(props) {
914
920
  completedRef.current = false;
915
921
  setSelected(null);
916
922
  setSelectionCorrect(null);
917
- }, [props.checkId, props.answer, props.question]);
923
+ }, [props.checkId, props.answer, props.question, config.courseId]);
918
924
  const isChoiceCorrect = (choice, custom) => {
919
925
  if (!custom) return choice === props.answer;
920
926
  if (custom.passed !== void 0) return custom.passed;
@@ -964,7 +970,7 @@ function Quiz(props) {
964
970
  checkId: props.checkId,
965
971
  score: custom?.score ?? 1,
966
972
  maxScore: custom?.maxScore ?? 1,
967
- passingScore: 1
973
+ passingScore: props.passingScore ?? 1
968
974
  });
969
975
  }
970
976
  }
package/dist/index.d.cts CHANGED
@@ -91,12 +91,14 @@ declare function KnowledgeCheck(props: {
91
91
  question: string;
92
92
  choices: string[];
93
93
  answer: string;
94
+ passingScore?: number;
94
95
  }): react_jsx_runtime.JSX.Element;
95
96
  declare function Quiz(props: {
96
97
  checkId: CheckId;
97
98
  question: string;
98
99
  choices: string[];
99
100
  answer: string;
101
+ passingScore?: number;
100
102
  }): react_jsx_runtime.JSX.Element;
101
103
  declare function ProgressTracker(): react_jsx_runtime.JSX.Element;
102
104
 
package/dist/index.d.ts CHANGED
@@ -91,12 +91,14 @@ declare function KnowledgeCheck(props: {
91
91
  question: string;
92
92
  choices: string[];
93
93
  answer: string;
94
+ passingScore?: number;
94
95
  }): react_jsx_runtime.JSX.Element;
95
96
  declare function Quiz(props: {
96
97
  checkId: CheckId;
97
98
  question: string;
98
99
  choices: string[];
99
100
  answer: string;
101
+ passingScore?: number;
100
102
  }): react_jsx_runtime.JSX.Element;
101
103
  declare function ProgressTracker(): react_jsx_runtime.JSX.Element;
102
104
 
package/dist/index.js CHANGED
@@ -499,10 +499,7 @@ function LessonkitProvider(props) {
499
499
  useIsoLayoutEffect(() => {
500
500
  const prev = trackingRef.current;
501
501
  const baseSink = config.tracking?.sink;
502
- const sink = pluginHostRef.current && baseSink ? (event) => {
503
- const composed = pluginHostRef.current.composeTrackingSink(baseSink, buildCurrentPluginCtx()) ?? baseSink;
504
- return composed(event);
505
- } : baseSink;
502
+ const sink = pluginHostRef.current && baseSink ? pluginHostRef.current.composeTrackingSink(baseSink, buildCurrentPluginCtx) ?? baseSink : baseSink;
506
503
  const batchSink = pluginHostRef.current && config.tracking?.batchSink ? (events) => {
507
504
  const delivered = pluginHostRef.current.deliverTelemetryBatch(
508
505
  events,
@@ -633,9 +630,10 @@ function LessonkitProvider(props) {
633
630
  useEffect(() => {
634
631
  return () => {
635
632
  const client = trackingClientForUnmountRef.current;
633
+ const xapi2 = xapiRef.current;
636
634
  void (async () => {
637
635
  try {
638
- await xapiRef.current?.flush();
636
+ await xapi2?.flush();
639
637
  } catch {
640
638
  }
641
639
  try {
@@ -668,12 +666,19 @@ function LessonkitProvider(props) {
668
666
  [track, syncProgress, emitLessonCompleted]
669
667
  );
670
668
  const completeCourse = useCallback(() => {
669
+ const current = progressRef.current.getState();
670
+ if (current.activeLessonId) {
671
+ const lessonResult = progressRef.current.completeLesson(current.activeLessonId, Date.now());
672
+ if (lessonResult.didComplete) {
673
+ emitLessonCompleted(current.activeLessonId, lessonResult.durationMs);
674
+ }
675
+ }
671
676
  const result = progressRef.current.completeCourse();
672
677
  if (!result.didComplete) return;
673
678
  syncProgress();
674
679
  track("course_completed");
675
680
  void trackingRef.current?.flush?.();
676
- }, [track, syncProgress]);
681
+ }, [track, syncProgress, emitLessonCompleted]);
677
682
  const sessionUser = config.session?.user;
678
683
  const sessionAttemptId = config.session?.attemptId;
679
684
  const sessionConfiguredId = config.session?.sessionId;
@@ -856,7 +861,8 @@ function KnowledgeCheck(props) {
856
861
  checkId: props.checkId,
857
862
  question: props.question,
858
863
  choices: props.choices,
859
- answer: props.answer
864
+ answer: props.answer,
865
+ passingScore: props.passingScore
860
866
  }
861
867
  );
862
868
  }
@@ -872,7 +878,7 @@ function Quiz(props) {
872
878
  completedRef.current = false;
873
879
  setSelected(null);
874
880
  setSelectionCorrect(null);
875
- }, [props.checkId, props.answer, props.question]);
881
+ }, [props.checkId, props.answer, props.question, config.courseId]);
876
882
  const isChoiceCorrect = (choice, custom) => {
877
883
  if (!custom) return choice === props.answer;
878
884
  if (custom.passed !== void 0) return custom.passed;
@@ -922,7 +928,7 @@ function Quiz(props) {
922
928
  checkId: props.checkId,
923
929
  score: custom?.score ?? 1,
924
930
  maxScore: custom?.maxScore ?? 1,
925
- passingScore: 1
931
+ passingScore: props.passingScore ?? 1
926
932
  });
927
933
  }
928
934
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lessonkit/react",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "private": false,
5
5
  "description": "React components and hooks for building learning experiences with LessonKit.",
6
6
  "license": "Apache-2.0",
@@ -54,11 +54,11 @@
54
54
  "react-dom": ">=18"
55
55
  },
56
56
  "dependencies": {
57
- "@lessonkit/accessibility": "0.9.2",
58
- "@lessonkit/core": "0.9.2",
59
- "@lessonkit/lxpack": "0.9.2",
60
- "@lessonkit/themes": "0.9.2",
61
- "@lessonkit/xapi": "0.9.2"
57
+ "@lessonkit/accessibility": "0.9.3",
58
+ "@lessonkit/core": "0.9.3",
59
+ "@lessonkit/lxpack": "0.9.3",
60
+ "@lessonkit/themes": "0.9.3",
61
+ "@lessonkit/xapi": "0.9.3"
62
62
  },
63
63
  "devDependencies": {
64
64
  "@testing-library/react": "^16.3.0",