@pie-element/multiple-choice 12.0.0-next.43 → 12.1.0-next.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/configure/lib/defaults.js +3 -0
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/index.js +7 -7
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/main.js +2 -2
- package/configure/lib/main.js.map +1 -1
- package/configure/package.json +7 -7
- package/controller/lib/index.js +5 -5
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/utils.js +2 -3
- package/controller/lib/utils.js.map +1 -1
- package/controller/package.json +3 -3
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/print.js +3 -4
- package/lib/print.js.map +1 -1
- package/module/configure.js +1 -1
- package/module/controller.js +1551 -3664
- package/module/element.js +1 -1
- package/module/index.html +1 -1
- package/module/manifest.json +3 -3
- package/module/print.html +1 -1
- package/module/print.js +1 -1
- package/package.json +11 -8
package/controller/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/multiple-choice-controller",
|
|
3
3
|
"private": true,
|
|
4
|
-
"version": "7.
|
|
4
|
+
"version": "7.1.0-next.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "src/index.js",
|
|
8
8
|
"author": "",
|
|
9
9
|
"license": "ISC",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@pie-lib/controller-utils": "1.1.1-next.
|
|
11
|
+
"@pie-lib/controller-utils": "1.1.1-next.1",
|
|
12
12
|
"debug": "^4.1.1",
|
|
13
|
-
"lodash": "^4.17.23"
|
|
13
|
+
"lodash-es": "^4.17.23"
|
|
14
14
|
}
|
|
15
15
|
}
|
package/lib/index.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.isComplete = exports.default = void 0;
|
|
|
8
8
|
var _main = _interopRequireDefault(require("./main"));
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
10
|
var _client = require("react-dom/client");
|
|
11
|
-
var
|
|
11
|
+
var _lodashEs = require("lodash-es");
|
|
12
12
|
var _debug = _interopRequireDefault(require("debug"));
|
|
13
13
|
var _piePlayerEvents = require("@pie-framework/pie-player-events");
|
|
14
14
|
var _mathRendering = require("@pie-lib/math-rendering");
|
|
@@ -62,7 +62,7 @@ class MultipleChoice extends HTMLElement {
|
|
|
62
62
|
this._keyboardEventsEnabled = false;
|
|
63
63
|
this._audioInitialized = false;
|
|
64
64
|
this._root = null;
|
|
65
|
-
this._rerender = (0,
|
|
65
|
+
this._rerender = (0, _lodashEs.debounce)(() => {
|
|
66
66
|
if (this._model && this._session) {
|
|
67
67
|
var element = /*#__PURE__*/_react.default.createElement(_main.default, {
|
|
68
68
|
model: this._model,
|
|
@@ -94,10 +94,10 @@ class MultipleChoice extends HTMLElement {
|
|
|
94
94
|
leading: false,
|
|
95
95
|
trailing: true
|
|
96
96
|
});
|
|
97
|
-
this._dispatchResponseChanged = (0,
|
|
97
|
+
this._dispatchResponseChanged = (0, _lodashEs.debounce)(() => {
|
|
98
98
|
this.dispatchEvent(new _piePlayerEvents.SessionChangedEvent(this.tagName.toLowerCase(), isComplete(this._session, this._model, this.audioComplete, this)));
|
|
99
99
|
});
|
|
100
|
-
this._dispatchModelSet = (0,
|
|
100
|
+
this._dispatchModelSet = (0, _lodashEs.debounce)(() => {
|
|
101
101
|
this.dispatchEvent(new _piePlayerEvents.ModelSetEvent(this.tagName.toLowerCase(), isComplete(this._session, this._model, this.audioComplete, this), this._model !== undefined));
|
|
102
102
|
}, 50, {
|
|
103
103
|
leading: false,
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_main","_interopRequireDefault","require","_react","_client","_debounce","_debug","_piePlayerEvents","_mathRendering","_renderUi","_sessionUpdater","log","debug","isComplete","session","model","audioComplete","elementContext","autoplayAudioEnabled","completeAudioEnabled","audio","querySelector","isInsidePrompt","closest","value","choiceMode","minSelections","maxSelections","selections","length","exports","MultipleChoice","HTMLElement","constructor","_model","_session","_options","_boundHandleKeyDown","handleKeyDown","bind","_keyboardEventsEnabled","_audioInitialized","_root","_rerender","debounce","element","React","createElement","Main","options","onChoiceChanged","_onChange","onShowCorrectToggle","setAttribute","setLangAttribute","createRoot","render","queueMicrotask","renderMath","keyboardEventsEnabled","enableKeyboardEvents","leading","trailing","_dispatchResponseChanged","dispatchEvent","SessionChangedEvent","tagName","toLowerCase","_dispatchModelSet","ModelSetEvent","undefined","language","lang","slice","s","o","data","updateSessionValue","_createAudioInfoToast","info","document","id","Object","assign","style","position","top","width","height","display","justifyContent","alignItems","background","zIndex","cursor","img","src","EnableAudioAutoplayImage","alt","appendChild","connectedCallback","observer","MutationObserver","mutationsList","forEach","mutation","type","container","enableAudio","play","removeChild","removeEventListener","setTimeout","paused","addEventListener","handlePlaying","updateSessionMetadata","audioStartTime","Date","getTime","handleEnded","audioEndTime","_audio","_handlePlaying","_handleEnded","_enableAudio","disconnect","observe","childList","subtree","window","disconnectedCallback","unmount","event","mode","keyToIndex","key","numOffset","letterOffset","test","charCodeAt","choiceIndex","choices","currentValue","choiceId","newValue","selected","includes","selector","default"],"sources":["../src/index.js"],"sourcesContent":["import Main from './main';\nimport React from 'react';\nimport { createRoot } from 'react-dom/client';\nimport debounce from 'lodash/debounce';\nimport debug from 'debug';\nimport { ModelSetEvent, SessionChangedEvent } from '@pie-framework/pie-player-events';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport { EnableAudioAutoplayImage } from '@pie-lib/render-ui';\nimport { updateSessionValue, updateSessionMetadata } from './session-updater';\n\nconst log = debug('pie-ui:multiple-choice');\n\nexport const isComplete = (session, model, audioComplete, elementContext) => {\n const { autoplayAudioEnabled, completeAudioEnabled } = model || {};\n\n // check audio completion if audio settings are enabled and audio actually exists\n if (autoplayAudioEnabled && completeAudioEnabled && !audioComplete) {\n if (elementContext) {\n const audio = elementContext.querySelector('audio');\n const isInsidePrompt = audio && audio.closest('#preview-prompt');\n\n // only require audio completion if audio exists and is inside the prompt\n if (audio && isInsidePrompt) {\n return false;\n }\n }\n }\n\n if (!session || !session.value) {\n return false;\n }\n\n const { choiceMode, minSelections = 1, maxSelections } = model || {};\n const selections = session.value.length || 0;\n\n if (choiceMode === 'radio') {\n return !!selections;\n }\n\n if (selections < minSelections || selections > maxSelections) {\n return false;\n }\n\n return true;\n};\n\nexport default class MultipleChoice extends HTMLElement {\n constructor() {\n super();\n this._model = null;\n this._session = null;\n this._options = null; // added for ebsr print mode detection\n this.audioComplete = false;\n this._boundHandleKeyDown = this.handleKeyDown.bind(this);\n this._keyboardEventsEnabled = false;\n this._audioInitialized = false;\n this._root = null;\n\n this._rerender = debounce(\n () => {\n if (this._model && this._session) {\n var element = React.createElement(Main, {\n model: this._model,\n session: this._session,\n options: this._options,\n onChoiceChanged: this._onChange.bind(this),\n onShowCorrectToggle: this.onShowCorrectToggle.bind(this),\n });\n\n //TODO: aria-label is set in the _rerender because we need to change it when the model.choiceMode is updated. Consider revisiting the placement of the aria-label setting in the _rerender\n this.setAttribute(\n 'aria-label',\n this._model.choiceMode === 'radio' ? 'Multiple Choice Question' : 'Multiple Correct Answer Question',\n );\n this.setAttribute('role', 'region');\n this.setLangAttribute();\n\n if (!this._root) {\n this._root = createRoot(this);\n }\n this._root.render(element);\n queueMicrotask(() => {\n log('render complete - render math');\n renderMath(this);\n });\n\n if (this._model.keyboardEventsEnabled === true && !this._keyboardEventsEnabled) {\n this.enableKeyboardEvents();\n }\n } else {\n log('skip');\n }\n },\n 50,\n { leading: false, trailing: true },\n );\n\n this._dispatchResponseChanged = debounce(() => {\n this.dispatchEvent(\n new SessionChangedEvent(\n this.tagName.toLowerCase(),\n isComplete(this._session, this._model, this.audioComplete, this),\n ),\n );\n });\n\n this._dispatchModelSet = debounce(\n () => {\n this.dispatchEvent(\n new ModelSetEvent(\n this.tagName.toLowerCase(),\n isComplete(this._session, this._model, this.audioComplete, this),\n this._model !== undefined,\n ),\n );\n },\n 50,\n { leading: false, trailing: true },\n );\n }\n\n onShowCorrectToggle() {\n renderMath(this);\n }\n\n setLangAttribute() {\n const language = this._model && typeof this._model.language ? this._model.language : '';\n const lang = language ? language.slice(0, 2) : 'en';\n this.setAttribute('lang', lang);\n }\n\n set model(s) {\n this._model = s;\n this._rerender();\n // reset the audioInitialized to false since the model changed, and we might need to reinitialize the audio\n this._audioInitialized = false;\n this._dispatchModelSet();\n }\n\n get session() {\n return this._session;\n }\n\n get options() {\n return this._options;\n }\n\n set options(o) {\n this._options = o;\n this._rerender();\n }\n\n set session(s) {\n this._session = s;\n this._rerender();\n //TODO: remove this session-changed should only be emit on user change\n this._dispatchResponseChanged();\n }\n\n _onChange(data) {\n updateSessionValue(this._session, this._model.choiceMode, data);\n this._dispatchResponseChanged();\n this._rerender();\n }\n\n _createAudioInfoToast() {\n const info = document.createElement('div');\n info.id = 'play-audio-info';\n\n Object.assign(info.style, {\n position: 'absolute',\n top: 0,\n width: '100%',\n height: '100%',\n display: 'flex',\n justifyContent: 'center',\n alignItems: 'center',\n background: 'white',\n zIndex: '1000',\n cursor: 'pointer',\n });\n\n const img = document.createElement('img');\n img.src = EnableAudioAutoplayImage;\n img.alt = 'Click anywhere to enable audio autoplay';\n img.width = 500;\n img.height = 300;\n\n info.appendChild(img);\n return info;\n }\n\n connectedCallback() {\n this._rerender();\n\n // Observation: audio in Chrome will have the autoplay attribute,\n // while other browsers will not have the autoplay attribute and will need a user interaction to play the audio\n // This workaround fixes the issue of audio being cached and played on any user interaction in Safari and Firefox\n const observer = new MutationObserver((mutationsList, observer) => {\n mutationsList.forEach((mutation) => {\n if (mutation.type === 'childList') {\n if (this._audioInitialized) return;\n\n const audio = this.querySelector('audio');\n const isInsidePrompt = audio && audio.closest('#preview-prompt');\n\n if (!this._model) return;\n if (!this._model.autoplayAudioEnabled) return;\n if (audio && !isInsidePrompt) return;\n if (!audio) return;\n\n const info = this._createAudioInfoToast();\n const container = this.querySelector('#main-container');\n const enableAudio = () => {\n if (this.querySelector('#play-audio-info')) {\n audio.play();\n container.removeChild(info);\n }\n\n document.removeEventListener('click', enableAudio);\n };\n\n // if the audio is paused, it means the user has not interacted with the page yet and the audio will not play\n // FIX FOR SAFARI: play with a slight delay to check if autoplay was blocked\n setTimeout(() => {\n if (audio.paused && !this.querySelector('#play-audio-info')) {\n // add info message as a toast to enable audio playback\n container.appendChild(info);\n document.addEventListener('click', enableAudio);\n } else {\n document.removeEventListener('click', enableAudio);\n }\n }, 500);\n\n // we need to listen for the playing event to remove the toast in case the audio plays because of re-rendering\n const handlePlaying = () => {\n updateSessionMetadata(this._session, { audioStartTime: new Date().getTime() });\n\n const info = this.querySelector('#play-audio-info');\n if (info) {\n container.removeChild(info);\n }\n\n audio.removeEventListener('playing', handlePlaying);\n };\n\n audio.addEventListener('playing', handlePlaying);\n\n // we need to listen for the ended event to update the isComplete state\n const handleEnded = () => {\n updateSessionMetadata(this._session, { audioEndTime: new Date().getTime() });\n this.audioComplete = true;\n this._dispatchResponseChanged();\n audio.removeEventListener('ended', handleEnded);\n };\n\n audio.addEventListener('ended', handleEnded);\n\n // store references to remove later\n this._audio = audio;\n this._handlePlaying = handlePlaying;\n this._handleEnded = handleEnded;\n this._enableAudio = enableAudio;\n // set to true to prevent multiple initializations\n this._audioInitialized = true;\n\n observer.disconnect();\n }\n });\n });\n\n observer.observe(this, { childList: true, subtree: true });\n }\n\n enableKeyboardEvents() {\n if (!this._keyboardEventsEnabled) {\n window.addEventListener('keydown', this._boundHandleKeyDown);\n this._keyboardEventsEnabled = true;\n }\n }\n\n disconnectedCallback() {\n if (this._keyboardEventsEnabled) {\n window.removeEventListener('keydown', this._boundHandleKeyDown);\n this._keyboardEventsEnabled = false;\n }\n\n document.removeEventListener('click', this._enableAudio);\n\n if (this._audio) {\n this._audio.removeEventListener('playing', this._handlePlaying);\n this._audio.removeEventListener('ended', this._handleEnded);\n this._audio = null;\n }\n\n if (this._root) {\n this._root.unmount();\n }\n }\n\n /**\n * Handles global keyboard events for selecting or toggling multiple-choice answers.\n * Maps keys (1-9, 0, a-j, A-J) to choices and updates the session state accordingly.\n * Ensures valid key presses toggle or select the appropriate choice based on the model.\n */\n handleKeyDown(event) {\n if (!this._model || !this._session) {\n return;\n }\n\n const { mode } = this._model;\n if (mode !== 'gather') {\n return;\n }\n\n const keyToIndex = (key) => {\n const numOffset = key >= '1' && key <= '9' ? key - '1' : key === '0' ? 9 : -1;\n const letterOffset = /^[a-jA-J]$/.test(key) ? key.toLowerCase().charCodeAt(0) - 'a'.charCodeAt(0) : -1;\n return numOffset >= 0 ? numOffset : letterOffset;\n };\n\n const choiceIndex = keyToIndex(event.key);\n\n if (choiceIndex === undefined || choiceIndex <= -1 || choiceIndex >= this._model.choices?.length) {\n return;\n }\n\n const currentValue = this._session.value || [];\n const choiceId = this._model.choices[choiceIndex].value;\n\n const newValue = {\n value: choiceId,\n selected: !currentValue.includes(choiceId),\n selector: 'Keyboard',\n };\n\n this._onChange(newValue);\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,MAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,cAAA,GAAAN,OAAA;AACA,IAAAO,SAAA,GAAAP,OAAA;AACA,IAAAQ,eAAA,GAAAR,OAAA;AAEA,MAAMS,GAAG,GAAG,IAAAC,cAAK,EAAC,wBAAwB,CAAC;AAEpC,MAAMC,UAAU,GAAGA,CAACC,OAAO,EAAEC,KAAK,EAAEC,aAAa,EAAEC,cAAc,KAAK;EAC3E,MAAM;IAAEC,oBAAoB;IAAEC;EAAqB,CAAC,GAAGJ,KAAK,IAAI,CAAC,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E,CAACH,YAAY,CAACI,QAAQ,CAACH,QAAQ,CAAC;MAC1CI,QAAQ,EAAE;IACZ,CAAC;IAED,IAAI,CAACjG,SAAS,CAAC8F,QAAQ,CAAC;EAC1B;AACF;AAACnH,OAAA,CAAAuH,OAAA,GAAAtH,cAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_main","_interopRequireDefault","require","_react","_client","_lodashEs","_debug","_piePlayerEvents","_mathRendering","_renderUi","_sessionUpdater","log","debug","isComplete","session","model","audioComplete","elementContext","autoplayAudioEnabled","completeAudioEnabled","audio","querySelector","isInsidePrompt","closest","value","choiceMode","minSelections","maxSelections","selections","length","exports","MultipleChoice","HTMLElement","constructor","_model","_session","_options","_boundHandleKeyDown","handleKeyDown","bind","_keyboardEventsEnabled","_audioInitialized","_root","_rerender","debounce","element","React","createElement","Main","options","onChoiceChanged","_onChange","onShowCorrectToggle","setAttribute","setLangAttribute","createRoot","render","queueMicrotask","renderMath","keyboardEventsEnabled","enableKeyboardEvents","leading","trailing","_dispatchResponseChanged","dispatchEvent","SessionChangedEvent","tagName","toLowerCase","_dispatchModelSet","ModelSetEvent","undefined","language","lang","slice","s","o","data","updateSessionValue","_createAudioInfoToast","info","document","id","Object","assign","style","position","top","width","height","display","justifyContent","alignItems","background","zIndex","cursor","img","src","EnableAudioAutoplayImage","alt","appendChild","connectedCallback","observer","MutationObserver","mutationsList","forEach","mutation","type","container","enableAudio","play","removeChild","removeEventListener","setTimeout","paused","addEventListener","handlePlaying","updateSessionMetadata","audioStartTime","Date","getTime","handleEnded","audioEndTime","_audio","_handlePlaying","_handleEnded","_enableAudio","disconnect","observe","childList","subtree","window","disconnectedCallback","unmount","event","mode","keyToIndex","key","numOffset","letterOffset","test","charCodeAt","choiceIndex","choices","currentValue","choiceId","newValue","selected","includes","selector","default"],"sources":["../src/index.js"],"sourcesContent":["import Main from './main';\nimport React from 'react';\nimport { createRoot } from 'react-dom/client';\nimport { debounce } from 'lodash-es';\nimport debug from 'debug';\nimport { ModelSetEvent, SessionChangedEvent } from '@pie-framework/pie-player-events';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport { EnableAudioAutoplayImage } from '@pie-lib/render-ui';\nimport { updateSessionValue, updateSessionMetadata } from './session-updater';\n\nconst log = debug('pie-ui:multiple-choice');\n\nexport const isComplete = (session, model, audioComplete, elementContext) => {\n const { autoplayAudioEnabled, completeAudioEnabled } = model || {};\n\n // check audio completion if audio settings are enabled and audio actually exists\n if (autoplayAudioEnabled && completeAudioEnabled && !audioComplete) {\n if (elementContext) {\n const audio = elementContext.querySelector('audio');\n const isInsidePrompt = audio && audio.closest('#preview-prompt');\n\n // only require audio completion if audio exists and is inside the prompt\n if (audio && isInsidePrompt) {\n return false;\n }\n }\n }\n\n if (!session || !session.value) {\n return false;\n }\n\n const { choiceMode, minSelections = 1, maxSelections } = model || {};\n const selections = session.value.length || 0;\n\n if (choiceMode === 'radio') {\n return !!selections;\n }\n\n if (selections < minSelections || selections > maxSelections) {\n return false;\n }\n\n return true;\n};\n\nexport default class MultipleChoice extends HTMLElement {\n constructor() {\n super();\n this._model = null;\n this._session = null;\n this._options = null; // added for ebsr print mode detection\n this.audioComplete = false;\n this._boundHandleKeyDown = this.handleKeyDown.bind(this);\n this._keyboardEventsEnabled = false;\n this._audioInitialized = false;\n this._root = null;\n\n this._rerender = debounce(\n () => {\n if (this._model && this._session) {\n var element = React.createElement(Main, {\n model: this._model,\n session: this._session,\n options: this._options,\n onChoiceChanged: this._onChange.bind(this),\n onShowCorrectToggle: this.onShowCorrectToggle.bind(this),\n });\n\n //TODO: aria-label is set in the _rerender because we need to change it when the model.choiceMode is updated. Consider revisiting the placement of the aria-label setting in the _rerender\n this.setAttribute(\n 'aria-label',\n this._model.choiceMode === 'radio' ? 'Multiple Choice Question' : 'Multiple Correct Answer Question',\n );\n this.setAttribute('role', 'region');\n this.setLangAttribute();\n\n if (!this._root) {\n this._root = createRoot(this);\n }\n this._root.render(element);\n queueMicrotask(() => {\n log('render complete - render math');\n renderMath(this);\n });\n\n if (this._model.keyboardEventsEnabled === true && !this._keyboardEventsEnabled) {\n this.enableKeyboardEvents();\n }\n } else {\n log('skip');\n }\n },\n 50,\n { leading: false, trailing: true },\n );\n\n this._dispatchResponseChanged = debounce(() => {\n this.dispatchEvent(\n new SessionChangedEvent(\n this.tagName.toLowerCase(),\n isComplete(this._session, this._model, this.audioComplete, this),\n ),\n );\n });\n\n this._dispatchModelSet = debounce(\n () => {\n this.dispatchEvent(\n new ModelSetEvent(\n this.tagName.toLowerCase(),\n isComplete(this._session, this._model, this.audioComplete, this),\n this._model !== undefined,\n ),\n );\n },\n 50,\n { leading: false, trailing: true },\n );\n }\n\n onShowCorrectToggle() {\n renderMath(this);\n }\n\n setLangAttribute() {\n const language = this._model && typeof this._model.language ? this._model.language : '';\n const lang = language ? language.slice(0, 2) : 'en';\n this.setAttribute('lang', lang);\n }\n\n set model(s) {\n this._model = s;\n this._rerender();\n // reset the audioInitialized to false since the model changed, and we might need to reinitialize the audio\n this._audioInitialized = false;\n this._dispatchModelSet();\n }\n\n get session() {\n return this._session;\n }\n\n get options() {\n return this._options;\n }\n\n set options(o) {\n this._options = o;\n this._rerender();\n }\n\n set session(s) {\n this._session = s;\n this._rerender();\n //TODO: remove this session-changed should only be emit on user change\n this._dispatchResponseChanged();\n }\n\n _onChange(data) {\n updateSessionValue(this._session, this._model.choiceMode, data);\n this._dispatchResponseChanged();\n this._rerender();\n }\n\n _createAudioInfoToast() {\n const info = document.createElement('div');\n info.id = 'play-audio-info';\n\n Object.assign(info.style, {\n position: 'absolute',\n top: 0,\n width: '100%',\n height: '100%',\n display: 'flex',\n justifyContent: 'center',\n alignItems: 'center',\n background: 'white',\n zIndex: '1000',\n cursor: 'pointer',\n });\n\n const img = document.createElement('img');\n img.src = EnableAudioAutoplayImage;\n img.alt = 'Click anywhere to enable audio autoplay';\n img.width = 500;\n img.height = 300;\n\n info.appendChild(img);\n return info;\n }\n\n connectedCallback() {\n this._rerender();\n\n // Observation: audio in Chrome will have the autoplay attribute,\n // while other browsers will not have the autoplay attribute and will need a user interaction to play the audio\n // This workaround fixes the issue of audio being cached and played on any user interaction in Safari and Firefox\n const observer = new MutationObserver((mutationsList, observer) => {\n mutationsList.forEach((mutation) => {\n if (mutation.type === 'childList') {\n if (this._audioInitialized) return;\n\n const audio = this.querySelector('audio');\n const isInsidePrompt = audio && audio.closest('#preview-prompt');\n\n if (!this._model) return;\n if (!this._model.autoplayAudioEnabled) return;\n if (audio && !isInsidePrompt) return;\n if (!audio) return;\n\n const info = this._createAudioInfoToast();\n const container = this.querySelector('#main-container');\n const enableAudio = () => {\n if (this.querySelector('#play-audio-info')) {\n audio.play();\n container.removeChild(info);\n }\n\n document.removeEventListener('click', enableAudio);\n };\n\n // if the audio is paused, it means the user has not interacted with the page yet and the audio will not play\n // FIX FOR SAFARI: play with a slight delay to check if autoplay was blocked\n setTimeout(() => {\n if (audio.paused && !this.querySelector('#play-audio-info')) {\n // add info message as a toast to enable audio playback\n container.appendChild(info);\n document.addEventListener('click', enableAudio);\n } else {\n document.removeEventListener('click', enableAudio);\n }\n }, 500);\n\n // we need to listen for the playing event to remove the toast in case the audio plays because of re-rendering\n const handlePlaying = () => {\n updateSessionMetadata(this._session, { audioStartTime: new Date().getTime() });\n\n const info = this.querySelector('#play-audio-info');\n if (info) {\n container.removeChild(info);\n }\n\n audio.removeEventListener('playing', handlePlaying);\n };\n\n audio.addEventListener('playing', handlePlaying);\n\n // we need to listen for the ended event to update the isComplete state\n const handleEnded = () => {\n updateSessionMetadata(this._session, { audioEndTime: new Date().getTime() });\n this.audioComplete = true;\n this._dispatchResponseChanged();\n audio.removeEventListener('ended', handleEnded);\n };\n\n audio.addEventListener('ended', handleEnded);\n\n // store references to remove later\n this._audio = audio;\n this._handlePlaying = handlePlaying;\n this._handleEnded = handleEnded;\n this._enableAudio = enableAudio;\n // set to true to prevent multiple initializations\n this._audioInitialized = true;\n\n observer.disconnect();\n }\n });\n });\n\n observer.observe(this, { childList: true, subtree: true });\n }\n\n enableKeyboardEvents() {\n if (!this._keyboardEventsEnabled) {\n window.addEventListener('keydown', this._boundHandleKeyDown);\n this._keyboardEventsEnabled = true;\n }\n }\n\n disconnectedCallback() {\n if (this._keyboardEventsEnabled) {\n window.removeEventListener('keydown', this._boundHandleKeyDown);\n this._keyboardEventsEnabled = false;\n }\n\n document.removeEventListener('click', this._enableAudio);\n\n if (this._audio) {\n this._audio.removeEventListener('playing', this._handlePlaying);\n this._audio.removeEventListener('ended', this._handleEnded);\n this._audio = null;\n }\n\n if (this._root) {\n this._root.unmount();\n }\n }\n\n /**\n * Handles global keyboard events for selecting or toggling multiple-choice answers.\n * Maps keys (1-9, 0, a-j, A-J) to choices and updates the session state accordingly.\n * Ensures valid key presses toggle or select the appropriate choice based on the model.\n */\n handleKeyDown(event) {\n if (!this._model || !this._session) {\n return;\n }\n\n const { mode } = this._model;\n if (mode !== 'gather') {\n return;\n }\n\n const keyToIndex = (key) => {\n const numOffset = key >= '1' && key <= '9' ? key - '1' : key === '0' ? 9 : -1;\n const letterOffset = /^[a-jA-J]$/.test(key) ? key.toLowerCase().charCodeAt(0) - 'a'.charCodeAt(0) : -1;\n return numOffset >= 0 ? numOffset : letterOffset;\n };\n\n const choiceIndex = keyToIndex(event.key);\n\n if (choiceIndex === undefined || choiceIndex <= -1 || choiceIndex >= this._model.choices?.length) {\n return;\n }\n\n const currentValue = this._session.value || [];\n const choiceId = this._model.choices[choiceIndex].value;\n\n const newValue = {\n value: choiceId,\n selected: !currentValue.includes(choiceId),\n selector: 'Keyboard',\n };\n\n this._onChange(newValue);\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,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AI,CAAC,CAAC,IAAIA,WAAW,IAAI,IAAI,CAAC3G,MAAM,CAAC4G,OAAO,EAAEjH,MAAM,EAAE;MAChG;IACF;IAEA,MAAMkH,YAAY,GAAG,IAAI,CAAC5G,QAAQ,CAACX,KAAK,IAAI,EAAE;IAC9C,MAAMwH,QAAQ,GAAG,IAAI,CAAC9G,MAAM,CAAC4G,OAAO,CAACD,WAAW,CAAC,CAACrH,KAAK;IAEvD,MAAMyH,QAAQ,GAAG;MACfzH,KAAK,EAAEwH,QAAQ;MACfE,QAAQ,EAAE,CAACH,YAAY,CAACI,QAAQ,CAACH,QAAQ,CAAC;MAC1CI,QAAQ,EAAE;IACZ,CAAC;IAED,IAAI,CAACjG,SAAS,CAAC8F,QAAQ,CAAC;EAC1B;AACF;AAACnH,OAAA,CAAAuH,OAAA,GAAAtH,cAAA","ignoreList":[]}
|
package/lib/print.js
CHANGED
|
@@ -7,8 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _client = require("react-dom/client");
|
|
10
|
-
var
|
|
11
|
-
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
10
|
+
var _lodashEs = require("lodash-es");
|
|
12
11
|
var _main = _interopRequireDefault(require("./main"));
|
|
13
12
|
var _mathRendering = require("@pie-lib/math-rendering");
|
|
14
13
|
var _debug = _interopRequireDefault(require("debug"));
|
|
@@ -33,7 +32,7 @@ const preparePrintModel = (model, opts) => {
|
|
|
33
32
|
model.animationsDisabled = true;
|
|
34
33
|
model.lockChoiceOrder = true;
|
|
35
34
|
model.choicesLayout = model.choicesLayout || 'vertical';
|
|
36
|
-
const choices = (0,
|
|
35
|
+
const choices = (0, _lodashEs.cloneDeep)(model.choices);
|
|
37
36
|
model.choices = choices.map(c => {
|
|
38
37
|
c.rationale = instr && model.rationaleEnabled !== false ? c.rationale : undefined;
|
|
39
38
|
c.hideTick = instr;
|
|
@@ -50,7 +49,7 @@ class MultipleChoicePrint extends HTMLElement {
|
|
|
50
49
|
this._model = null;
|
|
51
50
|
this._session = [];
|
|
52
51
|
this._root = null;
|
|
53
|
-
this._rerender = (0,
|
|
52
|
+
this._rerender = (0, _lodashEs.debounce)(() => {
|
|
54
53
|
if (this._model && this._session) {
|
|
55
54
|
const printModel = preparePrintModel(this._model, this._options);
|
|
56
55
|
const element = this._options && /*#__PURE__*/_react.default.createElement(_main.default, {
|
package/lib/print.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"print.js","names":["_react","_interopRequireDefault","require","_client","
|
|
1
|
+
{"version":3,"file":"print.js","names":["_react","_interopRequireDefault","require","_client","_lodashEs","_main","_mathRendering","_debug","log","debug","preparePrintModel","model","opts","instr","role","prompt","promptEnabled","undefined","teacherInstructions","teacherInstructionsEnabled","showTeacherInstructions","alwaysShowCorrect","mode","disabled","animationsDisabled","lockChoiceOrder","choicesLayout","choices","cloneDeep","map","c","rationale","rationaleEnabled","hideTick","feedback","keyMode","choicePrefix","MultipleChoicePrint","HTMLElement","constructor","_options","_model","_session","_root","_rerender","debounce","printModel","element","React","createElement","Main","session","options","createRoot","render","queueMicrotask","renderMath","leading","trailing","o","s","connectedCallback","disconnectedCallback","unmount","exports","default"],"sources":["../src/print.js"],"sourcesContent":["import React from 'react';\nimport { createRoot } from 'react-dom/client';\nimport { cloneDeep, debounce } from 'lodash-es';\nimport Main from './main';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport debug from 'debug';\n\nconst log = debug('pie-element:multiple-choice:print');\n\n/**\n * Live in same package as main element - so we can access some of the shared comps!\n *\n * - update pslb to build print if src/print.js is there\n * - update demo el\n * - get configure/controller building\n */\n\nconst preparePrintModel = (model, opts) => {\n const instr = opts.role === 'instructor';\n\n model.prompt = model.promptEnabled !== false ? model.prompt : undefined;\n model.teacherInstructions =\n instr && model.teacherInstructionsEnabled !== false ? model.teacherInstructions : undefined;\n model.showTeacherInstructions = instr;\n model.alwaysShowCorrect = instr;\n model.mode = instr ? 'evaluate' : model.mode;\n\n model.disabled = true;\n model.animationsDisabled = true;\n model.lockChoiceOrder = true;\n model.choicesLayout = model.choicesLayout || 'vertical';\n\n const choices = cloneDeep(model.choices);\n\n model.choices = choices.map((c) => {\n c.rationale = instr && model.rationaleEnabled !== false ? c.rationale : undefined;\n c.hideTick = instr;\n c.feedback = undefined;\n return c;\n });\n\n model.keyMode = model.choicePrefix || 'letters';\n\n return model;\n};\n\nexport default class MultipleChoicePrint extends HTMLElement {\n constructor() {\n super();\n this._options = null;\n this._model = null;\n this._session = [];\n this._root = null;\n this._rerender = debounce(\n () => {\n if (this._model && this._session) {\n const printModel = preparePrintModel(this._model, this._options);\n\n const element =\n this._options &&\n React.createElement(Main, {\n model: printModel,\n session: {},\n options: this._options,\n });\n\n if (!this._root) {\n this._root = createRoot(this);\n }\n this._root.render(element);\n queueMicrotask(() => {\n log('render complete - render math');\n renderMath(this);\n });\n } else {\n log('skip');\n }\n },\n 50,\n { leading: false, trailing: true },\n );\n }\n set options(o) {\n this._options = o;\n }\n\n set model(s) {\n this._model = s;\n this._rerender();\n }\n\n connectedCallback() {}\n\n disconnectedCallback() {\n if (this._root) {\n this._root.unmount();\n }\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAN,sBAAA,CAAAC,OAAA;AAEA,MAAMM,GAAG,GAAG,IAAAC,cAAK,EAAC,mCAAmC,CAAC;;AAEtD;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMC,iBAAiB,GAAGA,CAACC,KAAK,EAAEC,IAAI,KAAK;EACzC,MAAMC,KAAK,GAAGD,IAAI,CA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AE;MACd,IAAI,CAACA,KAAK,CAACoB,OAAO,CAAC,CAAC;IACtB;EACF;AACF;AAACC,OAAA,CAAAC,OAAA,GAAA5B,mBAAA","ignoreList":[]}
|
package/module/configure.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_dll_react_dom as e,_dll_react as t,_dll_prop_types as o,_dll_mui__material_styles as n,_dll_pie_lib__render_ui as i,_dll_mui__material as a,_dll_lodash as s,_dll_mui__icons_material as l,_dll_debug as r}from"../../../@pie-lib/shared-module@^3.0.5/module/index.js";import{_dll_pie_lib__config_ui as c}from"../../../@pie-lib/config-module@^3.0.0/module/index.js";import{_dll_pie_lib__editable_html_tip_tap as d}from"../../../@pie-lib/editable-html-module@^6.0.5/module/index.js";var h,u=e;h=u.createRoot,u.hydrateRoot;var g={};Object.defineProperty(g,"__esModule",{value:!0});class p extends CustomEvent{constructor(e,t=!1){super(p.TYPE,{bubbles:!0,detail:{update:e,reset:t}}),this.update=e,this.reset=t}}p.TYPE="model.updated";var m=g.ModelUpdatedEvent=p;class b extends CustomEvent{constructor(e,t){super(b.TYPE,{bubbles:!0,detail:{src:e,done:t}}),this.src=e,this.done=t}}b.TYPE="delete.image";var C=g.DeleteImageEvent=b;class _ extends CustomEvent{constructor(e){super(_.TYPE,{bubbles:!0,detail:e}),this.handler=e}}_.TYPE="insert.image";var f=g.InsertImageEvent=_;class E extends CustomEvent{constructor(e,t){super(E.TYPE,{bubbles:!0,detail:{src:e,done:t}}),this.src=e,this.done=t}}E.TYPE="delete.sound";var S=g.DeleteSoundEvent=E;class y extends CustomEvent{constructor(e){super(y.TYPE,{bubbles:!0,detail:e}),this.handler=e}}y.TYPE="insert.sound";var v=g.InsertSoundEvent=y;const k=t,I=o,{styled:x}=n,{color:A}=i,{Button:M}=a,{Tooltip:P}=a,{Typography:w}=a,{Box:T}=a,{Info:R}=l,{merge:O}=s,L=d,{AlertDialog:D}=c,{InputContainer:q}=c,{ChoiceConfiguration:W}=c,{settings:z}=c,{layout:Y}=c,{choiceUtils:B}=c;function U(e){let t,o=e[0],n=1;for(;n<e.length;){const i=e[n],a=e[n+1];if(n+=2,("optionalAccess"===i||"optionalCall"===i)&&null==o)return;"access"===i||"optionalAccess"===i?(t=o,o=a(o)):"call"!==i&&"optionalCall"!==i||(o=a((...e)=>o.call(t,...e)),t=void 0)}return o}const{Panel:$,toggle:H,radio:j,dropdown:F}=z,N=x(q)(({theme:e})=>({width:"100%",paddingTop:e.spacing(2),marginBottom:e.spacing(2)})),G=x(q)(({theme:e})=>({flex:1,marginTop:e.spacing(1.5),paddingTop:e.spacing(2),marginLeft:e.spacing(3.5)})),V=x(q)(({theme:e})=>({display:"flex",flexDirection:"column",marginBottom:e.spacing(1),width:"100%"})),J=x(M)(({theme:e})=>({marginTop:e.spacing(1),float:"right"})),K=x(J)({cursor:"not-allowed",pointerEvents:"all",backgroundColor:A.disabled(),"&:hover":{backgroundColor:A.disabled()},"&:focus":{backgroundColor:A.disabled()}}),Q=x(T)({display:"flex",alignItems:"center"}),X=x(w)(({theme:e})=>({fontSize:e.typography.fontSize+2,marginRight:e.spacing(1)})),Z=x(P)(({theme:e})=>({"& .MuiTooltip-tooltip":{fontSize:e.typography.fontSize-2,whiteSpace:"pre",maxWidth:"500px"}})),ee=x("div")(({theme:e})=>({fontSize:e.typography.fontSize-2,color:e.palette.error.main,paddingTop:e.spacing(1)})),te=e=>{const{model:t,configuration:o,onPromptChanged:n,onChoiceChanged:i,onRemoveChoice:a,onAddChoice:s,imageSupport:l,uploadSoundSupport:r,onChangeModel:c,onConfigurationChanged:d,onTeacherInstructionsChanged:h}=e,{addChoiceButton:u={},contentDimensions:g={},feedback:p={},deleteChoice:m={},choiceMode:b={},choicePrefix:C={},partialScoring:_={},lockChoiceOrder:f={},teacherInstructions:E={},studentInstructions:S={},rationale:y={},scoringType:v={},sequentialChoiceLabels:I={},settingsPanelDisabled:x,choicesLayout:A,spellCheck:M={},gridColumns:P,maxImageWidth:w={},maxImageHeight:T={},prompt:O={},withRubric:D={},mathMlOptions:q={},language:z={},languageChoices:B={}}=o||{};let{maxAnswerChoices:te}=o||{};const{limitChoicesNumber:oe,teacherInstructionsEnabled:ne,rationaleEnabled:ie,feedbackEnabled:ae,promptEnabled:se,spellCheckEnabled:le,choices:re,errors:ce,toolbarEditorPosition:de,extraCSSRules:he}=t||{},{answerChoices:ue,choices:ge,correctResponse:pe,prompt:me,rationale:be,teacherInstructions:Ce}=ce||{},_e=U([re,"optionalAccess",e=>e.length])?Array.from({length:re.length},(e,t)=>`${t+1}`):[],{baseInputConfiguration:fe={}}=o,Ee={position:"top"===de?"top":"bottom"};oe&&(te=9);const Se=(e={})=>({...fe,...e}),ye=(e=>{const{minAnswerChoices:t,maxAnswerChoices:o}=e;return`Validation requirements:\nThere should be at least ${t} `+(o?`and at most ${o} `:"")+"answer choices defined.\nEvery answer choice should be non-blank and unique.\nA correct answer must be defined."})(o),ve=w&&w.prompt,ke=T&&T.prompt,Ie=te&&U([re,"optionalAccess",e=>e.length])>=te?`Only ${te} allowed maximum`:"",xe={choiceMode:b.settings&&j(b.label,["checkbox","radio"]),"sequentialChoiceLabels.enabled":I.settings&&H(I.label,!0),choicePrefix:C.settings&&j(C.label,["numbers","letters"]),partialScoring:_.settings&&H(_.label),lockChoiceOrder:f.settings&&H(f.label),feedbackEnabled:p.settings&&H(p.label),choicesLayout:A.settings&&F(A.label,["vertical","grid","horizontal"]),gridColumns:A.settings&&"grid"===t.choicesLayout&&_e.length>0&&F(P.label,_e),"language.enabled":z.settings&&H(z.label,!0),language:z.settings&&z.enabled&&F(B.label,B.options)},Ae={teacherInstructionsEnabled:E.settings&&H(E.label),studentInstructionsEnabled:S.settings&&H(S.label),promptEnabled:O.settings&&H(O.label),rationaleEnabled:y.settings&&H(y.label),spellCheckEnabled:M.settings&&H(M.label),scoringType:v.settings&&j(v.label,["auto","rubric"]),rubricEnabled:U([D,"optionalAccess",e=>e.settings])&&H(U([D,"optionalAccess",e=>e.label]))};return k.createElement(Y.ConfigLayout,{dimensions:g,hideSettings:x,extraCSSRules:he,classes:{},settings:k.createElement($,{model:t,onChangeModel:c,configuration:o,onChangeConfiguration:d,groups:{Settings:xe,Properties:Ae}})},ne&&k.createElement(N,{label:E.label},k.createElement(L,{markup:t.teacherInstructions||"",onChange:h,imageSupport:l,nonEmpty:!1,disableUnderline:!0,error:Ce,toolbarOpts:Ee,pluginProps:Se(U([o,"optionalAccess",e=>e.teacherInstructions,"optionalAccess",e=>e.inputConfiguration])),spellCheck:le,maxImageWidth:w&&w.teacherInstructions||ve,maxImageHeight:T&&T.teacherInstructions||ke,uploadSoundSupport:r,languageCharactersProps:[{language:"spanish"},{language:"special"}],mathMlOptions:q}),Ce&&k.createElement(ee,null,Ce)),se&&k.createElement(N,{label:O.label},k.createElement(L,{markup:t.prompt,onChange:n,imageSupport:l,nonEmpty:!1,disableUnderline:!0,error:me,toolbarOpts:Ee,pluginProps:Se(U([o,"optionalAccess",e=>e.prompt,"optionalAccess",e=>e.inputConfiguration])),spellCheck:le,maxImageWidth:w&&w.prompt,maxImageHeight:T&&T.prompt,uploadSoundSupport:r,languageCharactersProps:[{language:"spanish"},{language:"special"}],mathMlOptions:q}),me&&k.createElement(ee,null,me)),k.createElement(Q,null,k.createElement(X,{component:"div"},"Choices"),k.createElement(Z,{disableFocusListener:!0,disableTouchListener:!0,placement:"right",title:ye},k.createElement(R,{fontSize:"small",color:"primary"}))),re.map((e,n)=>k.createElement(V,{key:`choice-${n}`},k.createElement(W,{key:n,index:n+1,useLetterOrdering:"letters"===t.choicePrefix,mode:t.choiceMode,data:e,defaultFeedback:{},imageSupport:l,disableImageAlignmentButtons:!0,onDelete:()=>a(n),onChange:e=>i(n,e),allowFeedBack:ae,allowDelete:m.settings,noLabels:!0,pluginOpts:Se(U([o,"optionalAccess",e=>e.choices,"optionalAccess",e=>e.inputConfiguration])),toolbarOpts:Ee,spellCheck:le,error:U([ge,"optionalAccess",t=>t[e.value]])||null,noCorrectAnswerError:pe,maxImageWidth:w&&w.choices||ve,maxImageHeight:T&&T.choices||ke,uploadSoundSupport:r,mathMlOptions:q}),ie&&k.createElement(G,{key:`rationale-${n}`,label:y.label},k.createElement(L,{markup:e.rationale||"",onChange:t=>i(n,{...e,rationale:t}),imageSupport:l,error:U([be,"optionalAccess",t=>t[e.value]])||null,toolbarOpts:Ee,pluginProps:Se(U([o,"optionalAccess",e=>e.rationale,"optionalAccess",e=>e.inputConfiguration])),spellCheck:le,maxImageWidth:w&&w.rationale||ve,maxImageHeight:T&&T.rationale||ke,uploadSoundSupport:r,languageCharactersProps:[{language:"spanish"},{language:"special"}],mathMlOptions:q}),U([be,"optionalAccess",t=>t[e.value]])&&k.createElement(ee,null,U([be,"optionalAccess",t=>t[e.value]]))))),pe&&k.createElement(ee,null,pe),ue&&k.createElement(ee,null,ue),u.settings&&k.createElement(Z,{title:Ie},te&&U([re,"optionalAccess",e=>e.length])>=te?k.createElement(K,{variant:"contained",color:"primary",onClick:s,disabled:!0},u.label):k.createElement(J,{variant:"contained",color:"primary",onClick:s},u.label)))};class oe extends k.Component{constructor(...e){super(...e),oe.prototype.__init.call(this),oe.prototype.__init2.call(this),oe.prototype.__init3.call(this),oe.prototype.__init4.call(this),oe.prototype.__init5.call(this),oe.prototype.__init6.call(this),oe.prototype.__init7.call(this)}static __initStatic(){this.propTypes={model:I.object.isRequired,configuration:I.object.isRequired,disableSidePanel:I.bool,onModelChanged:I.func.isRequired,onConfigurationChanged:I.func.isRequired,imageSupport:I.shape({add:I.func.isRequired,delete:I.func.isRequired})}}__init(){this.state={showWarning:!1}}__init2(){this.onRemoveChoice=e=>{const{model:t,configuration:o,onModelChanged:n}=this.props,{minAnswerChoices:i}=o||{};i&&t.choices.length===i?this.setState({showWarning:!0}):(t.choices.splice(e,1),n(t))}}__init3(){this.onAddChoice=()=>{const{model:e,configuration:t,onModelChanged:o}=this.props;let{maxAnswerChoices:n}=t||{};const{limitChoicesNumber:i}=e||{};i&&(n=9),n&&e.choices.length>=n||(e.choices.push({label:"",value:B.firstAvailableIndex(e.choices.map(e=>e.value),0),feedback:{type:"none"}}),o(e))}}__init4(){this.onChoiceChanged=(e,t)=>{const{model:o,onModelChanged:n}=this.props;t.correct&&"radio"===o.choiceMode&&(o.choices=o.choices.map(e=>O({},e,{correct:!1}))),o.choices.splice(e,1,t),n(o)}}__init5(){this.onPromptChanged=e=>{this.props.onModelChanged({...this.props.model,prompt:e})}}__init6(){this.onTeacherInstructionsChanged=e=>{this.props.onModelChanged({...this.props.model,teacherInstructions:e})}}__init7(){this.onModelChanged=(e,t)=>{const{onModelChanged:o}=this.props;if("choiceMode"===t){if("radio"===e.choiceMode){let t=!1;e.choices=e.choices.map(e=>t?(e.correct=!1,e):(e.correct&&(t=!0),e))}o(e,!0)}else o(e)}}render(){const{configuration:{minAnswerChoices:e}={}}=this.props,{showWarning:t}=this.state;return k.createElement(k.Fragment,null,k.createElement(D,{open:t,title:"Warning",text:`There can't be less than ${e||0} choices.`,onConfirm:()=>this.setState({showWarning:!1})}),k.createElement(te,{...this.props,onChangeModel:this.onModelChanged,onRemoveChoice:this.onRemoveChoice,onChoiceChanged:this.onChoiceChanged,onAddChoice:this.onAddChoice,onPromptChanged:this.onPromptChanged,onTeacherInstructionsChanged:this.onTeacherInstructionsChanged}))}}oe.__initStatic();var ne={choiceMode:"checkbox",choicePrefix:"letters",choices:[],choicesLayout:"vertical",feedbackEnabled:!1,gridColumns:2,lockChoiceOrder:!0,partialScoring:!0,prompt:"",promptEnabled:!0,rationale:"",rationaleEnabled:!0,scoringType:"auto",studentInstructionsEnabled:!0,teacherInstructions:"",teacherInstructionsEnabled:!0,toolbarEditorPosition:"bottom",selectedAnswerBackgroundColor:"initial",keyboardEventsEnabled:!1},ie={baseInputConfiguration:{audio:{disabled:!1},video:{disabled:!1},image:{disabled:!1},textAlign:{disabled:!0},showParagraphs:{disabled:!1},separateParagraphs:{disabled:!0}},choices:{inputConfiguration:{audio:{disabled:!1},video:{disabled:!1},image:{disabled:!1}}},spellCheck:{label:"Spellcheck",settings:!1,enabled:!0},choicesLayout:{settings:!1,label:"Choices Layout"},gridColumns:{label:"Grid columns"},answerChoiceCount:0,addChoiceButton:{settings:!0,label:"Add a Choice"},choiceMode:{settings:!0,label:"Response Type"},choicePrefix:{settings:!0,label:"Choice Labels"},deleteChoice:{settings:!0},feedback:{settings:!0,label:"Feedback"},prompt:{settings:!0,label:"Prompt",inputConfiguration:{audio:{disabled:!1},video:{disabled:!1},image:{disabled:!1}},required:!1},lockChoiceOrder:{settings:!0,label:"Lock Choice Order"},partialScoring:{settings:!1,label:"Allow Partial Scoring"},rationale:{settings:!0,label:"Rationale",inputConfiguration:{audio:{disabled:!0},video:{disabled:!0},image:{disabled:!1}},required:!1},scoringType:{settings:!1,label:"Scoring Type"},studentInstructions:{settings:!1,label:"Student Instructions"},teacherInstructions:{settings:!0,label:"Teacher Instructions",inputConfiguration:{audio:{disabled:!1},video:{disabled:!1},image:{disabled:!1}},required:!1},toolbarEditorPosition:{settings:!1,label:"Toolbar Editor Position"},minAnswerChoices:2,maxAnswerChoices:5,maxImageWidth:{teacherInstructions:300,prompt:300,rationale:636,choices:900},maxImageHeight:{teacherInstructions:300,prompt:300,rationale:300,choices:300},withRubric:{settings:!1,label:"Add Rubric"},mathMlOptions:{mmlOutput:!1,mmlEditing:!1},language:{settings:!1,label:"Specify Language",enabled:!1},languageChoices:{label:"Language Choices",options:[]}};const ae=t,se=r,{defaults:le}=s,{choiceUtils:re}=c;function ce(e){let t,o=e[0],n=1;for(;n<e.length;){const i=e[n],a=e[n+1];if(n+=2,("optionalAccess"===i||"optionalCall"===i)&&null==o)return;"access"===i||"optionalAccess"===i?(t=o,o=a(o)):"call"!==i&&"optionalCall"!==i||(o=a((...e)=>o.call(t,...e)),t=void 0)}return o}const de=se("multiple-choice:configure"),he=(e,t=0)=>{if(!e||0===e.length){let e=[];for(let o=0;o<t;o++)e.push({value:`${o}`,label:"",feedback:{type:"none",value:""}});return e}return e},ue=(e,t)=>{const o=le(e,ie);return{configuration:o,model:{...t,choices:he(t&&t.choices||[],o&&o.answerChoiceCount)}}};class ge extends HTMLElement{static __initStatic(){this.createDefaultModel=(e={})=>{const t=re.normalizeChoices({...ne,...e,choices:he(e&&e.choices||[])});return t.choicesLayout=e.choicesLayout||!1===e.verticalMode&&"horizontal"||ne.choicesLayout,t}}constructor(){super(),this._root=null,this._reactContainer=null,this._model=ge.createDefaultModel(),this._configuration=ie,this.onModelChanged=this.onModelChanged.bind(this),this.onConfigurationChanged=this.onConfigurationChanged.bind(this)}set model(e){this._model=ge.createDefaultModel(e),this._render()}set configuration(e){const t=ue(e,this._model);this.onModelChanged(t.model);const o={...ie,...t.configuration};this._configuration=o,ce([o,"optionalAccess",e=>e.language,"optionalAccess",e=>e.enabled])?ce([o,"optionalAccess",e=>e.languageChoices,"optionalAccess",e=>e.options,"optionalAccess",e=>e.length])&&(this._model.language=ce([o,"optionalAccess",e=>e.languageChoices,"access",e=>e.options,"access",e=>e[0],"access",e=>e.value])):o.language.settings&&this._model.language?(this._configuration.language.enabled=!0,this._configuration.languageChoices.options&&this._configuration.languageChoices.options.length||(this._configuration.languageChoices.options=[]),this._configuration.languageChoices.options.find(e=>e.value===this._model.language)||this._configuration.languageChoices.options.push({value:this._model.language,label:this._model.language})):delete this._model.language,this._render()}set disableSidePanel(e){this._disableSidePanel=e,this._render()}dispatchModelUpdated(e){const t=!!e;this.dispatchEvent(new m(this._model,t))}onModelChanged(e,t){this._model=e,this._render(),this.dispatchModelUpdated(t)}onConfigurationChanged(e){this._configuration=ue(e,this._model).configuration,this._model&&this.onModelChanged(this._model),this._render()}insertImage(e){this.dispatchEvent(new f(e))}onDeleteImage(e,t){this.dispatchEvent(new C(e,t))}insertSound(e){this.dispatchEvent(new v(e))}onDeleteSound(e,t){this.dispatchEvent(new S(e,t))}_render(){console.log("🔧 [multiple-choice-configure] _render - Starting render"),console.log("🔧 [multiple-choice-configure] _render - Model:",this._model?"present":"missing"),console.log("🔧 [multiple-choice-configure] _render - Configuration:",this._configuration?"present":"missing"),console.log("🔧 [multiple-choice-configure] _render - Root exists:",!!this._root),de("_render - Starting render"),de("_render - Model:",this._model?"present":"missing"),de("_render - Configuration:",this._configuration?"present":"missing"),de("_render - Root exists:",!!this._root);try{let e=ae.createElement(oe,{model:this._model,configuration:this._configuration,onModelChanged:this.onModelChanged,onConfigurationChanged:this.onConfigurationChanged,disableSidePanel:this._disableSidePanel,imageSupport:{add:this.insertImage.bind(this),delete:this.onDeleteImage.bind(this)},uploadSoundSupport:{add:this.insertSound.bind(this),delete:this.onDeleteSound.bind(this)}});this._root||(console.log("🔧 [multiple-choice-configure] _render - Creating React container"),de("_render - Creating React container"),this._reactContainer=document.createElement("div"),this._reactContainer.className="pie-configure-wrapper",this.appendChild(this._reactContainer),console.log("🔧 [multiple-choice-configure] _render - Creating new React root"),de("_render - Creating new React root"),this._root=h(this._reactContainer),console.log("✅ [multiple-choice-configure] _render - React root created successfully"),de("_render - React root created successfully")),console.log("🔧 [multiple-choice-configure] _render - Calling root.render()"),de("_render - Calling root.render()"),this._root.render(e),console.log("✅ [multiple-choice-configure] _render - Render completed successfully"),de("_render - Render completed successfully")}catch(e){throw console.error("❌ [multiple-choice-configure] Render error:",e),console.error("Error stack:",e.stack),e}}connectedCallback(){console.log("🔧 [multiple-choice-configure] connectedCallback - Component connected to DOM"),de("connectedCallback - Component connected to DOM"),de("connectedCallback - Model:",this._model?"present":"missing"),de("connectedCallback - Configuration:",this._configuration?"present":"missing")}disconnectedCallback(){console.log("🔧 [multiple-choice-configure] disconnectedCallback - Component disconnected from DOM"),de("disconnectedCallback - Component disconnected from DOM"),this._root&&(console.log("🔧 [multiple-choice-configure] disconnectedCallback - Unmounting React root"),de("disconnectedCallback - Unmounting React root"),this._root.unmount(),this._root=null),this._reactContainer&&(this._reactContainer=null)}}ge.__initStatic();export{ge as default};
|
|
1
|
+
import{_dll_react_dom as e,_dll_react as t,_dll_prop_types as o,_dll_mui__material_styles as n,_dll_pie_lib__render_ui as i,_dll_mui__material as r,_dll_mui__icons_material as a,_dll_debug as s}from"../../../@pie-lib/shared-module@^4.0.1/module/index.js";import{_dll_pie_lib__config_ui as l}from"../../../@pie-lib/config-module@^3.0.1/module/index.js";import{_dll_pie_lib__editable_html_tip_tap as c}from"../../../@pie-lib/editable-html-module@^6.1.2/module/index.js";var u,d=e;u=d.createRoot,d.hydrateRoot;var h={};Object.defineProperty(h,"__esModule",{value:!0});class p extends CustomEvent{constructor(e,t=!1){super(p.TYPE,{bubbles:!0,detail:{update:e,reset:t}}),this.update=e,this.reset=t}}p.TYPE="model.updated";var g=h.ModelUpdatedEvent=p;class f extends CustomEvent{constructor(e,t){super(f.TYPE,{bubbles:!0,detail:{src:e,done:t}}),this.src=e,this.done=t}}f.TYPE="delete.image";var b=h.DeleteImageEvent=f;class m extends CustomEvent{constructor(e){super(m.TYPE,{bubbles:!0,detail:e}),this.handler=e}}m.TYPE="insert.image";var _=h.InsertImageEvent=m;class C extends CustomEvent{constructor(e,t){super(C.TYPE,{bubbles:!0,detail:{src:e,done:t}}),this.src=e,this.done=t}}C.TYPE="delete.sound";var y=h.DeleteSoundEvent=C;class v extends CustomEvent{constructor(e){super(v.TYPE,{bubbles:!0,detail:e}),this.handler=e}}v.TYPE="insert.sound";var E=h.InsertSoundEvent=v,j="object"==typeof global&&global&&global.Object===Object&&global,S="object"==typeof self&&self&&self.Object===Object&&self,A=j||S||Function("return this")(),x=A.Symbol,w=Object.prototype,O=w.hasOwnProperty,P=w.toString,k=x?x.toStringTag:void 0,I=Object.prototype.toString,M=x?x.toStringTag:void 0;function T(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":M&&M in Object(e)?function(e){var t=O.call(e,k),o=e[k];try{e[k]=void 0;var n=!0}catch(e){}var i=P.call(e);return n&&(t?e[k]=o:delete e[k]),i}(e):function(e){return I.call(e)}(e)}function R(e){return null!=e&&"object"==typeof e}var z=Array.isArray;function L(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function D(e){return e}function U(e){if(!L(e))return!1;var t=T(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t}var q,F=A["__core-js_shared__"],$=(q=/[^.]+$/.exec(F&&F.keys&&F.keys.IE_PROTO||""))?"Symbol(src)_1."+q:"",B=Function.prototype.toString,W=/^\[object .+?Constructor\]$/,Y=Function.prototype,H=Object.prototype,N=Y.toString,G=H.hasOwnProperty,V=RegExp("^"+N.call(G).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function J(e,t){var o=function(e,t){return null==e?void 0:e[t]}(e,t);return function(e){return!(!L(e)||(t=e,$&&$ in t))&&(U(e)?V:W).test(function(e){if(null!=e){try{return B.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e));var t}(o)?o:void 0}var K,Q,X,Z=Object.create,ee=function(){function e(){}return function(t){if(!L(t))return{};if(Z)return Z(t);e.prototype=t;var o=new e;return e.prototype=void 0,o}}(),te=Date.now,oe=function(){try{var e=J(Object,"defineProperty");return e({},"",{}),e}catch(e){}}(),ne=oe,ie=ne?function(e,t){return ne(e,"toString",{configurable:!0,enumerable:!1,value:(o=t,function(){return o}),writable:!0});var o}:D,re=(K=ie,Q=0,X=0,function(){var e=te(),t=16-(e-X);if(X=e,t>0){if(++Q>=800)return arguments[0]}else Q=0;return K.apply(void 0,arguments)}),ae=/^(?:0|[1-9]\d*)$/;function se(e,t){var o=typeof e;return!!(t=null==t?9007199254740991:t)&&("number"==o||"symbol"!=o&&ae.test(e))&&e>-1&&e%1==0&&e<t}function le(e,t,o){"__proto__"==t&&ne?ne(e,t,{configurable:!0,enumerable:!0,value:o,writable:!0}):e[t]=o}function ce(e,t){return e===t||e!=e&&t!=t}var ue=Object.prototype.hasOwnProperty;function de(e,t,o){var n=e[t];ue.call(e,t)&&ce(n,o)&&(void 0!==o||t in e)||le(e,t,o)}var he=Math.max;function pe(e,t){return re(function(e,t,o){return t=he(void 0===t?e.length-1:t,0),function(){for(var n=arguments,i=-1,r=he(n.length-t,0),a=Array(r);++i<r;)a[i]=n[t+i];i=-1;for(var s=Array(t+1);++i<t;)s[i]=n[i];return s[t]=o(a),function(e,t,o){switch(o.length){case 0:return e.call(t);case 1:return e.call(t,o[0]);case 2:return e.call(t,o[0],o[1]);case 3:return e.call(t,o[0],o[1],o[2])}return e.apply(t,o)}(e,this,s)}}(e,t,D),e+"")}function ge(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991}function fe(e){return null!=e&&ge(e.length)&&!U(e)}function be(e,t,o){if(!L(o))return!1;var n=typeof t;return!!("number"==n?fe(o)&&se(t,o.length):"string"==n&&t in o)&&ce(o[t],e)}var me=Object.prototype;function _e(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||me)}function Ce(e){return R(e)&&"[object Arguments]"==T(e)}var ye=Object.prototype,ve=ye.hasOwnProperty,Ee=ye.propertyIsEnumerable,je=Ce(function(){return arguments}())?Ce:function(e){return R(e)&&ve.call(e,"callee")&&!Ee.call(e,"callee")},Se="object"==typeof exports&&exports&&!exports.nodeType&&exports,Ae=Se&&"object"==typeof module&&module&&!module.nodeType&&module,xe=Ae&&Ae.exports===Se?A.Buffer:void 0,we=(xe?xe.isBuffer:void 0)||function(){return!1},Oe={};Oe["[object Float32Array]"]=Oe["[object Float64Array]"]=Oe["[object Int8Array]"]=Oe["[object Int16Array]"]=Oe["[object Int32Array]"]=Oe["[object Uint8Array]"]=Oe["[object Uint8ClampedArray]"]=Oe["[object Uint16Array]"]=Oe["[object Uint32Array]"]=!0,Oe["[object Arguments]"]=Oe["[object Array]"]=Oe["[object ArrayBuffer]"]=Oe["[object Boolean]"]=Oe["[object DataView]"]=Oe["[object Date]"]=Oe["[object Error]"]=Oe["[object Function]"]=Oe["[object Map]"]=Oe["[object Number]"]=Oe["[object Object]"]=Oe["[object RegExp]"]=Oe["[object Set]"]=Oe["[object String]"]=Oe["[object WeakMap]"]=!1;var Pe="object"==typeof exports&&exports&&!exports.nodeType&&exports,ke=Pe&&"object"==typeof module&&module&&!module.nodeType&&module,Ie=ke&&ke.exports===Pe&&j.process,Me=function(){try{return ke&&ke.require&&ke.require("util").types||Ie&&Ie.binding&&Ie.binding("util")}catch(e){}}(),Te=Me&&Me.isTypedArray,Re=Te?function(e){return function(t){return e(t)}}(Te):function(e){return R(e)&&ge(e.length)&&!!Oe[T(e)]},ze=Re,Le=Object.prototype.hasOwnProperty;var De=Object.prototype.hasOwnProperty;function Ue(e){return fe(e)?function(e,t){var o=z(e),n=!o&&je(e),i=!o&&!n&&we(e),r=!o&&!n&&!i&&ze(e),a=o||n||i||r,s=a?function(e,t){for(var o=-1,n=Array(e);++o<e;)n[o]=t(o);return n}(e.length,String):[],l=s.length;for(var c in e)!t&&!Le.call(e,c)||a&&("length"==c||i&&("offset"==c||"parent"==c)||r&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||se(c,l))||s.push(c);return s}(e,!0):function(e){if(!L(e))return function(e){var t=[];if(null!=e)for(var o in Object(e))t.push(o);return t}(e);var t=_e(e),o=[];for(var n in e)("constructor"!=n||!t&&De.call(e,n))&&o.push(n);return o}(e)}var qe=J(Object,"create"),Fe=Object.prototype.hasOwnProperty,$e=Object.prototype.hasOwnProperty;function Be(e){var t=-1,o=null==e?0:e.length;for(this.clear();++t<o;){var n=e[t];this.set(n[0],n[1])}}function We(e,t){for(var o=e.length;o--;)if(ce(e[o][0],t))return o;return-1}Be.prototype.clear=function(){this.__data__=qe?qe(null):{},this.size=0},Be.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},Be.prototype.get=function(e){var t=this.__data__;if(qe){var o=t[e];return"__lodash_hash_undefined__"===o?void 0:o}return Fe.call(t,e)?t[e]:void 0},Be.prototype.has=function(e){var t=this.__data__;return qe?void 0!==t[e]:$e.call(t,e)},Be.prototype.set=function(e,t){var o=this.__data__;return this.size+=this.has(e)?0:1,o[e]=qe&&void 0===t?"__lodash_hash_undefined__":t,this};var Ye=Array.prototype.splice;function He(e){var t=-1,o=null==e?0:e.length;for(this.clear();++t<o;){var n=e[t];this.set(n[0],n[1])}}He.prototype.clear=function(){this.__data__=[],this.size=0},He.prototype.delete=function(e){var t=this.__data__,o=We(t,e);return!(o<0||(o==t.length-1?t.pop():Ye.call(t,o,1),--this.size,0))},He.prototype.get=function(e){var t=this.__data__,o=We(t,e);return o<0?void 0:t[o][1]},He.prototype.has=function(e){return We(this.__data__,e)>-1},He.prototype.set=function(e,t){var o=this.__data__,n=We(o,e);return n<0?(++this.size,o.push([e,t])):o[n][1]=t,this};var Ne=J(A,"Map");function Ge(e,t){var o,n,i=e.__data__;return("string"==(n=typeof(o=t))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==o:null===o)?i["string"==typeof t?"string":"hash"]:i.map}function Ve(e){var t=-1,o=null==e?0:e.length;for(this.clear();++t<o;){var n=e[t];this.set(n[0],n[1])}}Ve.prototype.clear=function(){this.size=0,this.__data__={hash:new Be,map:new(Ne||He),string:new Be}},Ve.prototype.delete=function(e){var t=Ge(this,e).delete(e);return this.size-=t?1:0,t},Ve.prototype.get=function(e){return Ge(this,e).get(e)},Ve.prototype.has=function(e){return Ge(this,e).has(e)},Ve.prototype.set=function(e,t){var o=Ge(this,e),n=o.size;return o.set(e,t),this.size+=o.size==n?0:1,this};var Je=function(e,t){return function(o){return e(t(o))}}(Object.getPrototypeOf,Object),Ke=Je,Qe=Function.prototype,Xe=Object.prototype,Ze=Qe.toString,et=Xe.hasOwnProperty,tt=Ze.call(Object);function ot(e){var t=this.__data__=new He(e);this.size=t.size}ot.prototype.clear=function(){this.__data__=new He,this.size=0},ot.prototype.delete=function(e){var t=this.__data__,o=t.delete(e);return this.size=t.size,o},ot.prototype.get=function(e){return this.__data__.get(e)},ot.prototype.has=function(e){return this.__data__.has(e)},ot.prototype.set=function(e,t){var o=this.__data__;if(o instanceof He){var n=o.__data__;if(!Ne||n.length<199)return n.push([e,t]),this.size=++o.size,this;o=this.__data__=new Ve(n)}return o.set(e,t),this.size=o.size,this};var nt="object"==typeof exports&&exports&&!exports.nodeType&&exports,it=nt&&"object"==typeof module&&module&&!module.nodeType&&module,rt=it&&it.exports===nt?A.Buffer:void 0,at=(rt&&rt.allocUnsafe,A.Uint8Array);var st=Object.prototype,lt=st.hasOwnProperty,ct=pe(function(e,t){e=Object(e);var o=-1,n=t.length,i=n>2?t[2]:void 0;for(i&&be(t[0],t[1],i)&&(n=1);++o<n;)for(var r=t[o],a=Ue(r),s=-1,l=a.length;++s<l;){var c=a[s],u=e[c];(void 0===u||ce(u,st[c])&&!lt.call(e,c))&&(e[c]=r[c])}return e});function ut(e,t,o){(void 0!==o&&!ce(e[t],o)||void 0===o&&!(t in e))&&le(e,t,o)}function dt(e,t){if(("constructor"!==t||"function"!=typeof e[t])&&"__proto__"!=t)return e[t]}function ht(e,t,o,n,i,r,a){var s=dt(e,o),l=dt(t,o),c=a.get(l);if(c)ut(e,o,c);else{var u,d=r?r(s,l,o+"",e,t,a):void 0,h=void 0===d;if(h){var p=z(l),g=!p&&we(l),f=!p&&!g&&ze(l);d=l,p||g||f?z(s)?d=s:R(u=s)&&fe(u)?d=function(e,t){var o=-1,n=e.length;for(t||(t=Array(n));++o<n;)t[o]=e[o];return t}(s):g?(h=!1,d=function(e){return e.slice()}(l)):f?(h=!1,d=function(e,t){var o,n,i=t?(n=new(o=e.buffer).constructor(o.byteLength),new at(n).set(new at(o)),n):e.buffer;return new e.constructor(i,e.byteOffset,e.length)}(l,!0)):d=[]:function(e){if(!R(e)||"[object Object]"!=T(e))return!1;var t=Ke(e);if(null===t)return!0;var o=et.call(t,"constructor")&&t.constructor;return"function"==typeof o&&o instanceof o&&Ze.call(o)==tt}(l)||je(l)?(d=s,je(s)?d=function(e){return function(e,t,o){var n=!o;o||(o={});for(var i=-1,r=t.length;++i<r;){var a=t[i],s=void 0;void 0===s&&(s=e[a]),n?le(o,a,s):de(o,a,s)}return o}(e,Ue(e))}(s):L(s)&&!U(s)||(d=function(e){return"function"!=typeof e.constructor||_e(e)?{}:ee(Ke(e))}(l))):h=!1}h&&(a.set(l,d),i(d,l,n,r,a),a.delete(l)),ut(e,o,d)}}function pt(e,t,o,n,i){e!==t&&function(e,t,o){for(var n=-1,i=Object(e),r=o(e),a=r.length;a--;){var s=r[++n];if(!1===t(i[s],s,i))break}}(t,function(r,a){if(i||(i=new ot),L(r))ht(e,t,a,o,pt,n,i);else{var s=n?n(dt(e,a),r,a+"",e,t,i):void 0;void 0===s&&(s=r),ut(e,a,s)}},Ue)}var gt,ft=(gt=function(e,t,o){pt(e,t,o)},pe(function(e,t){var o=-1,n=t.length,i=n>1?t[n-1]:void 0,r=n>2?t[2]:void 0;for(i=gt.length>3&&"function"==typeof i?(n--,i):void 0,r&&be(t[0],t[1],r)&&(i=n<3?void 0:i,n=1),e=Object(e);++o<n;){var a=t[o];a&>(e,a,o)}return e}));const bt=t,mt=o,{styled:_t}=n,{color:Ct}=i,{Button:yt}=r,{Tooltip:vt}=r,{Typography:Et}=r,{Box:jt}=r,{Info:St}=a,At=c,{AlertDialog:xt}=l,{InputContainer:wt}=l,{ChoiceConfiguration:Ot}=l,{settings:Pt}=l,{layout:kt}=l,{choiceUtils:It}=l;function Mt(e){let t,o=e[0],n=1;for(;n<e.length;){const i=e[n],r=e[n+1];if(n+=2,("optionalAccess"===i||"optionalCall"===i)&&null==o)return;"access"===i||"optionalAccess"===i?(t=o,o=r(o)):"call"!==i&&"optionalCall"!==i||(o=r((...e)=>o.call(t,...e)),t=void 0)}return o}const{Panel:Tt,toggle:Rt,radio:zt,dropdown:Lt}=Pt,Dt=_t(wt)(({theme:e})=>({width:"100%",paddingTop:e.spacing(2),marginBottom:e.spacing(2)})),Ut=_t(wt)(({theme:e})=>({flex:1,marginTop:e.spacing(1.5),paddingTop:e.spacing(2),marginLeft:e.spacing(3.5)})),qt=_t(wt)(({theme:e})=>({display:"flex",flexDirection:"column",marginBottom:e.spacing(1),width:"100%"})),Ft=_t(yt)(({theme:e})=>({marginTop:e.spacing(1),float:"right"})),$t=_t(Ft)({cursor:"not-allowed",pointerEvents:"all",backgroundColor:Ct.disabled(),"&:hover":{backgroundColor:Ct.disabled()},"&:focus":{backgroundColor:Ct.disabled()}}),Bt=_t(jt)({display:"flex",alignItems:"center"}),Wt=_t(Et)(({theme:e})=>({fontSize:e.typography.fontSize+2,marginRight:e.spacing(1)})),Yt=_t(vt)(({theme:e})=>({"& .MuiTooltip-tooltip":{fontSize:e.typography.fontSize-2,whiteSpace:"pre",maxWidth:"500px"}})),Ht=_t("div")(({theme:e})=>({fontSize:e.typography.fontSize-2,color:e.palette.error.main,paddingTop:e.spacing(1)})),Nt=e=>{const{model:t,configuration:o,onPromptChanged:n,onChoiceChanged:i,onRemoveChoice:r,onAddChoice:a,imageSupport:s,uploadSoundSupport:l,onChangeModel:c,onConfigurationChanged:u,onTeacherInstructionsChanged:d}=e,{addChoiceButton:h={},contentDimensions:p={},feedback:g={},deleteChoice:f={},choiceMode:b={},choicePrefix:m={},partialScoring:_={},lockChoiceOrder:C={},teacherInstructions:y={},studentInstructions:v={},rationale:E={},scoringType:j={},sequentialChoiceLabels:S={},settingsPanelDisabled:A,choicesLayout:x,spellCheck:w={},gridColumns:O,maxImageWidth:P={},maxImageHeight:k={},prompt:I={},withRubric:M={},mathMlOptions:T={},language:R={},languageChoices:z={}}=o||{};let{maxAnswerChoices:L}=o||{};const{limitChoicesNumber:D,teacherInstructionsEnabled:U,rationaleEnabled:q,feedbackEnabled:F,promptEnabled:$,spellCheckEnabled:B,choices:W,errors:Y,toolbarEditorPosition:H,extraCSSRules:N}=t||{},{answerChoices:G,choices:V,correctResponse:J,prompt:K,rationale:Q,teacherInstructions:X}=Y||{},Z=Mt([W,"optionalAccess",e=>e.length])?Array.from({length:W.length},(e,t)=>`${t+1}`):[],{baseInputConfiguration:ee={}}=o,te={position:"top"===H?"top":"bottom"};D&&(L=9);const oe=(e={})=>({...ee,...e}),ne=(e=>{const{minAnswerChoices:t,maxAnswerChoices:o}=e;return`Validation requirements:\nThere should be at least ${t} `+(o?`and at most ${o} `:"")+"answer choices defined.\nEvery answer choice should be non-blank and unique.\nA correct answer must be defined."})(o),ie=P&&P.prompt,re=k&&k.prompt,ae=L&&Mt([W,"optionalAccess",e=>e.length])>=L?`Only ${L} allowed maximum`:"",se={choiceMode:b.settings&&zt(b.label,["checkbox","radio"]),"sequentialChoiceLabels.enabled":S.settings&&Rt(S.label,!0),choicePrefix:m.settings&&zt(m.label,["numbers","letters"]),partialScoring:_.settings&&Rt(_.label),lockChoiceOrder:C.settings&&Rt(C.label),feedbackEnabled:g.settings&&Rt(g.label),choicesLayout:x.settings&&Lt(x.label,["vertical","grid","horizontal"]),gridColumns:x.settings&&"grid"===t.choicesLayout&&Z.length>0&&Lt(O.label,Z),"language.enabled":R.settings&&Rt(R.label,!0),language:R.settings&&R.enabled&&Lt(z.label,z.options)},le={teacherInstructionsEnabled:y.settings&&Rt(y.label),studentInstructionsEnabled:v.settings&&Rt(v.label),promptEnabled:I.settings&&Rt(I.label),rationaleEnabled:E.settings&&Rt(E.label),spellCheckEnabled:w.settings&&Rt(w.label),scoringType:j.settings&&zt(j.label,["auto","rubric"]),rubricEnabled:Mt([M,"optionalAccess",e=>e.settings])&&Rt(Mt([M,"optionalAccess",e=>e.label]))};return bt.createElement(kt.ConfigLayout,{dimensions:p,hideSettings:A,extraCSSRules:N,classes:{},settings:bt.createElement(Tt,{model:t,onChangeModel:c,configuration:o,onChangeConfiguration:u,groups:{Settings:se,Properties:le}})},U&&bt.createElement(Dt,{label:y.label},bt.createElement(At,{markup:t.teacherInstructions||"",onChange:d,imageSupport:s,nonEmpty:!1,disableUnderline:!0,error:X,toolbarOpts:te,pluginProps:oe(Mt([o,"optionalAccess",e=>e.teacherInstructions,"optionalAccess",e=>e.inputConfiguration])),spellCheck:B,maxImageWidth:P&&P.teacherInstructions||ie,maxImageHeight:k&&k.teacherInstructions||re,uploadSoundSupport:l,languageCharactersProps:[{language:"spanish"},{language:"special"}],mathMlOptions:T}),X&&bt.createElement(Ht,null,X)),$&&bt.createElement(Dt,{label:I.label},bt.createElement(At,{markup:t.prompt,onChange:n,imageSupport:s,nonEmpty:!1,disableUnderline:!0,error:K,toolbarOpts:te,pluginProps:oe(Mt([o,"optionalAccess",e=>e.prompt,"optionalAccess",e=>e.inputConfiguration])),spellCheck:B,maxImageWidth:P&&P.prompt,maxImageHeight:k&&k.prompt,uploadSoundSupport:l,languageCharactersProps:[{language:"spanish"},{language:"special"}],mathMlOptions:T}),K&&bt.createElement(Ht,null,K)),bt.createElement(Bt,null,bt.createElement(Wt,{component:"div"},"Choices"),bt.createElement(Yt,{disableFocusListener:!0,disableTouchListener:!0,placement:"right",title:ne},bt.createElement(St,{fontSize:"small",color:"primary"}))),W.map((e,n)=>bt.createElement(qt,{key:`choice-${n}`},bt.createElement(Ot,{key:n,index:n+1,useLetterOrdering:"letters"===t.choicePrefix,mode:t.choiceMode,data:e,defaultFeedback:{},imageSupport:s,disableImageAlignmentButtons:!0,onDelete:()=>r(n),onChange:e=>i(n,e),allowFeedBack:F,allowDelete:f.settings,noLabels:!0,pluginOpts:oe(Mt([o,"optionalAccess",e=>e.choices,"optionalAccess",e=>e.inputConfiguration])),toolbarOpts:te,spellCheck:B,error:Mt([V,"optionalAccess",t=>t[e.value]])||null,noCorrectAnswerError:J,maxImageWidth:P&&P.choices||ie,maxImageHeight:k&&k.choices||re,uploadSoundSupport:l,mathMlOptions:T}),q&&bt.createElement(Ut,{key:`rationale-${n}`,label:E.label},bt.createElement(At,{markup:e.rationale||"",onChange:t=>i(n,{...e,rationale:t}),imageSupport:s,error:Mt([Q,"optionalAccess",t=>t[e.value]])||null,toolbarOpts:te,pluginProps:oe(Mt([o,"optionalAccess",e=>e.rationale,"optionalAccess",e=>e.inputConfiguration])),spellCheck:B,maxImageWidth:P&&P.rationale||ie,maxImageHeight:k&&k.rationale||re,uploadSoundSupport:l,languageCharactersProps:[{language:"spanish"},{language:"special"}],mathMlOptions:T}),Mt([Q,"optionalAccess",t=>t[e.value]])&&bt.createElement(Ht,null,Mt([Q,"optionalAccess",t=>t[e.value]]))))),J&&bt.createElement(Ht,null,J),G&&bt.createElement(Ht,null,G),h.settings&&bt.createElement(Yt,{title:ae},L&&Mt([W,"optionalAccess",e=>e.length])>=L?bt.createElement($t,{variant:"contained",color:"primary",onClick:a,disabled:!0},h.label):bt.createElement(Ft,{variant:"contained",color:"primary",onClick:a},h.label)))};class Gt extends bt.Component{constructor(...e){super(...e),Gt.prototype.__init.call(this),Gt.prototype.__init2.call(this),Gt.prototype.__init3.call(this),Gt.prototype.__init4.call(this),Gt.prototype.__init5.call(this),Gt.prototype.__init6.call(this),Gt.prototype.__init7.call(this)}static __initStatic(){this.propTypes={model:mt.object.isRequired,configuration:mt.object.isRequired,disableSidePanel:mt.bool,onModelChanged:mt.func.isRequired,onConfigurationChanged:mt.func.isRequired,imageSupport:mt.shape({add:mt.func.isRequired,delete:mt.func.isRequired})}}__init(){this.state={showWarning:!1}}__init2(){this.onRemoveChoice=e=>{const{model:t,configuration:o,onModelChanged:n}=this.props,{minAnswerChoices:i}=o||{};i&&t.choices.length===i?this.setState({showWarning:!0}):(t.choices.splice(e,1),n(t))}}__init3(){this.onAddChoice=()=>{const{model:e,configuration:t,onModelChanged:o}=this.props;let{maxAnswerChoices:n}=t||{};const{limitChoicesNumber:i}=e||{};i&&(n=9),n&&e.choices.length>=n||(e.choices.push({label:"",value:It.firstAvailableIndex(e.choices.map(e=>e.value),0),feedback:{type:"none"}}),o(e))}}__init4(){this.onChoiceChanged=(e,t)=>{const{model:o,onModelChanged:n}=this.props;t.correct&&"radio"===o.choiceMode&&(o.choices=o.choices.map(e=>ft({},e,{correct:!1}))),o.choices.splice(e,1,t),n(o)}}__init5(){this.onPromptChanged=e=>{this.props.onModelChanged({...this.props.model,prompt:e})}}__init6(){this.onTeacherInstructionsChanged=e=>{this.props.onModelChanged({...this.props.model,teacherInstructions:e})}}__init7(){this.onModelChanged=(e,t)=>{const{onModelChanged:o}=this.props;if("choiceMode"===t){if("radio"===e.choiceMode){let t=!1;e.choices=e.choices.map(e=>t?(e.correct=!1,e):(e.correct&&(t=!0),e))}o(e,!0)}else o(e)}}render(){const{configuration:{minAnswerChoices:e}={}}=this.props,{showWarning:t}=this.state;return bt.createElement(bt.Fragment,null,bt.createElement(xt,{open:t,title:"Warning",text:`There can't be less than ${e||0} choices.`,onConfirm:()=>this.setState({showWarning:!1})}),bt.createElement(Nt,{...this.props,onChangeModel:this.onModelChanged,onRemoveChoice:this.onRemoveChoice,onChoiceChanged:this.onChoiceChanged,onAddChoice:this.onAddChoice,onPromptChanged:this.onPromptChanged,onTeacherInstructionsChanged:this.onTeacherInstructionsChanged}))}}Gt.__initStatic();var Vt={choiceMode:"checkbox",choicePrefix:"letters",choices:[],choicesLayout:"vertical",feedbackEnabled:!1,gridColumns:2,lockChoiceOrder:!0,partialScoring:!0,prompt:"",promptEnabled:!0,rationale:"",rationaleEnabled:!0,scoringType:"auto",studentInstructionsEnabled:!0,teacherInstructions:"",teacherInstructionsEnabled:!0,toolbarEditorPosition:"bottom",selectedAnswerBackgroundColor:"initial",keyboardEventsEnabled:!1},Jt={baseInputConfiguration:{h3:{disabled:!0},audio:{disabled:!1},video:{disabled:!1},image:{disabled:!1},textAlign:{disabled:!0},showParagraphs:{disabled:!1},separateParagraphs:{disabled:!0}},choices:{inputConfiguration:{audio:{disabled:!1},video:{disabled:!1},image:{disabled:!1}}},spellCheck:{label:"Spellcheck",settings:!1,enabled:!0},choicesLayout:{settings:!1,label:"Choices Layout"},gridColumns:{label:"Grid columns"},answerChoiceCount:0,addChoiceButton:{settings:!0,label:"Add a Choice"},choiceMode:{settings:!0,label:"Response Type"},choicePrefix:{settings:!0,label:"Choice Labels"},deleteChoice:{settings:!0},feedback:{settings:!0,label:"Feedback"},prompt:{settings:!0,label:"Prompt",inputConfiguration:{audio:{disabled:!1},video:{disabled:!1},image:{disabled:!1}},required:!1},lockChoiceOrder:{settings:!0,label:"Lock Choice Order"},partialScoring:{settings:!1,label:"Allow Partial Scoring"},rationale:{settings:!0,label:"Rationale",inputConfiguration:{audio:{disabled:!0},video:{disabled:!0},image:{disabled:!1}},required:!1},scoringType:{settings:!1,label:"Scoring Type"},studentInstructions:{settings:!1,label:"Student Instructions"},teacherInstructions:{settings:!0,label:"Teacher Instructions",inputConfiguration:{audio:{disabled:!1},video:{disabled:!1},image:{disabled:!1}},required:!1},toolbarEditorPosition:{settings:!1,label:"Toolbar Editor Position"},minAnswerChoices:2,maxAnswerChoices:5,maxImageWidth:{teacherInstructions:300,prompt:300,rationale:636,choices:900},maxImageHeight:{teacherInstructions:300,prompt:300,rationale:300,choices:300},withRubric:{settings:!1,label:"Add Rubric"},mathMlOptions:{mmlOutput:!1,mmlEditing:!1},language:{settings:!1,label:"Specify Language",enabled:!1},languageChoices:{label:"Language Choices",options:[]}};const Kt=t,Qt=s,{choiceUtils:Xt}=l;function Zt(e){let t,o=e[0],n=1;for(;n<e.length;){const i=e[n],r=e[n+1];if(n+=2,("optionalAccess"===i||"optionalCall"===i)&&null==o)return;"access"===i||"optionalAccess"===i?(t=o,o=r(o)):"call"!==i&&"optionalCall"!==i||(o=r((...e)=>o.call(t,...e)),t=void 0)}return o}const eo=Qt("multiple-choice:configure"),to=(e,t=0)=>{if(!e||0===e.length){let e=[];for(let o=0;o<t;o++)e.push({value:`${o}`,label:"",feedback:{type:"none",value:""}});return e}return e},oo=(e,t)=>{const o=ct(e,Jt);return{configuration:o,model:{...t,choices:to(t&&t.choices||[],o&&o.answerChoiceCount)}}};class no extends HTMLElement{static __initStatic(){this.createDefaultModel=(e={})=>{const t=Xt.normalizeChoices({...Vt,...e,choices:to(e&&e.choices||[])});return t.choicesLayout=e.choicesLayout||!1===e.verticalMode&&"horizontal"||Vt.choicesLayout,t}}constructor(){super(),this._root=null,this._reactContainer=null,this._model=no.createDefaultModel(),this._configuration=Jt,this.onModelChanged=this.onModelChanged.bind(this),this.onConfigurationChanged=this.onConfigurationChanged.bind(this)}set model(e){this._model=no.createDefaultModel(e),this._render()}set configuration(e){const t=oo(e,this._model);this.onModelChanged(t.model);const o={...Jt,...t.configuration};this._configuration=o,Zt([o,"optionalAccess",e=>e.language,"optionalAccess",e=>e.enabled])?Zt([o,"optionalAccess",e=>e.languageChoices,"optionalAccess",e=>e.options,"optionalAccess",e=>e.length])&&(this._model.language=Zt([o,"optionalAccess",e=>e.languageChoices,"access",e=>e.options,"access",e=>e[0],"access",e=>e.value])):o.language.settings&&this._model.language?(this._configuration.language.enabled=!0,this._configuration.languageChoices.options&&this._configuration.languageChoices.options.length||(this._configuration.languageChoices.options=[]),this._configuration.languageChoices.options.find(e=>e.value===this._model.language)||this._configuration.languageChoices.options.push({value:this._model.language,label:this._model.language})):delete this._model.language,this._render()}set disableSidePanel(e){this._disableSidePanel=e,this._render()}dispatchModelUpdated(e){const t=!!e;this.dispatchEvent(new g(this._model,t))}onModelChanged(e,t){this._model=e,this._render(),this.dispatchModelUpdated(t)}onConfigurationChanged(e){this._configuration=oo(e,this._model).configuration,this._model&&this.onModelChanged(this._model),this._render()}insertImage(e){this.dispatchEvent(new _(e))}onDeleteImage(e,t){this.dispatchEvent(new b(e,t))}insertSound(e){this.dispatchEvent(new E(e))}onDeleteSound(e,t){this.dispatchEvent(new y(e,t))}_render(){console.log("🔧 [multiple-choice-configure] _render - Starting render"),console.log("🔧 [multiple-choice-configure] _render - Model:",this._model?"present":"missing"),console.log("🔧 [multiple-choice-configure] _render - Configuration:",this._configuration?"present":"missing"),console.log("🔧 [multiple-choice-configure] _render - Root exists:",!!this._root),eo("_render - Starting render"),eo("_render - Model:",this._model?"present":"missing"),eo("_render - Configuration:",this._configuration?"present":"missing"),eo("_render - Root exists:",!!this._root);try{let e=Kt.createElement(Gt,{model:this._model,configuration:this._configuration,onModelChanged:this.onModelChanged,onConfigurationChanged:this.onConfigurationChanged,disableSidePanel:this._disableSidePanel,imageSupport:{add:this.insertImage.bind(this),delete:this.onDeleteImage.bind(this)},uploadSoundSupport:{add:this.insertSound.bind(this),delete:this.onDeleteSound.bind(this)}});this._root||(console.log("🔧 [multiple-choice-configure] _render - Creating React container"),eo("_render - Creating React container"),this._reactContainer=document.createElement("div"),this._reactContainer.className="pie-configure-wrapper",this.appendChild(this._reactContainer),console.log("🔧 [multiple-choice-configure] _render - Creating new React root"),eo("_render - Creating new React root"),this._root=u(this._reactContainer),console.log("✅ [multiple-choice-configure] _render - React root created successfully"),eo("_render - React root created successfully")),console.log("🔧 [multiple-choice-configure] _render - Calling root.render()"),eo("_render - Calling root.render()"),this._root.render(e),console.log("✅ [multiple-choice-configure] _render - Render completed successfully"),eo("_render - Render completed successfully")}catch(e){throw console.error("❌ [multiple-choice-configure] Render error:",e),console.error("Error stack:",e.stack),e}}connectedCallback(){console.log("🔧 [multiple-choice-configure] connectedCallback - Component connected to DOM"),eo("connectedCallback - Component connected to DOM"),eo("connectedCallback - Model:",this._model?"present":"missing"),eo("connectedCallback - Configuration:",this._configuration?"present":"missing")}disconnectedCallback(){console.log("🔧 [multiple-choice-configure] disconnectedCallback - Component disconnected from DOM"),eo("disconnectedCallback - Component disconnected from DOM"),this._root&&(console.log("🔧 [multiple-choice-configure] disconnectedCallback - Unmounting React root"),eo("disconnectedCallback - Unmounting React root"),this._root.unmount(),this._root=null),this._reactContainer&&(this._reactContainer=null)}}no.__initStatic();export{no as default};
|