@qti-editor/interaction-choice 0.2.1 → 1.1.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.
@@ -1,3 +1,4 @@
1
+ import { createCorrectResponseClickPlugin } from './extensions/correct-response-click.js';
1
2
  export declare const choiceInteractionDescriptor: {
2
3
  tagName: string;
3
4
  nodeTypeName: string;
@@ -5,6 +6,7 @@ export declare const choiceInteractionDescriptor: {
5
6
  name: string;
6
7
  spec: import("prosemirror-model").NodeSpec;
7
8
  }[];
9
+ pluginFactories: (typeof createCorrectResponseClickPlugin)[];
8
10
  insertCommand: import("prosemirror-state").Command;
9
11
  keyboardShortcut: string;
10
12
  enterCommand: import("prosemirror-state").Command;
@@ -1 +1 @@
1
- {"version":3,"file":"descriptor.d.ts","sourceRoot":"","sources":["../src/descriptor.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgBP,CAAC"}
1
+ {"version":3,"file":"descriptor.d.ts","sourceRoot":"","sources":["../src/descriptor.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,gCAAgC,EAAE,MAAM,wCAAwC,CAAC;AAK1F,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiBP,CAAC"}
@@ -3,6 +3,7 @@ import { insertChoiceInteraction, insertSimpleChoiceOnEnter } from './components
3
3
  import { qtiChoiceInteractionNodeSpec } from './components/qti-choice-interaction/qti-choice-interaction.schema.js';
4
4
  import { choiceInteractionComposerMetadata, choiceNodeAttributePanelMetadataByNodeTypeName } from './composer/metadata.js';
5
5
  import { choiceComposerHandler } from './composer/handler.js';
6
+ import { createCorrectResponseClickPlugin } from './extensions/correct-response-click.js';
6
7
  export const choiceInteractionDescriptor = {
7
8
  tagName: 'qti-choice-interaction',
8
9
  nodeTypeName: 'qtiChoiceInteraction',
@@ -13,6 +14,7 @@ export const choiceInteractionDescriptor = {
13
14
  { name: 'qtiSimpleChoice', spec: qtiSimpleChoiceNodeSpec },
14
15
  { name: 'qtiSimpleChoiceParagraph', spec: qtiSimpleChoiceParagraphNodeSpec },
15
16
  ],
17
+ pluginFactories: [createCorrectResponseClickPlugin],
16
18
  insertCommand: insertChoiceInteraction,
17
19
  keyboardShortcut: 'Mod-Shift-q',
18
20
  enterCommand: insertSimpleChoiceOnEnter,
@@ -1,4 +1,5 @@
1
1
  import { type Extension } from 'prosekit/core';
2
+ import { Plugin } from 'prosekit/pm/state';
2
3
  /**
3
4
  * Event name for correct response changes at the interaction level.
4
5
  * Dispatched when selections change to update the ProseMirror document.
@@ -21,4 +22,5 @@ export interface QtiCorrectResponseChangeDetail {
21
22
  * 3. Updates the interaction node's attributes
22
23
  */
23
24
  export declare function defineCorrectResponseClickExtension(): Extension;
25
+ export declare function createCorrectResponseClickPlugin(): Plugin;
24
26
  //# sourceMappingURL=correct-response-click.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"correct-response-click.d.ts","sourceRoot":"","sources":["../../src/extensions/correct-response-click.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAW7D;;;GAGG;AACH,eAAO,MAAM,iCAAiC,gCAAgC,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,kBAAkB,EAAE,WAAW,CAAC;CACjC;AAqDD;;;;;;;GAOG;AACH,wBAAgB,mCAAmC,IAAI,SAAS,CAmD/D"}
1
+ {"version":3,"file":"correct-response-click.d.ts","sourceRoot":"","sources":["../../src/extensions/correct-response-click.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAa,MAAM,mBAAmB,CAAC;AAUtD;;;GAGG;AACH,eAAO,MAAM,iCAAiC,gCAAgC,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,kBAAkB,EAAE,WAAW,CAAC;CACjC;AAqDD;;;;;;;GAOG;AACH,wBAAgB,mCAAmC,IAAI,SAAS,CAE/D;AAED,wBAAgB,gCAAgC,IAAI,MAAM,CAyCzD"}
@@ -60,27 +60,25 @@ function findInteractionNodePos(view, interactionElement) {
60
60
  * 3. Updates the interaction node's attributes
61
61
  */
62
62
  export function defineCorrectResponseClickExtension() {
63
- return definePlugin(() => new Plugin({
63
+ return definePlugin(createCorrectResponseClickPlugin);
64
+ }
65
+ export function createCorrectResponseClickPlugin() {
66
+ return new Plugin({
64
67
  key: correctResponseClickPluginKey,
65
68
  view(view) {
66
69
  const handleToggle = (event) => {
67
70
  const choiceElement = event.target;
68
- // Find the parent interaction
69
71
  const interactionElement = findParentInteraction(choiceElement);
70
72
  if (!interactionElement)
71
73
  return;
72
- // Get all selected identifiers
73
74
  const selectedIdentifiers = getSelectedIdentifiers(interactionElement);
74
- // Compute maxChoices and correctResponse
75
75
  const maxChoices = selectedIdentifiers.length <= 1 ? 1 : 0;
76
76
  const correctResponse = selectedIdentifiers.length > 0
77
77
  ? selectedIdentifiers.join(',')
78
78
  : null;
79
- // Find the node position
80
79
  const pos = findInteractionNodePos(view, interactionElement);
81
80
  if (pos === null)
82
81
  return;
83
- // Update the node attributes
84
82
  const { state, dispatch } = view;
85
83
  const node = state.doc.nodeAt(pos);
86
84
  if (!node)
@@ -92,7 +90,6 @@ export function defineCorrectResponseClickExtension() {
92
90
  };
93
91
  dispatch(state.tr.setNodeMarkup(pos, undefined, nextAttrs));
94
92
  };
95
- // Listen for toggle events on the editor DOM
96
93
  view.dom.addEventListener(QTI_CORRECT_RESPONSE_TOGGLE_EVENT, handleToggle);
97
94
  return {
98
95
  destroy() {
@@ -100,5 +97,5 @@ export function defineCorrectResponseClickExtension() {
100
97
  },
101
98
  };
102
99
  },
103
- }));
100
+ });
104
101
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qti-editor/interaction-choice",
3
3
  "description": "QTI choice interaction schemas, components, commands, and composer",
4
- "version": "0.2.1",
4
+ "version": "1.1.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/Citolab/qti-editor",
@@ -26,8 +26,8 @@
26
26
  "@qti-components/interactions": "^1.10.1",
27
27
  "@qti-components/interactions-core": "^1.1.3",
28
28
  "@qti-components/utilities": "^1.3.2",
29
- "@qti-editor/interaction-shared": "0.2.1",
30
- "@qti-editor/interfaces": "0.3.0"
29
+ "@qti-editor/interaction-shared": "1.1.0",
30
+ "@qti-editor/interfaces": "1.1.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "lit": "^3.3.1"