@intellectif/lk-react 6.0.0 → 7.0.0
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/CHANGELOG.md +386 -0
- package/README.md +45 -12
- package/dist/{WrittenResponse-BfpzfLlR.d.cts → WrittenResponse-BJL4dGsR.d.ts} +6 -2
- package/dist/{WrittenResponse-C3GIWErG.d.ts → WrittenResponse-zWT-Go1g.d.cts} +6 -2
- package/dist/{chunk-E4MNA2IQ.js → chunk-2TW6WLBC.js} +3 -2
- package/dist/chunk-2TW6WLBC.js.map +1 -0
- package/dist/chunk-6F4X2NKL.js +1 -0
- package/dist/chunk-6N43WDVG.js +1 -0
- package/dist/chunk-6ZKVJAO6.js +540 -0
- package/dist/chunk-6ZKVJAO6.js.map +1 -0
- package/dist/chunk-A572N5G7.cjs +542 -0
- package/dist/chunk-A572N5G7.cjs.map +1 -0
- package/dist/{chunk-CPF2JJG6.cjs → chunk-AMGK7DDM.cjs} +32 -2
- package/dist/chunk-AMGK7DDM.cjs.map +1 -0
- package/dist/{chunk-UQ3BBEIT.js → chunk-BG456EM3.js} +22 -5
- package/dist/chunk-BG456EM3.js.map +1 -0
- package/dist/{chunk-YXG3UJVG.cjs → chunk-BNESCXJ5.cjs} +17 -4
- package/dist/chunk-BNESCXJ5.cjs.map +1 -0
- package/dist/{chunk-BQHDQ33H.js → chunk-CMZGT26S.js} +22 -4
- package/dist/chunk-CMZGT26S.js.map +1 -0
- package/dist/{chunk-B3FUUKZ2.js → chunk-DQNVAXG6.js} +32 -3
- package/dist/chunk-DQNVAXG6.js.map +1 -0
- package/dist/{chunk-57E3E2H4.js → chunk-J23XVR2B.js} +17 -4
- package/dist/chunk-J23XVR2B.js.map +1 -0
- package/dist/{chunk-PBVMEOWI.cjs → chunk-J4LP4CLY.cjs} +110 -29
- package/dist/chunk-J4LP4CLY.cjs.map +1 -0
- package/dist/{chunk-NEWGUDA5.cjs → chunk-KK4WGW2V.cjs} +22 -5
- package/dist/chunk-KK4WGW2V.cjs.map +1 -0
- package/dist/{chunk-R3OZ6JHQ.cjs → chunk-KPI335JJ.cjs} +22 -4
- package/dist/chunk-KPI335JJ.cjs.map +1 -0
- package/dist/{chunk-5TUTJ4R3.js → chunk-MB532SXM.js} +17 -4
- package/dist/chunk-MB532SXM.js.map +1 -0
- package/dist/chunk-PGEG7UZJ.cjs +1 -0
- package/dist/{chunk-IYLQSNLE.cjs → chunk-PNNUPUH4.cjs} +3 -2
- package/dist/chunk-PNNUPUH4.cjs.map +1 -0
- package/dist/{chunk-NPY2F7F6.cjs → chunk-VXOOGQ6W.cjs} +17 -4
- package/dist/chunk-VXOOGQ6W.cjs.map +1 -0
- package/dist/chunk-XOR4MPEN.cjs +1 -0
- package/dist/{chunk-OQGBAQL2.js → chunk-ZPVMB3LH.js} +108 -27
- package/dist/chunk-ZPVMB3LH.js.map +1 -0
- package/dist/components/ActivitySequence.cjs +8 -7
- package/dist/components/ActivitySequence.d.cts +29 -23
- package/dist/components/ActivitySequence.d.ts +29 -23
- package/dist/components/ActivitySequence.js +7 -6
- package/dist/components/FillInTheBlanks.cjs +4 -3
- package/dist/components/FillInTheBlanks.d.cts +1 -1
- package/dist/components/FillInTheBlanks.d.ts +1 -1
- package/dist/components/FillInTheBlanks.js +3 -2
- package/dist/components/MultipleChoice.cjs +4 -3
- package/dist/components/MultipleChoice.d.cts +2 -2
- package/dist/components/MultipleChoice.d.ts +2 -2
- package/dist/components/MultipleChoice.js +3 -2
- package/dist/components/StimulusPanel.cjs +4 -3
- package/dist/components/StimulusPanel.d.cts +19 -3
- package/dist/components/StimulusPanel.d.ts +19 -3
- package/dist/components/StimulusPanel.js +3 -2
- package/dist/components/WrittenResponse.cjs +4 -3
- package/dist/components/WrittenResponse.d.cts +3 -3
- package/dist/components/WrittenResponse.d.ts +3 -3
- package/dist/components/WrittenResponse.js +3 -2
- package/dist/hooks/useActivityState.cjs +1 -0
- package/dist/hooks/useActivityState.js +1 -0
- package/dist/hooks/useXAPI.cjs +3 -2
- package/dist/hooks/useXAPI.d.cts +31 -0
- package/dist/hooks/useXAPI.d.ts +31 -0
- package/dist/hooks/useXAPI.js +2 -1
- package/dist/index.cjs +23 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +9 -8
- package/dist/index.js.map +1 -1
- package/dist/theme/ThemeProvider.cjs +10 -5
- package/dist/theme/ThemeProvider.d.cts +21 -1
- package/dist/theme/ThemeProvider.d.ts +21 -1
- package/dist/theme/ThemeProvider.js +2 -1
- package/dist/theme/skin.css +211 -8
- package/dist/types-eXX4hzSj.d.cts +307 -0
- package/dist/types-eXX4hzSj.d.ts +307 -0
- package/package.json +28 -5
- package/dist/chunk-4HZ7LQIH.cjs +0 -40
- package/dist/chunk-4HZ7LQIH.cjs.map +0 -1
- package/dist/chunk-57E3E2H4.js.map +0 -1
- package/dist/chunk-5TUTJ4R3.js.map +0 -1
- package/dist/chunk-B3FUUKZ2.js.map +0 -1
- package/dist/chunk-BQHDQ33H.js.map +0 -1
- package/dist/chunk-CPF2JJG6.cjs.map +0 -1
- package/dist/chunk-E4MNA2IQ.js.map +0 -1
- package/dist/chunk-GB5URWM4.js +0 -38
- package/dist/chunk-GB5URWM4.js.map +0 -1
- package/dist/chunk-IYLQSNLE.cjs.map +0 -1
- package/dist/chunk-NEWGUDA5.cjs.map +0 -1
- package/dist/chunk-NPY2F7F6.cjs.map +0 -1
- package/dist/chunk-OQGBAQL2.js.map +0 -1
- package/dist/chunk-PBVMEOWI.cjs.map +0 -1
- package/dist/chunk-R3OZ6JHQ.cjs.map +0 -1
- package/dist/chunk-UQ3BBEIT.js.map +0 -1
- package/dist/chunk-YXG3UJVG.cjs.map +0 -1
- package/dist/types-DlHmPLbD.d.cts +0 -165
- package/dist/types-DlHmPLbD.d.ts +0 -165
package/dist/theme/skin.css
CHANGED
|
@@ -174,7 +174,7 @@
|
|
|
174
174
|
transition: var(--lk-transition-fast);
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
.lk-mc-option:hover {
|
|
177
|
+
.lk-mc-option:not([data-correct]):hover {
|
|
178
178
|
border-color: var(--lk-color-primary);
|
|
179
179
|
background: var(--lk-color-surface-raised);
|
|
180
180
|
}
|
|
@@ -188,14 +188,68 @@
|
|
|
188
188
|
cursor: default;
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
.lk-mc-option > span:first-of-type {
|
|
192
|
+
flex: 1 1 0%;
|
|
193
|
+
min-inline-size: 12ch;
|
|
194
|
+
overflow-wrap: anywhere;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/* -- Post-submit marking ---------------------------------------------
|
|
198
|
+
Hue says correctness; weight says whether the LEARNER chose it. Both
|
|
199
|
+
correct states are green, because it is the same fact, but only the
|
|
200
|
+
chosen one is filled, so "you got it" and "the key was here" cannot be
|
|
201
|
+
confused. The glyphs exist for WCAG 1.4.1: colour must not be the only
|
|
202
|
+
carrier, and the component emits no correctness text of its own. They
|
|
203
|
+
are declared decorative (the `/ ""` alt text) because the translatable
|
|
204
|
+
announcement belongs to the component, not to a stylesheet that would
|
|
205
|
+
bake English into every locale. */
|
|
206
|
+
|
|
207
|
+
/* The answer was here and the learner did not pick it: outlined, not filled. */
|
|
191
208
|
.lk-mc-option[data-correct="true"] {
|
|
192
209
|
border-color: var(--lk-color-success);
|
|
210
|
+
border-style: dashed;
|
|
211
|
+
box-shadow: none;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.lk-mc-option[data-correct="true"]::after {
|
|
215
|
+
content: "○" / "";
|
|
216
|
+
margin-inline-start: auto;
|
|
217
|
+
font-weight: var(--lk-font-weight-bold);
|
|
218
|
+
color: var(--lk-color-success);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/* Chosen AND right: the strongest mark. At (0,3,1) this outranks
|
|
222
|
+
`:has(input:checked)`, which is the whole reason it has to exist. */
|
|
223
|
+
.lk-mc-option[data-correct="true"]:has(input:checked) {
|
|
224
|
+
border-color: var(--lk-color-success);
|
|
225
|
+
border-style: solid;
|
|
193
226
|
box-shadow: inset 0 0 0 1px var(--lk-color-success);
|
|
227
|
+
background: color-mix(in srgb, var(--lk-color-success) 10%, var(--lk-color-surface));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
.lk-mc-option[data-correct="true"]:has(input:checked)::after {
|
|
231
|
+
content: "✓" / "";
|
|
194
232
|
}
|
|
195
233
|
|
|
234
|
+
/* Chosen and wrong. */
|
|
196
235
|
.lk-mc-option[data-correct="false"]:has(input:checked) {
|
|
197
236
|
border-color: var(--lk-color-error);
|
|
198
237
|
box-shadow: inset 0 0 0 1px var(--lk-color-error);
|
|
238
|
+
background: color-mix(in srgb, var(--lk-color-error) 8%, var(--lk-color-surface));
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
.lk-mc-option[data-correct="false"]:has(input:checked)::after {
|
|
242
|
+
content: "✗" / "";
|
|
243
|
+
margin-inline-start: auto;
|
|
244
|
+
font-weight: var(--lk-font-weight-bold);
|
|
245
|
+
color: var(--lk-color-error);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/* A distractor nobody picked recedes so the three marks carry the eye.
|
|
249
|
+
0.7 keeps the default text at 6.6:1 on the default surface (AA);
|
|
250
|
+
0.55 would drop it to 3.9:1 and fail. */
|
|
251
|
+
.lk-mc-option[data-correct="false"]:not(:has(input:checked)) {
|
|
252
|
+
opacity: 0.7;
|
|
199
253
|
}
|
|
200
254
|
|
|
201
255
|
.lk-mc-option input {
|
|
@@ -409,7 +463,7 @@
|
|
|
409
463
|
.lk-wr-prompt {
|
|
410
464
|
margin: 0;
|
|
411
465
|
color: var(--lk-color-text);
|
|
412
|
-
font-family: var(--lk-font-family);
|
|
466
|
+
font-family: var(--lk-font-family-base);
|
|
413
467
|
font-size: var(--lk-font-size-base);
|
|
414
468
|
line-height: 1.6;
|
|
415
469
|
}
|
|
@@ -418,10 +472,10 @@
|
|
|
418
472
|
width: 100%;
|
|
419
473
|
padding: var(--lk-spacing-sm) var(--lk-spacing-md);
|
|
420
474
|
border: 1px solid var(--lk-color-border);
|
|
421
|
-
border-radius: var(--lk-
|
|
475
|
+
border-radius: var(--lk-radius-base);
|
|
422
476
|
background: var(--lk-color-surface);
|
|
423
477
|
color: var(--lk-color-text);
|
|
424
|
-
font-family: var(--lk-font-family);
|
|
478
|
+
font-family: var(--lk-font-family-base);
|
|
425
479
|
font-size: var(--lk-font-size-base);
|
|
426
480
|
line-height: 1.5;
|
|
427
481
|
resize: vertical;
|
|
@@ -445,10 +499,10 @@
|
|
|
445
499
|
align-self: flex-start;
|
|
446
500
|
padding: var(--lk-spacing-sm) var(--lk-spacing-lg);
|
|
447
501
|
border: none;
|
|
448
|
-
border-radius: var(--lk-
|
|
502
|
+
border-radius: var(--lk-radius-base);
|
|
449
503
|
background: var(--lk-color-primary);
|
|
450
|
-
color: var(--lk-color-
|
|
451
|
-
font-family: var(--lk-font-family);
|
|
504
|
+
color: var(--lk-color-surface);
|
|
505
|
+
font-family: var(--lk-font-family-base);
|
|
452
506
|
font-size: var(--lk-font-size-base);
|
|
453
507
|
cursor: pointer;
|
|
454
508
|
transition: var(--lk-transition-fast);
|
|
@@ -493,7 +547,7 @@
|
|
|
493
547
|
gap: var(--lk-spacing-sm);
|
|
494
548
|
padding: var(--lk-spacing-md);
|
|
495
549
|
border: 1px solid var(--lk-color-border);
|
|
496
|
-
border-radius: var(--lk-
|
|
550
|
+
border-radius: var(--lk-radius-base);
|
|
497
551
|
background: var(--lk-color-surface);
|
|
498
552
|
}
|
|
499
553
|
|
|
@@ -559,3 +613,152 @@
|
|
|
559
613
|
color: var(--lk-color-warning);
|
|
560
614
|
}
|
|
561
615
|
}
|
|
616
|
+
|
|
617
|
+
/*
|
|
618
|
+
* The SDK's own audio transport, rendered whenever a playback policy has
|
|
619
|
+
* something to enforce. It replaces the browser's control bar, so it has to be
|
|
620
|
+
* at least as operable: 44px targets (WCAG 2.5.8), visible focus, and controls
|
|
621
|
+
* that never disappear just because a budget is spent.
|
|
622
|
+
*/
|
|
623
|
+
@layer lk-skin {
|
|
624
|
+
.lk-media[data-controls="minimal"] {
|
|
625
|
+
margin: 0 0 var(--lk-spacing-md);
|
|
626
|
+
padding: var(--lk-spacing-sm) var(--lk-spacing-md);
|
|
627
|
+
background: var(--lk-color-surface-raised);
|
|
628
|
+
border: 1px solid var(--lk-color-border);
|
|
629
|
+
border-radius: var(--lk-radius-base);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
.lk-media-transport {
|
|
633
|
+
display: flex;
|
|
634
|
+
flex-wrap: wrap;
|
|
635
|
+
align-items: center;
|
|
636
|
+
gap: var(--lk-spacing-sm);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
.lk-media-play,
|
|
640
|
+
.lk-media-mute {
|
|
641
|
+
min-block-size: 44px;
|
|
642
|
+
min-inline-size: 44px;
|
|
643
|
+
padding: var(--lk-spacing-xs) var(--lk-spacing-md);
|
|
644
|
+
font: inherit;
|
|
645
|
+
font-weight: var(--lk-font-weight-bold);
|
|
646
|
+
color: var(--lk-color-surface);
|
|
647
|
+
background: var(--lk-color-primary);
|
|
648
|
+
border: 0;
|
|
649
|
+
border-radius: var(--lk-radius-base);
|
|
650
|
+
cursor: pointer;
|
|
651
|
+
transition: var(--lk-transition-fast);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
.lk-media-mute {
|
|
655
|
+
color: var(--lk-color-text);
|
|
656
|
+
background: transparent;
|
|
657
|
+
border: 1px solid var(--lk-color-border);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
.lk-media-play:hover {
|
|
661
|
+
background: var(--lk-color-primary-hover);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/*
|
|
665
|
+
* `aria-disabled`, never `disabled`: the button stays focusable so a learner
|
|
666
|
+
* who tabs to it is told why it will not start, and pressing it re-announces
|
|
667
|
+
* the refusal. Styled as unavailable without leaving the focus order.
|
|
668
|
+
*/
|
|
669
|
+
.lk-media-play[aria-disabled="true"] {
|
|
670
|
+
background: var(--lk-color-text-muted);
|
|
671
|
+
cursor: not-allowed;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
.lk-media-play:focus-visible,
|
|
675
|
+
.lk-media-mute:focus-visible,
|
|
676
|
+
.lk-media-scrub:focus-visible,
|
|
677
|
+
.lk-media-volume:focus-visible,
|
|
678
|
+
.lk-media-rate:focus-visible {
|
|
679
|
+
outline: 2px solid var(--lk-color-focus-ring);
|
|
680
|
+
outline-offset: 2px;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
.lk-media-time {
|
|
684
|
+
font-size: var(--lk-font-size-sm);
|
|
685
|
+
font-variant-numeric: tabular-nums;
|
|
686
|
+
color: var(--lk-color-text-muted);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
.lk-media-scrub {
|
|
690
|
+
flex: 1 1 8rem;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
.lk-media-volume {
|
|
694
|
+
inline-size: 6rem;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
.lk-media-rate {
|
|
698
|
+
min-block-size: 44px;
|
|
699
|
+
padding: var(--lk-spacing-xs);
|
|
700
|
+
font: inherit;
|
|
701
|
+
color: var(--lk-color-text);
|
|
702
|
+
background: var(--lk-color-surface);
|
|
703
|
+
border: 1px solid var(--lk-color-border);
|
|
704
|
+
border-radius: var(--lk-radius-sm);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
.lk-media-plays {
|
|
708
|
+
margin: var(--lk-spacing-xs) 0 0;
|
|
709
|
+
font-size: var(--lk-font-size-sm);
|
|
710
|
+
color: var(--lk-color-text-muted);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/* A refusal is the highest-stakes text on a listening paper. */
|
|
714
|
+
.lk-media-notice:not(:empty) {
|
|
715
|
+
margin: var(--lk-spacing-xs) 0 0;
|
|
716
|
+
font-size: var(--lk-font-size-sm);
|
|
717
|
+
color: var(--lk-color-warning);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
.lk-media-confirm {
|
|
721
|
+
display: flex;
|
|
722
|
+
flex-wrap: wrap;
|
|
723
|
+
align-items: center;
|
|
724
|
+
gap: var(--lk-spacing-sm);
|
|
725
|
+
margin: var(--lk-spacing-sm) 0 0;
|
|
726
|
+
padding: var(--lk-spacing-sm);
|
|
727
|
+
border: 1px solid var(--lk-color-border);
|
|
728
|
+
border-radius: var(--lk-radius-base);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
.lk-media-confirm legend {
|
|
732
|
+
padding-inline: var(--lk-spacing-xs);
|
|
733
|
+
font-size: var(--lk-font-size-sm);
|
|
734
|
+
color: var(--lk-color-text);
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
.lk-media-confirm-start,
|
|
738
|
+
.lk-media-confirm-cancel {
|
|
739
|
+
min-block-size: 44px;
|
|
740
|
+
padding: var(--lk-spacing-xs) var(--lk-spacing-md);
|
|
741
|
+
font: inherit;
|
|
742
|
+
border-radius: var(--lk-radius-base);
|
|
743
|
+
cursor: pointer;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
.lk-media-confirm-start {
|
|
747
|
+
color: var(--lk-color-surface);
|
|
748
|
+
background: var(--lk-color-primary);
|
|
749
|
+
border: 0;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
.lk-media-confirm-cancel {
|
|
753
|
+
color: var(--lk-color-text);
|
|
754
|
+
background: transparent;
|
|
755
|
+
border: 1px solid var(--lk-color-border);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
@media (prefers-reduced-motion: reduce) {
|
|
759
|
+
.lk-media-play,
|
|
760
|
+
.lk-media-mute {
|
|
761
|
+
transition: none;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { ActivityData, ActivityResult, LearnerResponse, ItemOutcome, MediaPlayLedgerEntry, MediaPlayClaim, MediaPlayGrant, InteractionEvent, ThemeTokens, RedactedActivityData, ItemGroup, SequenceEntry } from '@intellectif/lk-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* How an activity is being presented. This is the single switch that decides
|
|
5
|
+
* whether the component may grade, reveal, or submit — the three things a
|
|
6
|
+
* summative exam must take away from the client.
|
|
7
|
+
*
|
|
8
|
+
* - `practice` (default, and the only behaviour before `renderMode` existed):
|
|
9
|
+
* the component owns the attempt. It
|
|
10
|
+
* scores locally on submit, reveals correctness and feedback, and calls
|
|
11
|
+
* `onComplete` with a full {@link ActivityResult}.
|
|
12
|
+
* - `exam`: the component NEVER scores and NEVER reveals correctness. Submit
|
|
13
|
+
* emits the raw learner response through `onSubmit`; the server grades it.
|
|
14
|
+
* Safe to render redacted data, because nothing here needs the answer key.
|
|
15
|
+
* - `review`: read-only. Renders the learner's submitted answer, and marks
|
|
16
|
+
* correctness only from an `outcome` the caller supplies (which the server
|
|
17
|
+
* computed). Nothing is submittable.
|
|
18
|
+
*/
|
|
19
|
+
type RenderMode = 'practice' | 'exam' | 'review';
|
|
20
|
+
/**
|
|
21
|
+
* Makes the answer-key-bearing parts of an activity optional, so a component
|
|
22
|
+
* can render either full activity data OR a `redact()` projection with the
|
|
23
|
+
* same props. Fields the SDK classifies `answer-key` become optional here;
|
|
24
|
+
* a component in `exam` mode must not read them at all.
|
|
25
|
+
*/
|
|
26
|
+
type Renderable<TData> = Omit<TData, 'scoringStrategy'> & {
|
|
27
|
+
scoringStrategy?: unknown;
|
|
28
|
+
/** Present on a `redact()` projection. */
|
|
29
|
+
redacted?: true;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* {@link Renderable} DISTRIBUTED over a union of activity types.
|
|
33
|
+
*
|
|
34
|
+
* This distinction is load-bearing, not cosmetic. `Renderable<T>` is built on
|
|
35
|
+
* `Omit`, and `Omit` does not distribute: `Omit<A | B, K>` collapses to the
|
|
36
|
+
* keys A and B have IN COMMON, so `Renderable<ActivityData>` is a single
|
|
37
|
+
* object type carrying only the fields every activity shares. Narrowing it
|
|
38
|
+
* dies with it — after `if (data.type === 'multiple-choice')` the compiler
|
|
39
|
+
* still refuses `data.options`, because the union it would narrow to no
|
|
40
|
+
* longer exists.
|
|
41
|
+
*
|
|
42
|
+
* The conditional below re-distributes, so `RenderableActivity` is a real
|
|
43
|
+
* union of per-type renderables and `.type` narrows again. Anything that
|
|
44
|
+
* accepts "some renderable activity, I don't know which" — a custom renderer,
|
|
45
|
+
* a sequence entry — must use THIS, not `Renderable<ActivityData>`.
|
|
46
|
+
*/
|
|
47
|
+
type RenderableActivity<TData extends ActivityData = ActivityData> = TData extends unknown ? Renderable<TData> : never;
|
|
48
|
+
/**
|
|
49
|
+
* Sanitiser for author-supplied rich text (`questionHtml`, `promptHtml`, and a
|
|
50
|
+
* stimulus's `bodyHtml`). The SDK deliberately ships NO sanitiser — that would
|
|
51
|
+
* add a dependency and, worse, a false promise. Rich text is rendered only when
|
|
52
|
+
* you supply this function; without it the component falls back to the
|
|
53
|
+
* plain-text field, which is always escaped. Fail-safe by construction: the SDK
|
|
54
|
+
* never injects HTML it was not explicitly given a sanitiser for.
|
|
55
|
+
*
|
|
56
|
+
* `FillInTheBlanks.passageHtml` is the one exception, and is **never**
|
|
57
|
+
* rendered: the passage hosts the answer inputs, so it cannot be split at the
|
|
58
|
+
* `{{blank}}` placeholders without voiding the sanitiser. The plain `passage`
|
|
59
|
+
* is always used, and passing `passageHtml` warns in development.
|
|
60
|
+
*/
|
|
61
|
+
type HtmlSanitizer = (html: string) => string;
|
|
62
|
+
/**
|
|
63
|
+
* The prop contract shared by every activity component (Req 3.1). Defined
|
|
64
|
+
* here (React-specific) rather than in lk-core, which is React-free.
|
|
65
|
+
*
|
|
66
|
+
* Controlled / uncontrolled follows the React convention: pass `value` +
|
|
67
|
+
* `onChange` to own the learner's answer (restore an in-progress attempt,
|
|
68
|
+
* autosave a delta, drive a review); pass `defaultValue` to seed an
|
|
69
|
+
* uncontrolled component; pass neither to keep the pre-2.1.0 behaviour, where
|
|
70
|
+
* the component owns the answer outright.
|
|
71
|
+
*/
|
|
72
|
+
interface ActivityProps<TData extends ActivityData = ActivityData> {
|
|
73
|
+
/** Activity content. Accepts a `redact()` projection in `exam` mode. */
|
|
74
|
+
data: RenderableActivity<TData>;
|
|
75
|
+
/**
|
|
76
|
+
* Called when the component scored the attempt itself. Only ever fires in
|
|
77
|
+
* `practice` mode — in `exam` mode the client does not grade, so there is
|
|
78
|
+
* no `ActivityResult` to give you; use `onSubmit`.
|
|
79
|
+
*/
|
|
80
|
+
onComplete?: (result: ActivityResult) => void;
|
|
81
|
+
/**
|
|
82
|
+
* Called on submit with the raw learner response and no grade. Fires in
|
|
83
|
+
* every mode, before `onComplete`, so an exam runner can persist the
|
|
84
|
+
* response and let the server score it.
|
|
85
|
+
*/
|
|
86
|
+
onSubmit?: (response: LearnerResponse) => void;
|
|
87
|
+
/** Controlled value: the learner's current response. */
|
|
88
|
+
value?: LearnerResponse;
|
|
89
|
+
/** Initial response for an uncontrolled component (ignored when `value` is set). */
|
|
90
|
+
defaultValue?: LearnerResponse;
|
|
91
|
+
/**
|
|
92
|
+
* Mount the component as already submitted — read at mount only, like any
|
|
93
|
+
* `default*` prop.
|
|
94
|
+
*
|
|
95
|
+
* Restoring an attempt without it reopens a question the learner had already
|
|
96
|
+
* submitted as answerable, so on a summative paper they can change and
|
|
97
|
+
* re-submit it. `AttemptState.submittedSlotIds` is what this consumes.
|
|
98
|
+
*/
|
|
99
|
+
defaultSubmitted?: boolean;
|
|
100
|
+
/** Fires on every change to the learner's response. Required for a controlled component. */
|
|
101
|
+
onChange?: (response: LearnerResponse) => void;
|
|
102
|
+
/** Presentation mode. Defaults to `practice`. */
|
|
103
|
+
renderMode?: RenderMode;
|
|
104
|
+
/**
|
|
105
|
+
* Server-computed outcome, used by `review` mode to mark correctness
|
|
106
|
+
* without the client ever scoring. Ignored in other modes.
|
|
107
|
+
*/
|
|
108
|
+
outcome?: ItemOutcome;
|
|
109
|
+
/** Renders author-supplied rich text when provided. See {@link HtmlSanitizer}. */
|
|
110
|
+
sanitizeHtml?: HtmlSanitizer;
|
|
111
|
+
/**
|
|
112
|
+
* Binds this activity's own `data.media` to a play budget the consumer
|
|
113
|
+
* persists. Usually supplied by `<ActivitySequence mediaBudget={…}>`; pass it
|
|
114
|
+
* yourself when rendering an activity standalone.
|
|
115
|
+
*/
|
|
116
|
+
mediaBudget?: MediaBudgetBinding;
|
|
117
|
+
/** Translations for the audio transport chrome. See {@link MediaTransportStrings}. */
|
|
118
|
+
mediaStrings?: Partial<MediaTransportStrings>;
|
|
119
|
+
onInteraction?: (event: InteractionEvent) => void;
|
|
120
|
+
/** Per-instance token overrides, applied as inline CSS vars on the root. */
|
|
121
|
+
theme?: Partial<ThemeTokens>;
|
|
122
|
+
locale?: string;
|
|
123
|
+
disabled?: boolean;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Bridges a server-produced `redact()` projection into the `data` prop.
|
|
127
|
+
*
|
|
128
|
+
* `RedactedActivityData` is deliberately index-signature typed in lk-core — it
|
|
129
|
+
* proves a payload is learner-safe, not what shape it has — so TypeScript
|
|
130
|
+
* cannot know it still carries the public fields a renderer needs. This is the
|
|
131
|
+
* SDK's single, documented crossing of that gap, so an exam runner does not
|
|
132
|
+
* have to write `as unknown as` at every call site:
|
|
133
|
+
*
|
|
134
|
+
* ```tsx
|
|
135
|
+
* <MultipleChoice
|
|
136
|
+
* data={asRenderable<MultipleChoiceData>(redactedFromServer)}
|
|
137
|
+
* renderMode="exam"
|
|
138
|
+
* onSubmit={persist}
|
|
139
|
+
* />
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* Safe because `exam` mode reads only public fields; the answer-key fields the
|
|
143
|
+
* type claims are exactly the ones the component is forbidden to touch there.
|
|
144
|
+
*
|
|
145
|
+
* Per-type redacted interfaces (`RedactedMultipleChoiceData`, …) ship from
|
|
146
|
+
* lk-core since 0.6.0, but they are not yet *assignable* to `data`:
|
|
147
|
+
* {@link Renderable} widens `scoringStrategy` and leaves nested answer-key
|
|
148
|
+
* fields (`options[].isCorrect`, `blanks[].acceptedAnswers`) required, so a
|
|
149
|
+
* real redacted payload still needs this bridge. Closing that gap is tracked
|
|
150
|
+
* in the roadmap.
|
|
151
|
+
*/
|
|
152
|
+
declare function asRenderable<TData extends ActivityData>(redacted: RedactedActivityData): Renderable<TData>;
|
|
153
|
+
/**
|
|
154
|
+
* The same bridge as {@link asRenderable}, for a whole sequence: activities
|
|
155
|
+
* and item groups as a server hands them over, ready for `<ActivitySequence>`.
|
|
156
|
+
*
|
|
157
|
+
* Needed for the same reason and no other. `redactItemGroup` returns
|
|
158
|
+
* `ItemGroup<RedactedActivityData>`, and `RedactedActivityData` is an
|
|
159
|
+
* index-signature type whose fields are all `unknown` — so its `question` is
|
|
160
|
+
* not a `string` and it satisfies no per-type renderable, however the prop is
|
|
161
|
+
* widened. Widening alone cannot fix this; a crossing point is required, and
|
|
162
|
+
* having exactly one keeps `as unknown as` out of consumer code.
|
|
163
|
+
*
|
|
164
|
+
* ```tsx
|
|
165
|
+
* const entries = await fetchExam(); // redacted, server-side
|
|
166
|
+
* <ActivitySequence
|
|
167
|
+
* activities={asRenderableSequence(entries)}
|
|
168
|
+
* renderMode="exam" // REQUIRED: see below
|
|
169
|
+
* shuffleSeed={attemptId}
|
|
170
|
+
* onSubmit={persist}
|
|
171
|
+
* />
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* Pass `renderMode="exam"` (or `"review"`). Redacted data has no answer key,
|
|
175
|
+
* and the default `practice` mode grades locally — so `<MultipleChoice>` and
|
|
176
|
+
* `<FillInTheBlanks>` throw at render rather than fail at submit time.
|
|
177
|
+
*
|
|
178
|
+
* `<WrittenResponse>` is the exception: it never grades on the client and has
|
|
179
|
+
* no such guard, so a redacted essay renders and stays answerable in
|
|
180
|
+
* `practice`. A mis-wired essay item is therefore SILENT — set `renderMode`
|
|
181
|
+
* explicitly rather than relying on the throw.
|
|
182
|
+
*/
|
|
183
|
+
declare function asRenderableSequence(entries: readonly (RedactedActivityData | RedactedItemGroupData)[]): readonly SequenceEntry<RenderableActivity>[];
|
|
184
|
+
/** Structural shape of a `redactItemGroup()` projection, as it arrives from a server. */
|
|
185
|
+
type RedactedItemGroupData = ItemGroup<RedactedActivityData> & {
|
|
186
|
+
redacted: true;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Every English string the SDK's audio transport renders.
|
|
190
|
+
*
|
|
191
|
+
* Supply them to translate it. These are the highest-stakes strings on a
|
|
192
|
+
* listening paper — "No plays remaining" decides whether a learner believes
|
|
193
|
+
* they may try again — so shipping them as untranslatable English inside a
|
|
194
|
+
* Spanish panel was not acceptable. Supplying any of them also sets `lang` on
|
|
195
|
+
* the transport chrome, so a screen reader does not read the SDK's own words
|
|
196
|
+
* with the passage's phonetics.
|
|
197
|
+
*/
|
|
198
|
+
interface MediaTransportStrings {
|
|
199
|
+
play: string;
|
|
200
|
+
pause: string;
|
|
201
|
+
preparing: string;
|
|
202
|
+
mute: string;
|
|
203
|
+
unmute: string;
|
|
204
|
+
volume: string;
|
|
205
|
+
speed: string;
|
|
206
|
+
seek: string;
|
|
207
|
+
/** e.g. `(1, 2) => '1 of 2 plays remaining'`. */
|
|
208
|
+
playsRemaining: (remaining: number, max: number) => string;
|
|
209
|
+
noPlaysRemaining: string;
|
|
210
|
+
/** Shown before the LAST play is spent, so a stray press cannot cost it. */
|
|
211
|
+
lastPlayConfirm: string;
|
|
212
|
+
lastPlayStart: string;
|
|
213
|
+
lastPlayCancel: string;
|
|
214
|
+
seekBlocked: string;
|
|
215
|
+
rateBlocked: string;
|
|
216
|
+
playFailed: string;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Binds ONE media block to a play budget the consumer persists.
|
|
220
|
+
*
|
|
221
|
+
* The SDK refuses a play; it does not remember one. Everything durable here is
|
|
222
|
+
* the consuming application's — see {@link SequenceMediaBudget.onPlayConsumed}.
|
|
223
|
+
*/
|
|
224
|
+
interface MediaBudgetBinding {
|
|
225
|
+
/** From `slotMediaKey(slotId)` / `stimulusMediaKey(slotId)` in lk-core. */
|
|
226
|
+
key: string;
|
|
227
|
+
/** Plays already spent, and where playback stood. Read at mount only. */
|
|
228
|
+
entry?: MediaPlayLedgerEntry;
|
|
229
|
+
/** Defaults to `renderMode !== 'review'`. An explicit boolean wins either way. */
|
|
230
|
+
enforced?: boolean;
|
|
231
|
+
/** Slot context stamped onto the claim and the interaction event. */
|
|
232
|
+
slotId: string;
|
|
233
|
+
index: number;
|
|
234
|
+
activityId?: string;
|
|
235
|
+
onPlayConsumed?: (claim: MediaPlayClaim) => undefined | Promise<MediaPlayGrant | undefined>;
|
|
236
|
+
onPlayRefunded?: (claim: MediaPlayClaim) => void;
|
|
237
|
+
onPosition?: (key: string, seconds: number) => void;
|
|
238
|
+
/** Translations for the transport chrome. */
|
|
239
|
+
strings?: Partial<MediaTransportStrings>;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* The pager-level half of a play budget. One prop, because it is one concept.
|
|
243
|
+
*/
|
|
244
|
+
interface SequenceMediaBudget {
|
|
245
|
+
/**
|
|
246
|
+
* `MediaPlayLedger.entries` goes straight in. An absent key means nothing
|
|
247
|
+
* spent. Read at mount, like `responses`.
|
|
248
|
+
*/
|
|
249
|
+
plays?: Readonly<Record<string, MediaPlayLedgerEntry>>;
|
|
250
|
+
/**
|
|
251
|
+
* Re-seed token. Change this string and the budgets re-seed from `plays`
|
|
252
|
+
* WITHOUT remounting the pager — the invigilator path ("the audio never
|
|
253
|
+
* started, give her the play back") that would otherwise cost the learner
|
|
254
|
+
* their focus, their scroll position and an unsaved answer.
|
|
255
|
+
*/
|
|
256
|
+
resumeKey?: string;
|
|
257
|
+
/** Explicit override of the default (`renderMode !== 'review'`). */
|
|
258
|
+
enforced?: boolean;
|
|
259
|
+
/**
|
|
260
|
+
* Called the instant a play is claimed, BEFORE any audio is audible.
|
|
261
|
+
*
|
|
262
|
+
* Two tiers, chosen by what you return:
|
|
263
|
+
*
|
|
264
|
+
* - **Return nothing (optimistic).** Playback starts immediately and the
|
|
265
|
+
* count is only as durable as your write. **Do not debounce this, and do
|
|
266
|
+
* not batch it with the answer autosave** — an eight-second debounce is
|
|
267
|
+
* exactly long enough to start a third play and hard-reload. A `pagehide`
|
|
268
|
+
* beacon is a backstop, not the mechanism. A crash between this call and
|
|
269
|
+
* your write landing RETURNS the play to the learner; that is the honest
|
|
270
|
+
* description of what you are buying.
|
|
271
|
+
* - **Return a promise (confirmed).** Playback is held — the button reads
|
|
272
|
+
* "Preparing…" and is `aria-busy` — until it settles. Resolve with
|
|
273
|
+
* `{ playsUsed }` from an ATOMIC server write (`UPDATE … SET plays = plays
|
|
274
|
+
* + 1 … RETURNING plays`, or a compare-and-set on
|
|
275
|
+
* `claim.previousPlaysUsed`). A resolved count above `maxPlays` refuses the
|
|
276
|
+
* play, which is how a second tab is caught: two mounts both seeded at 0
|
|
277
|
+
* both claim 1, and only an atomic increment can tell them apart. A
|
|
278
|
+
* rejection charges nothing and lets the learner retry. This is the only
|
|
279
|
+
* tier in which "consumed before audible" is true of storage rather than
|
|
280
|
+
* only of memory; use it for summative papers.
|
|
281
|
+
*
|
|
282
|
+
* Never settle the promise and the learner cannot play at all: settle it.
|
|
283
|
+
*/
|
|
284
|
+
onPlayConsumed?: (claim: MediaPlayClaim) => undefined | Promise<MediaPlayGrant | undefined>;
|
|
285
|
+
/**
|
|
286
|
+
* Called when a charged play produced no audio — the element errored before
|
|
287
|
+
* playback advanced past 0.25 s, an expired signed URL being the realistic
|
|
288
|
+
* cause. Supply it to give the play back, decrementing with a compare-and-set
|
|
289
|
+
* on `claim.playsUsed`. Omit it and the play stays spent: the SDK will not
|
|
290
|
+
* decrement a ledger it has no channel to correct.
|
|
291
|
+
*/
|
|
292
|
+
onPlayRefunded?: (claim: MediaPlayClaim) => void;
|
|
293
|
+
/**
|
|
294
|
+
* Position reports, so a refresh resumes the play the learner already paid
|
|
295
|
+
* for instead of charging them again. Fires on pause, on end (with 0), and at
|
|
296
|
+
* most once per whole second of playback.
|
|
297
|
+
*
|
|
298
|
+
* **This one you MAY throttle** — the granularity you persist is the
|
|
299
|
+
* granularity of the replay a crash grants. Three seconds is sane; three
|
|
300
|
+
* minutes is not.
|
|
301
|
+
*/
|
|
302
|
+
onPosition?: (key: string, seconds: number) => void;
|
|
303
|
+
/** Translations for the transport chrome. Defaults are English. */
|
|
304
|
+
strings?: Partial<MediaTransportStrings>;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export { type ActivityProps as A, type HtmlSanitizer as H, type MediaBudgetBinding as M, type RenderMode as R, type SequenceMediaBudget as S, type MediaTransportStrings as a, type Renderable as b, type RenderableActivity as c, asRenderable as d, asRenderableSequence as e };
|