@patch-adams/core 1.4.11 → 1.4.13

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/dist/cli.js CHANGED
@@ -3368,10 +3368,10 @@ function generateLrsBridgeCode(options) {
3368
3368
  var result = {
3369
3369
  completion: true,
3370
3370
  extensions: {
3371
- 'https://patch-adams.io/xapi/extensions/assessmentName': data.assessmentName || data.title || null,
3372
- 'https://patch-adams.io/xapi/extensions/lessonName': lessonInfo.name || null,
3373
- 'https://patch-adams.io/xapi/extensions/sectionName': lessonInfo.sectionName || null,
3374
- 'https://patch-adams.io/xapi/extensions/questionCount': data.questionCount || null
3371
+ 'https://w3id.org/xapi/acrossx/extensions/assessmentName': data.assessmentName || data.title || null,
3372
+ 'https://w3id.org/xapi/acrossx/extensions/lessonName': lessonInfo.name || null,
3373
+ 'https://w3id.org/xapi/acrossx/extensions/sectionName': lessonInfo.sectionName || null,
3374
+ 'https://w3id.org/xapi/acrossx/extensions/questionCount': data.questionCount || null
3375
3375
  }
3376
3376
  };
3377
3377
 
@@ -3415,13 +3415,13 @@ function generateLrsBridgeCode(options) {
3415
3415
  var result = {
3416
3416
  response: data.answer || data.response || '',
3417
3417
  extensions: {
3418
- 'https://patch-adams.io/xapi/extensions/questionNumber': data.questionNumber || null,
3419
- 'https://patch-adams.io/xapi/extensions/questionText': data.questionText || null,
3420
- 'https://patch-adams.io/xapi/extensions/answerText': data.answer || data.response || null,
3421
- 'https://patch-adams.io/xapi/extensions/correctAnswer': data.correctAnswer || null,
3422
- 'https://patch-adams.io/xapi/extensions/assessmentName': data.assessmentName || null,
3423
- 'https://patch-adams.io/xapi/extensions/lessonName': lessonInfo.lessonName || lessonInfo.name || null,
3424
- 'https://patch-adams.io/xapi/extensions/sectionName': lessonInfo.sectionName || null
3418
+ 'https://w3id.org/xapi/acrossx/extensions/questionNumber': data.questionNumber || null,
3419
+ 'https://w3id.org/xapi/acrossx/extensions/questionText': data.questionText || null,
3420
+ 'https://w3id.org/xapi/acrossx/extensions/answerText': data.answer || data.response || null,
3421
+ 'https://w3id.org/xapi/acrossx/extensions/correctAnswer': data.correctAnswer || null,
3422
+ 'https://w3id.org/xapi/acrossx/extensions/assessmentName': data.assessmentName || null,
3423
+ 'https://w3id.org/xapi/acrossx/extensions/lessonName': lessonInfo.lessonName || lessonInfo.name || null,
3424
+ 'https://w3id.org/xapi/acrossx/extensions/sectionName': lessonInfo.sectionName || null
3425
3425
  }
3426
3426
  };
3427
3427
 
@@ -3722,6 +3722,9 @@ function generateLrsBridgeCode(options) {
3722
3722
  function setupQuizInterceptors() {
3723
3723
  if (!TRACK_QUIZZES) return;
3724
3724
 
3725
+ // Set up Knowledge Check specific interceptors for Rise blocks
3726
+ setupKnowledgeCheckInterceptors();
3727
+
3725
3728
  var quizObserver = new MutationObserver(function(mutations) {
3726
3729
  mutations.forEach(function(mutation) {
3727
3730
  mutation.addedNodes.forEach(function(node) {
@@ -3926,6 +3929,162 @@ function generateLrsBridgeCode(options) {
3926
3929
  });
3927
3930
  }
3928
3931
 
3932
+ // Track submitted Knowledge Check blocks to avoid duplicates
3933
+ var submittedKnowledgeChecks = {};
3934
+
3935
+ /**
3936
+ * Set up interceptors specifically for Rise Knowledge Check blocks
3937
+ * These blocks have a different DOM structure than standard quiz results
3938
+ */
3939
+ function setupKnowledgeCheckInterceptors() {
3940
+ if (!TRACK_QUIZZES) return;
3941
+
3942
+ // Intercept submit button clicks on Knowledge Check blocks
3943
+ document.addEventListener('click', function(e) {
3944
+ var submitBtn = e.target.closest('.quiz-card__button');
3945
+ if (!submitBtn) return;
3946
+
3947
+ // Find the Knowledge Check block
3948
+ var kcBlock = submitBtn.closest('[data-test-id="block-kc-card"]') ||
3949
+ submitBtn.closest('.block-knowledge');
3950
+ if (!kcBlock) return;
3951
+
3952
+ // Wait for feedback to appear after submission
3953
+ setTimeout(function() {
3954
+ extractKnowledgeCheckResult(kcBlock);
3955
+ }, 500);
3956
+ }, true);
3957
+
3958
+ log('Knowledge Check interceptors set up');
3959
+ }
3960
+
3961
+ /**
3962
+ * Extract and send xAPI statement for a Knowledge Check submission
3963
+ */
3964
+ function extractKnowledgeCheckResult(kcBlock) {
3965
+ // Get block ID for deduplication
3966
+ var blockContainer = kcBlock.closest('[data-block-id]');
3967
+ var blockId = blockContainer ? blockContainer.getAttribute('data-block-id') : null;
3968
+
3969
+ // Get question ID from the title element
3970
+ var questionTitleEl = kcBlock.querySelector('.quiz-card__title');
3971
+ var questionId = questionTitleEl ? questionTitleEl.id : (blockId ? 'q-' + blockId : 'q-' + generateUUID());
3972
+
3973
+ // Check if we already processed this submission (avoid duplicates)
3974
+ var submissionKey = blockId || questionId;
3975
+ var feedbackLabel = kcBlock.querySelector('.quiz-card__feedback-label');
3976
+ if (!feedbackLabel) {
3977
+ log('Knowledge Check: No feedback visible yet');
3978
+ return;
3979
+ }
3980
+
3981
+ var feedbackText = feedbackLabel.textContent.trim().toLowerCase();
3982
+ var submissionId = submissionKey + '-' + feedbackText;
3983
+
3984
+ if (submittedKnowledgeChecks[submissionId]) {
3985
+ log('Knowledge Check: Already processed this submission');
3986
+ return;
3987
+ }
3988
+ submittedKnowledgeChecks[submissionId] = true;
3989
+
3990
+ // Get question text
3991
+ var questionText = '';
3992
+ var questionTextEl = kcBlock.querySelector('.quiz-card__title .fr-view, .quiz-card__title');
3993
+ if (questionTextEl) {
3994
+ questionText = questionTextEl.textContent.trim();
3995
+ }
3996
+
3997
+ // Determine question type from aria-label
3998
+ var wrapper = kcBlock.querySelector('[data-test-id="block-knowledge-wrapper"]');
3999
+ var ariaLabel = wrapper ? wrapper.getAttribute('aria-label') : '';
4000
+ var questionType = 'unknown';
4001
+ if (ariaLabel.indexOf('Multiple choice') > -1) questionType = 'multiple-choice';
4002
+ else if (ariaLabel.indexOf('Multiple response') > -1) questionType = 'multiple-response';
4003
+ else if (ariaLabel.indexOf('Fill in the blank') > -1) questionType = 'fill-in-blank';
4004
+ else if (ariaLabel.indexOf('Matching') > -1) questionType = 'matching';
4005
+
4006
+ // Get selected answer(s) based on question type
4007
+ var answerText = extractKnowledgeCheckAnswer(kcBlock, questionType);
4008
+
4009
+ // Get correct/incorrect from feedback
4010
+ var isCorrect = feedbackText === 'correct';
4011
+
4012
+ // Get lesson context
4013
+ var lessonInfo = getCachedLessonInfo();
4014
+
4015
+ log('Knowledge Check submitted:', {
4016
+ questionId: questionId,
4017
+ questionText: questionText.substring(0, 50) + '...',
4018
+ questionType: questionType,
4019
+ answer: answerText.substring(0, 50) + '...',
4020
+ correct: isCorrect
4021
+ });
4022
+
4023
+ // Send question answered statement using existing LRS method
4024
+ LRS.questionAnswered({
4025
+ questionId: questionId,
4026
+ questionGuid: blockId || generateUUID(),
4027
+ questionNumber: 1,
4028
+ questionText: questionText.substring(0, 500),
4029
+ questionType: questionType,
4030
+ answer: answerText.substring(0, 500),
4031
+ correct: isCorrect,
4032
+ result: isCorrect ? 'correct' : 'incorrect',
4033
+ assessmentName: 'Knowledge Check',
4034
+ lessonName: lessonInfo.name,
4035
+ sectionName: lessonInfo.sectionName
4036
+ });
4037
+ }
4038
+
4039
+ /**
4040
+ * Extract the selected answer text from a Knowledge Check block
4041
+ * based on the question type
4042
+ */
4043
+ function extractKnowledgeCheckAnswer(kcBlock, questionType) {
4044
+ var answerText = '';
4045
+
4046
+ if (questionType === 'multiple-choice') {
4047
+ // Find checked radio button
4048
+ var checkedInput = kcBlock.querySelector('.quiz-multiple-choice-option__input:checked');
4049
+ if (checkedInput) {
4050
+ var label = checkedInput.closest('.quiz-multiple-choice-option');
4051
+ var textEl = label ? label.querySelector('.quiz-multiple-choice-option__label .fr-view, .quiz-multiple-choice-option__label') : null;
4052
+ answerText = textEl ? textEl.textContent.trim() : '';
4053
+ }
4054
+ }
4055
+ else if (questionType === 'multiple-response') {
4056
+ // Find all checked checkboxes
4057
+ var checkedInputs = kcBlock.querySelectorAll('.quiz-multiple-response-option__input:checked');
4058
+ var answers = [];
4059
+ checkedInputs.forEach(function(input) {
4060
+ var label = input.closest('.quiz-multiple-response-option');
4061
+ var textEl = label ? label.querySelector('.quiz-multiple-response-option__text .fr-view, .quiz-multiple-response-option__text') : null;
4062
+ if (textEl) answers.push(textEl.textContent.trim());
4063
+ });
4064
+ answerText = answers.join('; ');
4065
+ }
4066
+ else if (questionType === 'fill-in-blank') {
4067
+ // Get text input value
4068
+ var textInput = kcBlock.querySelector('.quiz-fill__input');
4069
+ answerText = textInput ? textInput.value.trim() : '';
4070
+ }
4071
+ else if (questionType === 'matching') {
4072
+ // Extract matching pairs from the drop zones
4073
+ var dropZones = kcBlock.querySelectorAll('.matching-drop-zone');
4074
+ var pairs = [];
4075
+ dropZones.forEach(function(zone) {
4076
+ var prompt = zone.querySelector('.matching-prompt-content');
4077
+ var response = zone.querySelector('.matching-interaction-piece-content');
4078
+ if (prompt && response) {
4079
+ pairs.push(prompt.textContent.trim() + ' \u2192 ' + response.textContent.trim());
4080
+ }
4081
+ });
4082
+ answerText = pairs.length > 0 ? pairs.join('; ') : 'Matching submitted';
4083
+ }
4084
+
4085
+ return answerText;
4086
+ }
4087
+
3929
4088
  function setupInteractionInterceptors() {
3930
4089
  if (!TRACK_INTERACTIONS) return;
3931
4090