@citolab/qti-components 7.27.0 → 7.27.2

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.
@@ -644,38 +644,6 @@
644
644
  "description": "",
645
645
  "name": "QtiChoiceInteraction",
646
646
  "members": [
647
- {
648
- "kind": "method",
649
- "name": "_addLabels",
650
- "privacy": "private",
651
- "inheritedFrom": {
652
- "name": "VocabularyMixin",
653
- "module": "packages/interactions/core/src/mixins/vocabulary/vocabulary-mixin.ts"
654
- }
655
- },
656
- {
657
- "kind": "field",
658
- "name": "_allLabels",
659
- "type": {
660
- "text": "array"
661
- },
662
- "privacy": "private",
663
- "default": "['qti-labels-decimal', 'qti-labels-lower-alpha', 'qti-labels-upper-alpha']",
664
- "inheritedFrom": {
665
- "name": "VocabularyMixin",
666
- "module": "packages/interactions/core/src/mixins/vocabulary/vocabulary-mixin.ts"
667
- }
668
- },
669
- {
670
- "kind": "field",
671
- "name": "_allLabelSuffixes",
672
- "privacy": "private",
673
- "default": "['qti-labels-suffix-period', 'qti-labels-suffix-parenthesis']",
674
- "inheritedFrom": {
675
- "name": "VocabularyMixin",
676
- "module": "packages/interactions/core/src/mixins/vocabulary/vocabulary-mixin.ts"
677
- }
678
- },
679
647
  {
680
648
  "kind": "field",
681
649
  "name": "_choiceElements",
@@ -706,19 +674,6 @@
706
674
  "module": "packages/interactions/core/src/mixins/choices/choices.mixin.ts"
707
675
  }
708
676
  },
709
- {
710
- "kind": "field",
711
- "name": "_classes",
712
- "type": {
713
- "text": "string[]"
714
- },
715
- "privacy": "private",
716
- "default": "[]",
717
- "inheritedFrom": {
718
- "name": "VocabularyMixin",
719
- "module": "packages/interactions/core/src/mixins/vocabulary/vocabulary-mixin.ts"
720
- }
721
- },
722
677
  {
723
678
  "kind": "field",
724
679
  "name": "_configContext",
@@ -787,23 +742,6 @@
787
742
  "module": "packages/interactions/core/src/mixins/choices/choices.mixin.ts"
788
743
  }
789
744
  },
790
- {
791
- "kind": "method",
792
- "name": "_getLabel",
793
- "privacy": "private",
794
- "parameters": [
795
- {
796
- "name": "index",
797
- "type": {
798
- "text": "number"
799
- }
800
- }
801
- ],
802
- "inheritedFrom": {
803
- "name": "VocabularyMixin",
804
- "module": "packages/interactions/core/src/mixins/vocabulary/vocabulary-mixin.ts"
805
- }
806
- },
807
745
  {
808
746
  "kind": "method",
809
747
  "name": "_handleChoiceSelection",
@@ -1029,11 +967,206 @@
1029
967
  "module": "packages/interactions/core/src/mixins/choices/choices.mixin.ts"
1030
968
  }
1031
969
  },
970
+ {
971
+ "kind": "field",
972
+ "name": "#allLabels",
973
+ "privacy": "private",
974
+ "type": {
975
+ "text": "LabelType[]"
976
+ },
977
+ "default": "[ 'qti-labels-none', 'qti-labels-decimal', 'qti-labels-lower-alpha', 'qti-labels-upper-alpha', ]",
978
+ "inheritedFrom": {
979
+ "name": "VocabularyMixin",
980
+ "module": "packages/interactions/core/src/mixins/vocabulary/vocabulary-mixin.ts"
981
+ }
982
+ },
983
+ {
984
+ "kind": "field",
985
+ "name": "#allLabelSuffixes",
986
+ "privacy": "private",
987
+ "type": {
988
+ "text": "LabelSuffixType[]"
989
+ },
990
+ "default": "[ 'qti-labels-suffix-none', 'qti-labels-suffix-period', 'qti-labels-suffix-parenthesis', ]",
991
+ "inheritedFrom": {
992
+ "name": "VocabularyMixin",
993
+ "module": "packages/interactions/core/src/mixins/vocabulary/vocabulary-mixin.ts"
994
+ }
995
+ },
996
+ {
997
+ "kind": "field",
998
+ "name": "#classes",
999
+ "privacy": "private",
1000
+ "type": {
1001
+ "text": "string[]"
1002
+ },
1003
+ "default": "[]",
1004
+ "inheritedFrom": {
1005
+ "name": "VocabularyMixin",
1006
+ "module": "packages/interactions/core/src/mixins/vocabulary/vocabulary-mixin.ts"
1007
+ }
1008
+ },
1009
+ {
1010
+ "kind": "method",
1011
+ "name": "#getActiveLabelSuffixType",
1012
+ "privacy": "private",
1013
+ "return": {
1014
+ "type": {
1015
+ "text": "LabelSuffixType | null"
1016
+ }
1017
+ },
1018
+ "inheritedFrom": {
1019
+ "name": "VocabularyMixin",
1020
+ "module": "packages/interactions/core/src/mixins/vocabulary/vocabulary-mixin.ts"
1021
+ }
1022
+ },
1023
+ {
1024
+ "kind": "method",
1025
+ "name": "#getActiveLabelType",
1026
+ "privacy": "private",
1027
+ "return": {
1028
+ "type": {
1029
+ "text": "LabelType | null"
1030
+ }
1031
+ },
1032
+ "inheritedFrom": {
1033
+ "name": "VocabularyMixin",
1034
+ "module": "packages/interactions/core/src/mixins/vocabulary/vocabulary-mixin.ts"
1035
+ }
1036
+ },
1037
+ {
1038
+ "kind": "method",
1039
+ "name": "#getLabel",
1040
+ "privacy": "private",
1041
+ "return": {
1042
+ "type": {
1043
+ "text": "string"
1044
+ }
1045
+ },
1046
+ "parameters": [
1047
+ {
1048
+ "name": "index",
1049
+ "type": {
1050
+ "text": "number"
1051
+ }
1052
+ },
1053
+ {
1054
+ "name": "labelType",
1055
+ "type": {
1056
+ "text": "LabelType | null"
1057
+ }
1058
+ },
1059
+ {
1060
+ "name": "labelSuffixType",
1061
+ "type": {
1062
+ "text": "LabelSuffixType | null"
1063
+ }
1064
+ }
1065
+ ],
1066
+ "inheritedFrom": {
1067
+ "name": "VocabularyMixin",
1068
+ "module": "packages/interactions/core/src/mixins/vocabulary/vocabulary-mixin.ts"
1069
+ }
1070
+ },
1071
+ {
1072
+ "kind": "method",
1073
+ "name": "#getOrderedChoices",
1074
+ "privacy": "private",
1075
+ "return": {
1076
+ "type": {
1077
+ "text": "QtiSimpleChoice[]"
1078
+ }
1079
+ },
1080
+ "parameters": [
1081
+ {
1082
+ "name": "choiceElements",
1083
+ "type": {
1084
+ "text": "QtiSimpleChoice[]"
1085
+ }
1086
+ }
1087
+ ],
1088
+ "inheritedFrom": {
1089
+ "name": "VocabularyMixin",
1090
+ "module": "packages/interactions/core/src/mixins/vocabulary/vocabulary-mixin.ts"
1091
+ }
1092
+ },
1032
1093
  {
1033
1094
  "kind": "method",
1034
1095
  "name": "#handleSlotChange",
1035
1096
  "privacy": "private"
1036
1097
  },
1098
+ {
1099
+ "kind": "field",
1100
+ "name": "#mutationObserver",
1101
+ "privacy": "private",
1102
+ "type": {
1103
+ "text": "MutationObserver | null"
1104
+ },
1105
+ "default": "null",
1106
+ "inheritedFrom": {
1107
+ "name": "VocabularyMixin",
1108
+ "module": "packages/interactions/core/src/mixins/vocabulary/vocabulary-mixin.ts"
1109
+ }
1110
+ },
1111
+ {
1112
+ "kind": "method",
1113
+ "name": "#syncLabels",
1114
+ "privacy": "private",
1115
+ "inheritedFrom": {
1116
+ "name": "VocabularyMixin",
1117
+ "module": "packages/interactions/core/src/mixins/vocabulary/vocabulary-mixin.ts"
1118
+ }
1119
+ },
1120
+ {
1121
+ "kind": "method",
1122
+ "name": "#toAlphabetic",
1123
+ "privacy": "private",
1124
+ "return": {
1125
+ "type": {
1126
+ "text": "string"
1127
+ }
1128
+ },
1129
+ "parameters": [
1130
+ {
1131
+ "name": "index",
1132
+ "type": {
1133
+ "text": "number"
1134
+ }
1135
+ },
1136
+ {
1137
+ "name": "casing",
1138
+ "type": {
1139
+ "text": "'lower' | 'upper'"
1140
+ }
1141
+ }
1142
+ ],
1143
+ "inheritedFrom": {
1144
+ "name": "VocabularyMixin",
1145
+ "module": "packages/interactions/core/src/mixins/vocabulary/vocabulary-mixin.ts"
1146
+ }
1147
+ },
1148
+ {
1149
+ "kind": "method",
1150
+ "name": "#tokenizeClasses",
1151
+ "privacy": "private",
1152
+ "return": {
1153
+ "type": {
1154
+ "text": "string[]"
1155
+ }
1156
+ },
1157
+ "parameters": [
1158
+ {
1159
+ "name": "value",
1160
+ "type": {
1161
+ "text": "string | null | undefined"
1162
+ }
1163
+ }
1164
+ ],
1165
+ "inheritedFrom": {
1166
+ "name": "VocabularyMixin",
1167
+ "module": "packages/interactions/core/src/mixins/vocabulary/vocabulary-mixin.ts"
1168
+ }
1169
+ },
1037
1170
  {
1038
1171
  "kind": "field",
1039
1172
  "name": "class",
@@ -9489,57 +9622,157 @@
9489
9622
  "description": "",
9490
9623
  "name": "VocabularyMixin",
9491
9624
  "members": [
9492
- {
9493
- "kind": "method",
9494
- "name": "_addLabels",
9495
- "privacy": "private"
9496
- },
9497
9625
  {
9498
9626
  "kind": "field",
9499
- "name": "_allLabels",
9627
+ "name": "#allLabels",
9628
+ "privacy": "private",
9500
9629
  "type": {
9501
- "text": "array"
9630
+ "text": "LabelType[]"
9502
9631
  },
9503
- "privacy": "private",
9504
- "default": "['qti-labels-decimal', 'qti-labels-lower-alpha', 'qti-labels-upper-alpha']"
9632
+ "default": "[ 'qti-labels-none', 'qti-labels-decimal', 'qti-labels-lower-alpha', 'qti-labels-upper-alpha', ]"
9505
9633
  },
9506
9634
  {
9507
9635
  "kind": "field",
9508
- "name": "_allLabelSuffixes",
9636
+ "name": "#allLabelSuffixes",
9509
9637
  "privacy": "private",
9510
- "default": "['qti-labels-suffix-period', 'qti-labels-suffix-parenthesis']"
9638
+ "type": {
9639
+ "text": "LabelSuffixType[]"
9640
+ },
9641
+ "default": "[ 'qti-labels-suffix-none', 'qti-labels-suffix-period', 'qti-labels-suffix-parenthesis', ]"
9511
9642
  },
9512
9643
  {
9513
9644
  "kind": "field",
9514
- "name": "_classes",
9645
+ "name": "#classes",
9646
+ "privacy": "private",
9515
9647
  "type": {
9516
9648
  "text": "string[]"
9517
9649
  },
9518
- "privacy": "private",
9519
9650
  "default": "[]"
9520
9651
  },
9521
9652
  {
9522
9653
  "kind": "method",
9523
- "name": "_getLabel",
9654
+ "name": "#getActiveLabelSuffixType",
9655
+ "privacy": "private",
9656
+ "return": {
9657
+ "type": {
9658
+ "text": "LabelSuffixType | null"
9659
+ }
9660
+ }
9661
+ },
9662
+ {
9663
+ "kind": "method",
9664
+ "name": "#getActiveLabelType",
9665
+ "privacy": "private",
9666
+ "return": {
9667
+ "type": {
9668
+ "text": "LabelType | null"
9669
+ }
9670
+ }
9671
+ },
9672
+ {
9673
+ "kind": "method",
9674
+ "name": "#getLabel",
9524
9675
  "privacy": "private",
9676
+ "return": {
9677
+ "type": {
9678
+ "text": "string"
9679
+ }
9680
+ },
9525
9681
  "parameters": [
9526
9682
  {
9527
9683
  "name": "index",
9528
9684
  "type": {
9529
9685
  "text": "number"
9530
9686
  }
9687
+ },
9688
+ {
9689
+ "name": "labelType",
9690
+ "type": {
9691
+ "text": "LabelType | null"
9692
+ }
9693
+ },
9694
+ {
9695
+ "name": "labelSuffixType",
9696
+ "type": {
9697
+ "text": "LabelSuffixType | null"
9698
+ }
9699
+ }
9700
+ ]
9701
+ },
9702
+ {
9703
+ "kind": "method",
9704
+ "name": "#getOrderedChoices",
9705
+ "privacy": "private",
9706
+ "return": {
9707
+ "type": {
9708
+ "text": "QtiSimpleChoice[]"
9709
+ }
9710
+ },
9711
+ "parameters": [
9712
+ {
9713
+ "name": "choiceElements",
9714
+ "type": {
9715
+ "text": "QtiSimpleChoice[]"
9716
+ }
9531
9717
  }
9532
9718
  ]
9533
9719
  },
9534
9720
  {
9535
9721
  "kind": "field",
9536
- "name": "_mutationObserver",
9722
+ "name": "#mutationObserver",
9723
+ "privacy": "private",
9537
9724
  "type": {
9538
9725
  "text": "MutationObserver | null"
9539
9726
  },
9540
- "privacy": "private",
9541
9727
  "default": "null"
9542
9728
  },
9729
+ {
9730
+ "kind": "method",
9731
+ "name": "#syncLabels",
9732
+ "privacy": "private"
9733
+ },
9734
+ {
9735
+ "kind": "method",
9736
+ "name": "#toAlphabetic",
9737
+ "privacy": "private",
9738
+ "return": {
9739
+ "type": {
9740
+ "text": "string"
9741
+ }
9742
+ },
9743
+ "parameters": [
9744
+ {
9745
+ "name": "index",
9746
+ "type": {
9747
+ "text": "number"
9748
+ }
9749
+ },
9750
+ {
9751
+ "name": "casing",
9752
+ "type": {
9753
+ "text": "'lower' | 'upper'"
9754
+ }
9755
+ }
9756
+ ]
9757
+ },
9758
+ {
9759
+ "kind": "method",
9760
+ "name": "#tokenizeClasses",
9761
+ "privacy": "private",
9762
+ "return": {
9763
+ "type": {
9764
+ "text": "string[]"
9765
+ }
9766
+ },
9767
+ "parameters": [
9768
+ {
9769
+ "name": "value",
9770
+ "type": {
9771
+ "text": "string | null | undefined"
9772
+ }
9773
+ }
9774
+ ]
9775
+ },
9543
9776
  {
9544
9777
  "kind": "field",
9545
9778
  "name": "class",
@@ -3749,83 +3749,127 @@ var ChoicesMixin = (superClass, selector) => {
3749
3749
  // ../interactions/core/src/mixins/vocabulary/vocabulary-mixin.ts
3750
3750
  var VocabularyMixin = (superClass, _selector) => {
3751
3751
  class VocabularyElement extends superClass {
3752
- constructor() {
3753
- super(...arguments);
3754
- this._classes = [];
3755
- this._allLabels = ["qti-labels-decimal", "qti-labels-lower-alpha", "qti-labels-upper-alpha"];
3756
- this._allLabelSuffixes = ["qti-labels-suffix-period", "qti-labels-suffix-parenthesis"];
3757
- this._mutationObserver = null;
3758
- }
3752
+ #classes = [];
3753
+ #allLabels = [
3754
+ "qti-labels-none",
3755
+ "qti-labels-decimal",
3756
+ "qti-labels-lower-alpha",
3757
+ "qti-labels-upper-alpha"
3758
+ ];
3759
+ #allLabelSuffixes = [
3760
+ "qti-labels-suffix-none",
3761
+ "qti-labels-suffix-period",
3762
+ "qti-labels-suffix-parenthesis"
3763
+ ];
3764
+ #mutationObserver = null;
3759
3765
  set class(value) {
3760
- if (!value) {
3761
- return;
3762
- }
3763
- this._classes = value.split(" ");
3764
- this._addLabels();
3766
+ this.#classes = this.#tokenizeClasses(value);
3767
+ this.#syncLabels();
3765
3768
  }
3766
3769
  get class() {
3767
- return this._classes?.join(" ") || "";
3770
+ return this.#classes.join(" ");
3771
+ }
3772
+ attributeChangedCallback(name, oldValue, newValue) {
3773
+ super.attributeChangedCallback(name, oldValue, newValue);
3774
+ if (name === "class" && oldValue !== newValue) {
3775
+ this.class = newValue ?? "";
3776
+ }
3768
3777
  }
3769
3778
  updated(_changedProperties) {
3770
3779
  super.updated(_changedProperties);
3771
- this._addLabels();
3780
+ this.#syncLabels();
3772
3781
  }
3773
3782
  connectedCallback() {
3774
3783
  super.connectedCallback();
3775
- this._mutationObserver = new MutationObserver(() => this._addLabels());
3776
- this._mutationObserver.observe(this, { childList: true, subtree: true });
3784
+ this.class = this.getAttribute("class") ?? "";
3785
+ this.#mutationObserver = new MutationObserver((mutations) => {
3786
+ if (mutations.some(
3787
+ (mutation) => mutation.type === "childList" || mutation.type === "attributes" && mutation.attributeName === "style"
3788
+ )) {
3789
+ this.#syncLabels();
3790
+ }
3791
+ });
3792
+ this.#mutationObserver.observe(this, {
3793
+ childList: true,
3794
+ subtree: true,
3795
+ attributes: true,
3796
+ attributeFilter: ["style"]
3797
+ });
3777
3798
  }
3778
3799
  disconnectedCallback() {
3779
3800
  super.disconnectedCallback();
3780
- this._mutationObserver?.disconnect();
3781
- this._mutationObserver = null;
3801
+ this.#mutationObserver?.disconnect();
3802
+ this.#mutationObserver = null;
3803
+ }
3804
+ #tokenizeClasses(value) {
3805
+ if (!value) return [];
3806
+ return value.split(/\s+/).map((token) => token.trim()).filter(Boolean).filter((token, index, tokens) => tokens.indexOf(token) === index);
3807
+ }
3808
+ #syncLabels() {
3809
+ const choiceElements = Array.from(this.querySelectorAll("qti-simple-choice")).map((c3) => c3);
3810
+ const choices = this.#getOrderedChoices(choiceElements);
3811
+ const labelType = this.#getActiveLabelType();
3812
+ const labelSuffixType = this.#getActiveLabelSuffixType();
3813
+ choices.forEach((choice, index) => {
3814
+ choice.marker = this.#getLabel(index + 1, labelType, labelSuffixType);
3815
+ });
3782
3816
  }
3783
- _addLabels() {
3784
- const classContainsLabel = this._classes.some(
3785
- (cls) => this._allLabels.includes(cls) || this._allLabelSuffixes.includes(cls)
3786
- );
3787
- const isNumber = (value) => {
3788
- return !isNaN(+value);
3789
- };
3790
- if (classContainsLabel) {
3791
- const choiceElements = Array.from(this.querySelectorAll("qti-simple-choice")).map((c3) => c3);
3792
- const choices = choiceElements.map((choice, index) => {
3793
- return { el: choice, order: isNumber(choice.style.order) ? +choice.style.order : index + 1 };
3794
- }).sort((a, b) => a.order - b.order).map((choice) => choice.el);
3795
- for (let i5 = 0; i5 < choices.length; i5++) {
3796
- choices[i5].marker = this._getLabel(i5 + 1);
3797
- }
3798
- }
3817
+ #getOrderedChoices(choiceElements) {
3818
+ return choiceElements.map((choice, index) => {
3819
+ const order = Number(choice.style.order);
3820
+ return { el: choice, order: Number.isFinite(order) ? order : index + 1, index };
3821
+ }).sort((a, b) => a.order - b.order || a.index - b.index).map((choice) => choice.el);
3822
+ }
3823
+ #getActiveLabelType() {
3824
+ return this.#classes.filter((c3) => this.#allLabels.includes(c3)).pop() ?? null;
3799
3825
  }
3800
- _getLabel(index) {
3801
- let lastLabel = this._classes.filter((c3) => this._allLabels.includes(c3)).pop();
3802
- const lastLabelSuffix = this._classes.filter((c3) => this._allLabelSuffixes.includes(c3)).pop();
3803
- if (!lastLabel && lastLabelSuffix) {
3804
- lastLabel = "qti-labels-upper-alpha";
3826
+ #getActiveLabelSuffixType() {
3827
+ return this.#classes.filter((c3) => this.#allLabelSuffixes.includes(c3)).pop() ?? null;
3828
+ }
3829
+ #getLabel(index, labelType, labelSuffixType) {
3830
+ let effectiveLabelType = labelType;
3831
+ if (!effectiveLabelType && labelSuffixType && labelSuffixType !== "qti-labels-suffix-none") {
3832
+ effectiveLabelType = "qti-labels-upper-alpha";
3833
+ }
3834
+ if (!effectiveLabelType || effectiveLabelType === "qti-labels-none") {
3835
+ return "";
3805
3836
  }
3806
3837
  let label = "";
3807
- switch (lastLabel) {
3838
+ switch (effectiveLabelType) {
3808
3839
  case "qti-labels-decimal":
3809
3840
  label = `${index}`;
3810
3841
  break;
3811
3842
  case "qti-labels-lower-alpha":
3812
- label = `${String.fromCharCode(97 + index - 1)}`;
3843
+ label = this.#toAlphabetic(index, "lower");
3813
3844
  break;
3814
3845
  case "qti-labels-upper-alpha":
3815
- label = `${String.fromCharCode(65 + index - 1)}`;
3846
+ label = this.#toAlphabetic(index, "upper");
3816
3847
  break;
3817
3848
  }
3818
- if (lastLabelSuffix === "qti-labels-suffix-period") {
3819
- label += ".";
3820
- } else if (lastLabelSuffix === "qti-labels-suffix-parenthesis") {
3821
- label += `)`;
3849
+ if (labelSuffixType === "qti-labels-suffix-period") {
3850
+ return `${label}.`;
3851
+ }
3852
+ if (labelSuffixType === "qti-labels-suffix-parenthesis") {
3853
+ return `${label})`;
3854
+ }
3855
+ return label;
3856
+ }
3857
+ #toAlphabetic(index, casing) {
3858
+ let value = index;
3859
+ let label = "";
3860
+ const charCodeBase = casing === "lower" ? 97 : 65;
3861
+ while (value > 0) {
3862
+ value -= 1;
3863
+ label = String.fromCharCode(charCodeBase + value % 26) + label;
3864
+ value = Math.floor(value / 26);
3822
3865
  }
3823
3866
  return label;
3824
3867
  }
3825
3868
  }
3826
3869
  __decorateClass([
3827
3870
  n({
3828
- type: String
3871
+ type: String,
3872
+ attribute: "class"
3829
3873
  })
3830
3874
  ], VocabularyElement.prototype, "class", 1);
3831
3875
  return VocabularyElement;
@@ -9674,4 +9718,4 @@ lit-html/node/directives/ref.js:
9674
9718
  * SPDX-License-Identifier: BSD-3-Clause
9675
9719
  *)
9676
9720
  */
9677
- //# sourceMappingURL=chunk-XZY2TIZJ.js.map
9721
+ //# sourceMappingURL=chunk-KY3II5OX.js.map