@patch-adams/core 1.4.10 → 1.4.12

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/index.cjs CHANGED
@@ -2898,7 +2898,8 @@ function generateLrsBridgeCode(options) {
2898
2898
  sendStatement(statement);
2899
2899
  };
2900
2900
 
2901
- // Content/Page viewed - uses document as object for Bravais aggregation
2901
+ // Content/Page viewed - uses page-specific object for human-readable display
2902
+ // Object shows page/lesson title, parent context maintains document aggregation
2902
2903
  LRS.contentOpened = function(data) {
2903
2904
  if (!TRACK_NAVIGATION) return;
2904
2905
 
@@ -2918,31 +2919,31 @@ function generateLrsBridgeCode(options) {
2918
2919
  lessonId = lessonId.substring(2); // Remove '#/'
2919
2920
  }
2920
2921
 
2921
- // Add page info to context extensions (not as main object)
2922
+ // Get the page title - prefer lesson name from DOM
2923
+ var pageTitle = data.title || lessonInfo.name || 'Page';
2924
+
2925
+ // Build page activity object with human-readable name
2926
+ // This shows the page/lesson title in the Object column
2927
+ var pageObject = buildPageActivityObject({
2928
+ pageGuid: lessonId,
2929
+ name: pageTitle,
2930
+ resourceType: 'Lesson'
2931
+ });
2932
+
2933
+ // Add page info to context extensions
2922
2934
  var additionalContext = {
2923
2935
  extensions: {
2924
2936
  pageId: lessonId || 'home',
2925
- pageTitle: data.title || lessonInfo.name || 'Page',
2937
+ pageTitle: pageTitle,
2926
2938
  lessonName: lessonInfo.name,
2927
2939
  sectionName: lessonInfo.sectionName,
2928
2940
  pageUrl: data.url || window.location.href
2929
2941
  }
2930
2942
  };
2931
2943
 
2932
- // Use document as main object (required for Bravais aggregation)
2933
- // Use 'experienced' verb which is standard xAPI for viewing content
2934
- var statement = buildStatement(
2935
- 'experienced',
2936
- 'http://xyleme.com/bravais/activities/document',
2937
- {
2938
- event: 'page_viewed',
2939
- pageId: lessonId,
2940
- lessonName: lessonInfo.name,
2941
- sectionName: lessonInfo.sectionName
2942
- },
2943
- result,
2944
- additionalContext
2945
- );
2944
+ // Use 'experienced' verb for viewing content
2945
+ // Parent course activity added by buildXylemeContext ensures document aggregation
2946
+ var statement = buildStatementXyleme('experienced', pageObject, result, additionalContext);
2946
2947
  sendStatement(statement);
2947
2948
  };
2948
2949
 
@@ -3394,6 +3395,9 @@ function generateLrsBridgeCode(options) {
3394
3395
  function setupQuizInterceptors() {
3395
3396
  if (!TRACK_QUIZZES) return;
3396
3397
 
3398
+ // Set up Knowledge Check specific interceptors for Rise blocks
3399
+ setupKnowledgeCheckInterceptors();
3400
+
3397
3401
  var quizObserver = new MutationObserver(function(mutations) {
3398
3402
  mutations.forEach(function(mutation) {
3399
3403
  mutation.addedNodes.forEach(function(node) {
@@ -3598,6 +3602,162 @@ function generateLrsBridgeCode(options) {
3598
3602
  });
3599
3603
  }
3600
3604
 
3605
+ // Track submitted Knowledge Check blocks to avoid duplicates
3606
+ var submittedKnowledgeChecks = {};
3607
+
3608
+ /**
3609
+ * Set up interceptors specifically for Rise Knowledge Check blocks
3610
+ * These blocks have a different DOM structure than standard quiz results
3611
+ */
3612
+ function setupKnowledgeCheckInterceptors() {
3613
+ if (!TRACK_QUIZZES) return;
3614
+
3615
+ // Intercept submit button clicks on Knowledge Check blocks
3616
+ document.addEventListener('click', function(e) {
3617
+ var submitBtn = e.target.closest('.quiz-card__button');
3618
+ if (!submitBtn) return;
3619
+
3620
+ // Find the Knowledge Check block
3621
+ var kcBlock = submitBtn.closest('[data-test-id="block-kc-card"]') ||
3622
+ submitBtn.closest('.block-knowledge');
3623
+ if (!kcBlock) return;
3624
+
3625
+ // Wait for feedback to appear after submission
3626
+ setTimeout(function() {
3627
+ extractKnowledgeCheckResult(kcBlock);
3628
+ }, 500);
3629
+ }, true);
3630
+
3631
+ log('Knowledge Check interceptors set up');
3632
+ }
3633
+
3634
+ /**
3635
+ * Extract and send xAPI statement for a Knowledge Check submission
3636
+ */
3637
+ function extractKnowledgeCheckResult(kcBlock) {
3638
+ // Get block ID for deduplication
3639
+ var blockContainer = kcBlock.closest('[data-block-id]');
3640
+ var blockId = blockContainer ? blockContainer.getAttribute('data-block-id') : null;
3641
+
3642
+ // Get question ID from the title element
3643
+ var questionTitleEl = kcBlock.querySelector('.quiz-card__title');
3644
+ var questionId = questionTitleEl ? questionTitleEl.id : (blockId ? 'q-' + blockId : 'q-' + generateUUID());
3645
+
3646
+ // Check if we already processed this submission (avoid duplicates)
3647
+ var submissionKey = blockId || questionId;
3648
+ var feedbackLabel = kcBlock.querySelector('.quiz-card__feedback-label');
3649
+ if (!feedbackLabel) {
3650
+ log('Knowledge Check: No feedback visible yet');
3651
+ return;
3652
+ }
3653
+
3654
+ var feedbackText = feedbackLabel.textContent.trim().toLowerCase();
3655
+ var submissionId = submissionKey + '-' + feedbackText;
3656
+
3657
+ if (submittedKnowledgeChecks[submissionId]) {
3658
+ log('Knowledge Check: Already processed this submission');
3659
+ return;
3660
+ }
3661
+ submittedKnowledgeChecks[submissionId] = true;
3662
+
3663
+ // Get question text
3664
+ var questionText = '';
3665
+ var questionTextEl = kcBlock.querySelector('.quiz-card__title .fr-view, .quiz-card__title');
3666
+ if (questionTextEl) {
3667
+ questionText = questionTextEl.textContent.trim();
3668
+ }
3669
+
3670
+ // Determine question type from aria-label
3671
+ var wrapper = kcBlock.querySelector('[data-test-id="block-knowledge-wrapper"]');
3672
+ var ariaLabel = wrapper ? wrapper.getAttribute('aria-label') : '';
3673
+ var questionType = 'unknown';
3674
+ if (ariaLabel.indexOf('Multiple choice') > -1) questionType = 'multiple-choice';
3675
+ else if (ariaLabel.indexOf('Multiple response') > -1) questionType = 'multiple-response';
3676
+ else if (ariaLabel.indexOf('Fill in the blank') > -1) questionType = 'fill-in-blank';
3677
+ else if (ariaLabel.indexOf('Matching') > -1) questionType = 'matching';
3678
+
3679
+ // Get selected answer(s) based on question type
3680
+ var answerText = extractKnowledgeCheckAnswer(kcBlock, questionType);
3681
+
3682
+ // Get correct/incorrect from feedback
3683
+ var isCorrect = feedbackText === 'correct';
3684
+
3685
+ // Get lesson context
3686
+ var lessonInfo = getCachedLessonInfo();
3687
+
3688
+ log('Knowledge Check submitted:', {
3689
+ questionId: questionId,
3690
+ questionText: questionText.substring(0, 50) + '...',
3691
+ questionType: questionType,
3692
+ answer: answerText.substring(0, 50) + '...',
3693
+ correct: isCorrect
3694
+ });
3695
+
3696
+ // Send question answered statement using existing LRS method
3697
+ LRS.questionAnswered({
3698
+ questionId: questionId,
3699
+ questionGuid: blockId || generateUUID(),
3700
+ questionNumber: 1,
3701
+ questionText: questionText.substring(0, 500),
3702
+ questionType: questionType,
3703
+ answer: answerText.substring(0, 500),
3704
+ correct: isCorrect,
3705
+ result: isCorrect ? 'correct' : 'incorrect',
3706
+ assessmentName: 'Knowledge Check',
3707
+ lessonName: lessonInfo.name,
3708
+ sectionName: lessonInfo.sectionName
3709
+ });
3710
+ }
3711
+
3712
+ /**
3713
+ * Extract the selected answer text from a Knowledge Check block
3714
+ * based on the question type
3715
+ */
3716
+ function extractKnowledgeCheckAnswer(kcBlock, questionType) {
3717
+ var answerText = '';
3718
+
3719
+ if (questionType === 'multiple-choice') {
3720
+ // Find checked radio button
3721
+ var checkedInput = kcBlock.querySelector('.quiz-multiple-choice-option__input:checked');
3722
+ if (checkedInput) {
3723
+ var label = checkedInput.closest('.quiz-multiple-choice-option');
3724
+ var textEl = label ? label.querySelector('.quiz-multiple-choice-option__label .fr-view, .quiz-multiple-choice-option__label') : null;
3725
+ answerText = textEl ? textEl.textContent.trim() : '';
3726
+ }
3727
+ }
3728
+ else if (questionType === 'multiple-response') {
3729
+ // Find all checked checkboxes
3730
+ var checkedInputs = kcBlock.querySelectorAll('.quiz-multiple-response-option__input:checked');
3731
+ var answers = [];
3732
+ checkedInputs.forEach(function(input) {
3733
+ var label = input.closest('.quiz-multiple-response-option');
3734
+ var textEl = label ? label.querySelector('.quiz-multiple-response-option__text .fr-view, .quiz-multiple-response-option__text') : null;
3735
+ if (textEl) answers.push(textEl.textContent.trim());
3736
+ });
3737
+ answerText = answers.join('; ');
3738
+ }
3739
+ else if (questionType === 'fill-in-blank') {
3740
+ // Get text input value
3741
+ var textInput = kcBlock.querySelector('.quiz-fill__input');
3742
+ answerText = textInput ? textInput.value.trim() : '';
3743
+ }
3744
+ else if (questionType === 'matching') {
3745
+ // Extract matching pairs from the drop zones
3746
+ var dropZones = kcBlock.querySelectorAll('.matching-drop-zone');
3747
+ var pairs = [];
3748
+ dropZones.forEach(function(zone) {
3749
+ var prompt = zone.querySelector('.matching-prompt-content');
3750
+ var response = zone.querySelector('.matching-interaction-piece-content');
3751
+ if (prompt && response) {
3752
+ pairs.push(prompt.textContent.trim() + ' \u2192 ' + response.textContent.trim());
3753
+ }
3754
+ });
3755
+ answerText = pairs.length > 0 ? pairs.join('; ') : 'Matching submitted';
3756
+ }
3757
+
3758
+ return answerText;
3759
+ }
3760
+
3601
3761
  function setupInteractionInterceptors() {
3602
3762
  if (!TRACK_INTERACTIONS) return;
3603
3763