@citolab/qti-components 7.14.2 → 7.14.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.
Files changed (30) hide show
  1. package/cdn/index.global.js +1 -1
  2. package/cdn/index.js +86 -78
  3. package/custom-elements.json +417 -1
  4. package/dist/chunks/{chunk-YD7FVKDP.js → chunk-AGV5GOTF.js} +3 -5
  5. package/dist/chunks/chunk-AGV5GOTF.js.map +1 -0
  6. package/dist/chunks/{chunk-2X2C5WI5.js → chunk-C4ELTNV7.js} +92 -33
  7. package/dist/chunks/chunk-C4ELTNV7.js.map +1 -0
  8. package/dist/chunks/{chunk-7567ZPN6.js → chunk-DGBI4IU5.js} +2 -2
  9. package/dist/chunks/{chunk-Z2FFXTKX.js → chunk-E4GR4K26.js} +15 -16
  10. package/dist/chunks/{chunk-Z2FFXTKX.js.map → chunk-E4GR4K26.js.map} +1 -1
  11. package/dist/chunks/{chunk-PT5ASWGQ.js → chunk-TN75CWLX.js} +9 -1
  12. package/dist/chunks/{chunk-PT5ASWGQ.js.map → chunk-TN75CWLX.js.map} +1 -1
  13. package/dist/exports/qti-test.d.ts +2 -2
  14. package/dist/index.d.ts +2 -2
  15. package/dist/index.js +30 -28
  16. package/dist/index.js.map +1 -1
  17. package/dist/item.css +8 -0
  18. package/dist/qti-components/index.d.ts +5 -3
  19. package/dist/qti-components/index.js +11 -9
  20. package/dist/qti-components-jsx.d.ts +65 -64
  21. package/dist/qti-item/index.js +2 -2
  22. package/dist/{qti-modal-feedback-PKbhO-3w.d.ts → qti-modal-feedback-Cp3CHVKw.d.ts} +1 -1
  23. package/dist/qti-test/index.d.ts +3 -3
  24. package/dist/qti-test/index.js +7 -7
  25. package/dist/{qti-test-Db7oNIWY.d.ts → qti-test-mmY8zNIj.d.ts} +1 -1
  26. package/dist/vscode.html-custom-data.json +18 -18
  27. package/package.json +10 -10
  28. package/dist/chunks/chunk-2X2C5WI5.js.map +0 -1
  29. package/dist/chunks/chunk-YD7FVKDP.js.map +0 -1
  30. /package/dist/chunks/{chunk-7567ZPN6.js.map → chunk-DGBI4IU5.js.map} +0 -0
@@ -1,36 +1,36 @@
1
1
  import {
2
- Interaction
3
- } from "./chunk-P4QBOVQ2.js";
2
+ QtiFeedback,
3
+ convertNumberToUniversalFormat,
4
+ liveQuery,
5
+ removeDoubleSlashes
6
+ } from "./chunk-AGV5GOTF.js";
4
7
  import {
5
- itemContextVariables
6
- } from "./chunk-JQ6HWGRY.js";
8
+ watch
9
+ } from "./chunk-ELDMXTUQ.js";
10
+ import {
11
+ qtiTransformItem
12
+ } from "./chunk-XBPO6E25.js";
7
13
  import {
8
14
  QtiConditionExpression
9
15
  } from "./chunk-SV4K25ZI.js";
10
16
  import {
11
17
  QtiExpression
12
18
  } from "./chunk-GAAFN7QF.js";
13
- import {
14
- QtiFeedback,
15
- convertNumberToUniversalFormat,
16
- liveQuery,
17
- removeDoubleSlashes
18
- } from "./chunk-YD7FVKDP.js";
19
19
  import {
20
20
  testContext
21
21
  } from "./chunk-CJADUWEC.js";
22
+ import {
23
+ Interaction
24
+ } from "./chunk-P4QBOVQ2.js";
22
25
  import {
23
26
  itemContext
24
27
  } from "./chunk-NJNQOQUU.js";
25
- import {
26
- watch
27
- } from "./chunk-ELDMXTUQ.js";
28
- import {
29
- qtiTransformItem
30
- } from "./chunk-XBPO6E25.js";
31
28
  import {
32
29
  configContext
33
30
  } from "./chunk-BHJSX3Q6.js";
31
+ import {
32
+ itemContextVariables
33
+ } from "./chunk-JQ6HWGRY.js";
34
34
  import {
35
35
  __decorateClass
36
36
  } from "./chunk-H2JE6IVU.js";
@@ -755,6 +755,8 @@ var DragDropInteractionMixin = (superClass, draggablesSelector, droppablesSelect
755
755
  // Minimum pixel movement to start dragging
756
756
  this.DRAG_CLONE_OPACITY = 1;
757
757
  // Opacity of the drag clone element
758
+ this.MAX_DRAGGABLE_WIDTH = 600;
759
+ // Maximum width of a draggable element
758
760
  this.dataTransfer = {
759
761
  data: {},
760
762
  setData(type, val) {
@@ -924,33 +926,50 @@ var DragDropInteractionMixin = (superClass, draggablesSelector, droppablesSelect
924
926
  await this.updateComplete;
925
927
  if (this.isMatchTabular()) return;
926
928
  const draggables = this.querySelectorAll(draggablesSelector);
927
- const droppables = Array.from(this.querySelectorAll(droppablesSelector)).map((d) => d);
928
- let maxHeight = 0;
929
- let maxWidth = 0;
930
- draggables.forEach((draggable) => {
931
- const rect = draggable.getBoundingClientRect();
932
- maxHeight = Math.max(maxHeight, rect.height);
933
- maxWidth = Math.max(maxWidth, rect.width);
934
- });
935
929
  const dragContainer = this.querySelector(dragContainersSelector) || this.shadowRoot?.querySelector(dragContainersSelector);
930
+ const droppables = this.querySelectorAll(droppablesSelector);
936
931
  const dropContainer = droppables[0]?.parentElement;
932
+ const maxWidth = this.determineMaxWidth(dragContainer, dropContainer);
933
+ let maxDraggableHeight = 0;
934
+ let maxDraggableWidth = 0;
935
+ for (const draggable of draggables) {
936
+ draggable.style.maxWidth = maxWidth + "px";
937
+ const { width, height } = await this.measureIntrinsicSize(draggable);
938
+ maxDraggableHeight = Math.max(maxDraggableHeight, height);
939
+ maxDraggableWidth = Math.max(maxDraggableWidth, width);
940
+ }
937
941
  if (dropContainer) {
938
- dropContainer.style.gridTemplateColumns = `repeat(auto-fit, minmax(calc(${maxWidth}px + 2 * var(--qti-dropzone-padding)), 1fr))`;
942
+ dropContainer.style.gridTemplateColumns = `repeat(auto-fit, minmax(calc(min(${maxWidth}px,${maxDraggableWidth}px + 2 * var(--qti-dropzone-padding))), 1fr))`;
939
943
  }
940
944
  if (dragContainer) {
941
- dragContainer.style.minHeight = `${maxHeight}px`;
942
- dragContainer.style.minWidth = `${maxWidth}px`;
945
+ dragContainer.style.minHeight = `${maxDraggableHeight}px`;
943
946
  }
944
947
  for (const droppable of droppables) {
945
- droppable.style.minHeight = `${maxHeight}px`;
946
- droppable.style.minWidth = `${maxWidth}px`;
948
+ droppable.style.minHeight = `${maxDraggableHeight}px`;
949
+ droppable.style.minWidth = `${maxDraggableWidth}px`;
947
950
  const dropSlot = droppable.shadowRoot?.querySelector('slot[part="dropslot"]');
948
951
  if (dropSlot) {
949
- dropSlot.style.minHeight = `${maxHeight}px`;
950
- dropSlot.style.minWidth = `${maxWidth}px`;
952
+ dropSlot.style.minHeight = `${maxDraggableHeight}px`;
951
953
  }
952
954
  }
953
955
  }
956
+ determineMaxWidth(dragContainer, dropContainer) {
957
+ const referenceContainer = dropContainer ?? dragContainer;
958
+ if (!referenceContainer || referenceContainer.clientWidth == 0) {
959
+ return this.MAX_DRAGGABLE_WIDTH;
960
+ }
961
+ const styles = window.getComputedStyle(referenceContainer);
962
+ const paddingLeft = parseFloat(styles.paddingLeft);
963
+ const paddingRight = parseFloat(styles.paddingRight);
964
+ return Math.min(this.MAX_DRAGGABLE_WIDTH, referenceContainer.clientWidth - paddingLeft - paddingRight);
965
+ }
966
+ async measureIntrinsicSize(el) {
967
+ const origPosition = el.style.position;
968
+ el.style.position = "fixed";
969
+ const rect = el.getBoundingClientRect();
970
+ el.style.position = origPosition;
971
+ return { width: rect.width, height: rect.height };
972
+ }
954
973
  activateDroppables(target) {
955
974
  if (this.isMatchTabular()) return;
956
975
  const dragContainers = this.dragContainers;
@@ -1696,7 +1715,7 @@ var ChoicesMixin = (superClass, selector) => {
1696
1715
  this._setChoiceChecked(choice, false);
1697
1716
  }
1698
1717
  });
1699
- } else if (this._configContext?.disableAfterIfMaxChoicesReached) {
1718
+ } else if (this.maxChoices !== 0 && this._configContext?.disableAfterIfMaxChoicesReached) {
1700
1719
  const selectedChoices = this._choiceElements.filter((choice) => this._getChoiceChecked(choice));
1701
1720
  if (selectedChoices.length >= this.maxChoices) {
1702
1721
  this._choiceElements.forEach((choice) => {
@@ -2469,6 +2488,46 @@ var QtiGapMatchInteraction = class extends DragDropInteractionMixin(
2469
2488
  });
2470
2489
  }
2471
2490
  }
2491
+ getMatches(responseVariable) {
2492
+ if (!responseVariable.correctResponse) {
2493
+ return [];
2494
+ }
2495
+ const correctResponse = Array.isArray(responseVariable.correctResponse) ? responseVariable.correctResponse : [responseVariable.correctResponse];
2496
+ const matches = [];
2497
+ if (correctResponse) {
2498
+ correctResponse.forEach((x) => {
2499
+ const split = x.split(" ");
2500
+ matches.push({ source: split[0], target: split[1] });
2501
+ });
2502
+ }
2503
+ return matches;
2504
+ }
2505
+ toggleCandidateCorrection(show) {
2506
+ const responseVariable = this.responseVariable;
2507
+ if (!responseVariable?.correctResponse) {
2508
+ return;
2509
+ }
2510
+ const matches = this.getMatches(responseVariable);
2511
+ const targetChoices = Array.from(this.querySelectorAll("qti-gap"));
2512
+ targetChoices.forEach((targetChoice) => {
2513
+ const targetId = targetChoice.getAttribute("identifier");
2514
+ const targetMatches = matches.filter((m) => m.target === targetId);
2515
+ const selectedChoices = targetChoice.querySelectorAll(`qti-gap-text`);
2516
+ selectedChoices.forEach((selectedChoice) => {
2517
+ selectedChoice.internals.states.delete("candidate-correct");
2518
+ selectedChoice.internals.states.delete("candidate-incorrect");
2519
+ if (!show) {
2520
+ return;
2521
+ }
2522
+ const isCorrect = targetMatches.find((m) => m.source === selectedChoice.identifier)?.source !== void 0;
2523
+ if (isCorrect) {
2524
+ selectedChoice.internals.states.add("candidate-correct");
2525
+ } else {
2526
+ selectedChoice.internals.states.add("candidate-incorrect");
2527
+ }
2528
+ });
2529
+ });
2530
+ }
2472
2531
  };
2473
2532
  QtiGapMatchInteraction.styles = qti_gap_match_interaction_styles_default;
2474
2533
  QtiGapMatchInteraction = __decorateClass([
@@ -8827,4 +8886,4 @@ export {
8827
8886
  QtiOutcomeDeclaration,
8828
8887
  QtiResponseDeclaration
8829
8888
  };
8830
- //# sourceMappingURL=chunk-2X2C5WI5.js.map
8889
+ //# sourceMappingURL=chunk-C4ELTNV7.js.map