2 lines
25 KiB
JavaScript
Executable File
2 lines
25 KiB
JavaScript
Executable File
(self.webpackChunkWebComponents=self.webpackChunkWebComponents||[]).push([[486],{35358:(t,e,s)=>{var r={"./af":25177,"./af.js":25177,"./ar":61509,"./ar-dz":41488,"./ar-dz.js":41488,"./ar-kw":58676,"./ar-kw.js":58676,"./ar-ly":42353,"./ar-ly.js":42353,"./ar-ma":24496,"./ar-ma.js":24496,"./ar-sa":82682,"./ar-sa.js":82682,"./ar-tn":89756,"./ar-tn.js":89756,"./ar.js":61509,"./az":95533,"./az.js":95533,"./be":28959,"./be.js":28959,"./bg":47777,"./bg.js":47777,"./bm":54903,"./bm.js":54903,"./bn":61290,"./bn.js":61290,"./bo":31545,"./bo.js":31545,"./br":11470,"./br.js":11470,"./bs":44429,"./bs.js":44429,"./ca":7306,"./ca.js":7306,"./cs":56464,"./cs.js":56464,"./cv":73635,"./cv.js":73635,"./cy":64226,"./cy.js":64226,"./da":93601,"./da.js":93601,"./de":77853,"./de-at":26111,"./de-at.js":26111,"./de-ch":54697,"./de-ch.js":54697,"./de.js":77853,"./dv":60708,"./dv.js":60708,"./el":54691,"./el.js":54691,"./en-au":53872,"./en-au.js":53872,"./en-ca":28298,"./en-ca.js":28298,"./en-gb":56195,"./en-gb.js":56195,"./en-ie":66584,"./en-ie.js":66584,"./en-nz":79402,"./en-nz.js":79402,"./eo":32934,"./eo.js":32934,"./es":97650,"./es-do":20838,"./es-do.js":20838,"./es-us":56575,"./es-us.js":56575,"./es.js":97650,"./et":3035,"./et.js":3035,"./eu":3508,"./eu.js":3508,"./fa":119,"./fa.js":119,"./fi":90527,"./fi.js":90527,"./fo":52477,"./fo.js":52477,"./fr":85498,"./fr-ca":26435,"./fr-ca.js":26435,"./fr-ch":37892,"./fr-ch.js":37892,"./fr.js":85498,"./fy":37071,"./fy.js":37071,"./gd":70217,"./gd.js":70217,"./gl":77329,"./gl.js":77329,"./gom-latn":93383,"./gom-latn.js":93383,"./gu":95050,"./gu.js":95050,"./he":11713,"./he.js":11713,"./hi":43861,"./hi.js":43861,"./hr":26308,"./hr.js":26308,"./hu":90609,"./hu.js":90609,"./hy-am":17160,"./hy-am.js":17160,"./id":74063,"./id.js":74063,"./is":89374,"./is.js":89374,"./it":88383,"./it.js":88383,"./ja":23827,"./ja.js":23827,"./jv":89722,"./jv.js":89722,"./ka":41794,"./ka.js":41794,"./kk":27088,"./kk.js":27088,"./km":96870,"./km.js":96870,"./kn":84451,"./kn.js":84451,"./ko":63164,"./ko.js":63164,"./ky":78474,"./ky.js":78474,"./lb":79680,"./lb.js":79680,"./lo":15867,"./lo.js":15867,"./lt":45766,"./lt.js":45766,"./lv":69532,"./lv.js":69532,"./me":58076,"./me.js":58076,"./mi":41848,"./mi.js":41848,"./mk":30306,"./mk.js":30306,"./ml":73739,"./ml.js":73739,"./mr":86169,"./mr.js":86169,"./ms":73386,"./ms-my":92297,"./ms-my.js":92297,"./ms.js":73386,"./mt":77075,"./mt.js":77075,"./my":72264,"./my.js":72264,"./nb":22274,"./nb.js":22274,"./ne":8235,"./ne.js":8235,"./nl":92572,"./nl-be":43784,"./nl-be.js":43784,"./nl.js":92572,"./nn":54566,"./nn.js":54566,"./pa-in":29849,"./pa-in.js":29849,"./pl":94418,"./pl.js":94418,"./pt":79834,"./pt-br":48303,"./pt-br.js":48303,"./pt.js":79834,"./ro":24457,"./ro.js":24457,"./ru":82271,"./ru.js":82271,"./sd":1221,"./sd.js":1221,"./se":33478,"./se.js":33478,"./si":17538,"./si.js":17538,"./sk":5784,"./sk.js":5784,"./sl":46637,"./sl.js":46637,"./sq":86794,"./sq.js":86794,"./sr":45719,"./sr-cyrl":3322,"./sr-cyrl.js":3322,"./sr.js":45719,"./ss":56e3,"./ss.js":56e3,"./sv":41011,"./sv.js":41011,"./sw":40748,"./sw.js":40748,"./ta":11025,"./ta.js":11025,"./te":11885,"./te.js":11885,"./tet":28861,"./tet.js":28861,"./th":55802,"./th.js":55802,"./tl-ph":29231,"./tl-ph.js":29231,"./tlh":31052,"./tlh.js":31052,"./tr":85096,"./tr.js":85096,"./tzl":79846,"./tzl.js":79846,"./tzm":81765,"./tzm-latn":97711,"./tzm-latn.js":97711,"./tzm.js":81765,"./uk":16618,"./uk.js":16618,"./ur":57777,"./ur.js":57777,"./uz":57609,"./uz-latn":72475,"./uz-latn.js":72475,"./uz.js":57609,"./vi":21135,"./vi.js":21135,"./x-pseudo":64051,"./x-pseudo.js":64051,"./yo":82218,"./yo.js":82218,"./zh-cn":52648,"./zh-cn.js":52648,"./zh-hk":1632,"./zh-hk.js":1632,"./zh-tw":50304,"./zh-tw.js":50304};function o(t){var e=n(t);return s(e)}function n(t){if(!s.o(r,t)){var e=new Error("Cannot find module '"+t+"'");throw e.code="MODULE_NOT_FOUND",e}return r[t]}o.keys=function(){return Object.keys(r)},o.resolve=n,t.exports=o,o.id=35358},39234:()=>{},46490:()=>{},56906:()=>{$.i18n().load({"pt-br":{msg_parson_check_me:"Verificar",msg_parson_reset:"Resetar",msg_parson_help:"Ajuda",msg_parson_too_short:"Seu programa é muito curto. Adicione mais blocos.",msg_parson_drag_from_here:"Arraste daqui",msg_parson_drag_to_here:"Largue os blocos aqui",msg_parson_correct_first_try:"Perfeito! Você levou apenas uma tentativa para resolver. Bom trabalho!",msg_parson_correct:"Perfeito! Você levou $1 tentativas para resolver. Clique em Resetar para tentar resolver em uma tentativa.",msg_parson_wrong_indent:"Este bloco não está indentado corretamente. Indente mais arrastando-o para a direita ou reduza a indentação arrastando para a esquerda.",msg_parson_wrong_indents:"Estes blocos não estão indentados corretamente. Para indentar mais, arraste o bloco para a direita. Para reduzir a indentação, arraste para a esquerda.",msg_parson_wrong_order:"Blocos destacados no seu programa estão errados ou estão na ordem errada. Isso pode ser resolvido movendo, excluindo ou substituindo os blocos destacados.",msg_parson_arrow_navigate:"Use as teclas de setas para navegar. Espaço para selecionar/ desmarcar blocos para mover.",msg_parson_help_info:"Clique no botão Ajuda se você quiser facilitar o problema",msg_parson_not_solution:"Foi desabilitado um bloco de código desnecessário (que não faz parte da solução).",msg_parson_provided_indent:"Foi fornecida a indentação.",msg_parson_combined_blocks:"Dois blocos de códigos foram combinados em um.",msg_parson_remove_incorrect:"Será removido um bloco de código incorreto da área de resposta",msg_parson_will_combine:"Serão combinados dois blocos",msg_parson_atleast_three_attempts:"Você deve tentar pelo menos três vezes antes de pedir ajuda",msg_parson_three_blocks_left:"Restam apenas 3 blocos corretos. Você deve colocá-los em ordem",msg_parson_will_provide_indent:"Será fornecida a indentação"}})},67920:()=>{},71182:(t,e,s)=>{"use strict";s.r(e),s.d(e,{default:()=>g,hpList:()=>p});var r=s(78673);class o{constructor(t){this.hparsons=t,this.percent=0}createOutput(){console.log("createOutput method not implemented in feedback!")}async runButtonHandler(){console.log("runButtonClicked method not implemented in feedback!")}customizeUI(){}init(){}clearFeedback(){console.log("clearFeedback method not implemented in feedback!")}reset(){console.log("reset method not implemented in feedback!")}}class n{constructor(t){this.problem=t,this.percent=0}inverseLISIndices(t){for(var e=[],s=0;s<t.length;s++){for(var r=[t[s]],o=t[s],n=-1,i=s;i<t.length;i++){var a=t[i];a>o&&n<a&&(r.push(a),n=a)}e.push(r)}var l,c=-1;for(let t in e){var h=e[t];h.length>c&&(c=h.length,l=h)}var u=[],d=0;for(let e=0;e<t.length;e++)d>l.length?u.push(e):t[e]==l[d]?d+=1:u.push(e);return u}grade(){this.correctLines=0,this.percentLines=0;var t,e,s=this.solution,r=this.answer;this.percentLines=Math.min(r.length,s.length)/Math.max(r.length,s.length),r.length<s.length?(e="incorrectTooShort",this.correctLength=!1):r.length==s.length?this.correctLength=!0:this.correctLength=!1;let o=!0;this.correctLines=0,this.solutionLength=s.length;let n=Math.min(s.length,r.length);for(t=0;t<n;t++)r[t]!==s[t]?o=!1:this.correctLines+=1;return o&&this.correctLength?e="correct":(o||"incorrectTooShort"==e)&&(this.correctLength||"incorrectTooShort"==e)||(e="incorrectMoveBlocks"),this.calculatePercent(),this.graderState=e,e}calculatePercent(){let t=.2*this.percentLines,e=this.answer.length,s=this.correctLines/e*.8;this.percent=t+s}}s(75794),s(56906);class i extends o{createOutput(){this.messageDiv=document.createElement("div"),this.hparsons.outerDiv.appendChild(this.messageDiv)}customizeUI(){this.hparsons.runButton.textContent="Check Me"}init(){this.checkCount=0,this.solved=!1,this.grader=new n;let t=[];for(let e=0;e<this.hparsons.blockAnswer.length;++e)t.push(this.hparsons.originalBlocks[this.hparsons.blockAnswer[e]]);this.solution=t,this.grader.solution=t,this.answerArea=this.hparsons.hparsonsInput.querySelector(".drop-area")}async runButtonHandler(){this.checkCurrentAnswer(),this.logCurrentAnswer(),this.renderFeedback()}async logCurrentAnswer(){let t={scheme:"block",correct:"correct"==this.grader.graderState?"T":"F",answer:this.hparsons.hparsonsInput.getParsonsTextArray(),percent:this.grader.percent},e={event:"hparsonsAnswer",div_id:this.hparsons.divid,act:JSON.stringify(t),answer:JSON.stringify({blocks:t.answer}),percent:this.grader.percent,correct:t.correct};await this.hparsons.logBookEvent(e)}checkCurrentAnswer(){this.solved||(this.checkCount++,this.clearFeedback(),this.grader.answer=this.hparsons.hparsonsInput.getParsonsTextArray(),this.grade=this.grader.grade(),"correct"==this.grade&&(this.hparsons.runButton.disabled=!0,this.solved=!0))}renderFeedback(){var t;this.grade=this.grader.graderState;var e=this.answerArea;if(t=this.messageDiv,"correct"===this.grade&&(e.classList.add("correct"),t.style.display="",t.className="hp_feedback alert alert-info",this.checkCount>1?t.innerHTML=$.i18n("msg_parson_correct",this.checkCount):t.innerHTML=$.i18n("msg_parson_correct_first_try"),this.checkCount=0),"incorrectTooShort"===this.grade&&(e.classList.add("incorrect"),t.style.display="",t.className="hp_feedback alert alert-danger",t.innerHTML=$.i18n("msg_parson_too_short")),"incorrectMoveBlocks"===this.grade){var s=this.answerArea.children,r=[],o=[],n=[];for(let t=0;t<s.length;t++){var i=s[t],a=this.solution.indexOf(i.textContent);-1==a?n.push(i):(r.push(i),o.push(a))}var l=this.grader.inverseLISIndices(o);for(let t=0;t<l.length;t++)n.push(r[l[t]]);e.classList.add("incorrect"),t.style.display="",t.className="alert alert-danger";for(let t=0;t<n.length;t++)n[t].classList.add("incorrectPosition");t.innerHTML=$.i18n("msg_parson_wrong_order")}}clearFeedback(){this.answerArea.classList.remove("incorrect","correct");for(var t=this.answerArea.childNodes,e=0;e<t.length;e++)t[e].classList.remove("correctPosition","incorrectPosition");this.messageDiv.style.display="none"}reset(){this.solved&&(this.checkCount=0,this.hparsons.runButton.disabled=!1,this.solved=!1),this.clearFeedback()}}var a=s(15826),l=s.n(a),c=s(12307),h={};class u extends o{createOutput(){var t=document.createElement("div");t.classList.add("hp_output"),this.outDiv=t,this.output=document.createElement("pre"),this.output.id=this.hparsons.divid+"_stdout",this.output.style.visibility="hidden";var e=document.createElement("div");e.style.clear="both",this.hparsons.outerDiv.appendChild(e),t.appendChild(this.output),this.hparsons.outerDiv.appendChild(t),(e=document.createElement("div")).style.clear="both",this.hparsons.outerDiv.appendChild(e)}renderFeedback(){this.testResult&&(this.output.textContent=this.testResult,this.output.style.visibility="visible"),this.outDiv.style.display=""}clearFeedback(){this.outDiv.style.display="none"}reset(){this.clearFeedback()}init(){var t,e;eBookConfig.useRunestoneServices||window.location.search.includes("mode=browsing")?(t=`/books/published/${eBookConfig.basecourse}`,e=t+"/_static"):(t="",e="/_static");let s={locateFile:t=>`${e}/${t}`};var r=this.hparsons;l()(s).then((function(e){if(r.dburl){r.dburl.startsWith("/_static")&&(r.dburl=`${t}${r.dburl}`),r.runButton.setAttribute("disabled","disabled");let o=r.runButton.textContent;if(r.runButton.textContent="Loading database...",r.dburl in h)return"loading"==h[r.dburl].status?void h[r.dburl].xWaitFor.promise.then((function(){r.db=h[r.dburl].dbObject,r.runButton.removeAttribute("disabled"),r.runButton.textContent=o})):(r.db=h[r.dburl].dbObject,r.runButton.removeAttribute("disabled"),void(r.runButton.textContent=o));{let t;const e=new Promise((e=>{t=e}));h[r.dburl]={status:"loading",xWaitFor:{promise:e,resolve:t}}}var s=new XMLHttpRequest;s.open("GET",r.dburl,!0),s.responseType="arraybuffer",s.onload=t=>{var n=new Uint8Array(s.response);r.db=new e.Database(n),h[r.dburl].dbObject=r.db,r.runButton.textContent=o,r.runButton.removeAttribute("disabled"),h[r.dburl].db=n,h[r.dburl].status="ready",h[r.dburl].xWaitFor.resolve()},s.send()}else r.db=new e.Database}))}async runButtonHandler(){this.hparsons.runButton.disabled=!0;try{await this.runProg()}catch(t){console.log(`there was an error ${t} running the code`)}this.logCurrentAnswer(),this.renderFeedback(),this.hparsons.runButton.disabled=!1}async runProg(){let t=this.hparsons.divid+"_sql_out",e=document.getElementById(t);e&&e.parentElement.removeChild(e),this.output.textContent="",e=document.createElement("div"),e.id=t,this.outDiv.appendChild(e),this.outDiv.style.display="";let s=await this.buildProg();if(!this.hparsons.db)return void(this.output.textContent=`Error: Database not initialized! DBURL: ${this.hparsons.dburl}`);let r=!0;return s.prefix&&(this.prefixresults=this.executeIteratedStatements(this.hparsons.db.iterateStatements(s.prefix)),"failure"==this.prefixresults.at(-1).status&&(this.visualizeResults(e,this.prefixresults,"Error executing hidden code in prefix"),r=!1)),r&&(this.results=this.executeIteratedStatements(this.hparsons.db.iterateStatements(s.input)),"failure"==this.results.at(-1).status?(this.visualizeResults(e,this.results),r=!1):s.suffix||this.visualizeResults(e,this.results)),r&&s.suffix&&(this.suffixresults=this.executeIteratedStatements(this.hparsons.db.iterateStatements(s.suffix)),"failure"==this.suffixresults.at(-1).status?(this.visualizeResults(e,this.suffixresults,"Error executing hidden code in suffix"),r=!1):this.visualizeResults(e,this.suffixresults)),this.hparsons.unittest?r?this.suffixresults?this.testResult=this.autograde(this.suffixresults[this.suffixresults.length-1]):this.testResult=this.autograde(this.results[this.results.length-1]):(this.passed=0,this.failed=0,this.percent=NaN,this.unit_results=`percent:${this.percent}:passed:${this.passed}:failed:${this.failed}`,this.output.style.visibility="hidden"):this.output.style.visibility="hidden",Promise.resolve("done")}executeIteratedStatements(t){let e=[];try{for(let s of t){let t=s.getColumnNames();if(t.length>0){let r=[];for(;s.step();)r.push(s.get());e.push({status:"success",columns:t,values:r,rowcount:r.length})}else{let t=s.getNormalizedSQL().substr(0,6).toLowerCase();s.step(),"insert"===t||"update"===t||"delete"===t?e.push({status:"success",operation:t,rowcount:this.hparsons.db.getRowsModified()}):e.push({status:"success"})}}}catch(s){e.push({status:"failure",message:s.toString(),sql:t.getRemainingSQL()})}return 0===e.length&&e.push({status:"failure",message:"No queries submitted."}),e}visualizeResults(t,e,s){if(s){let e=document.createElement("div");e.setAttribute("class","hp_sql_result"),t.appendChild(e);let r=document.createElement("pre");r.textContent=s,r.setAttribute("class","hp_sql_result_failure"),e.appendChild(r)}for(let s of e){let r=document.createElement("div");if(r.setAttribute("class","hp_sql_result"),t.appendChild(r),"success"===s.status)if(s.columns){let t=document.createElement("div");r.appendChild(t);let o=350;e.length>1&&(o=200),d(s,t,o);let n=document.createElement("pre"),i=1!==s.rowcount?" rows ":" row ",a=""+s.rowcount+i+"returned";s.rowcount>100&&(a+=" (only first 100 rows displayed)"),a+=".",n.textContent=a,n.setAttribute("class","hp_sql_result_success"),r.appendChild(n)}else if(s.rowcount){let t=document.createElement("pre"),e=s.operation;e+="e"===e.charAt(e.length-1)?"d.":"ed.";let o=1!==s.rowcount?" rows ":" row ";t.textContent=""+s.rowcount+o+e,t.setAttribute("class","hp_sql_result_success"),r.appendChild(t)}else{let t=document.createElement("pre");t.textContent="Operation succeeded.",t.setAttribute("class","hp_sql_result_success"),r.appendChild(t)}else{let t=document.createElement("pre");t.textContent=s.message,t.setAttribute("class","hp_sql_result_failure"),r.appendChild(t)}}}async buildProg(){let t={};return this.hparsons.hiddenPrefix&&(t.prefix=this.hparsons.hiddenPrefix),t.input=this.hparsons.hparsonsInput.getParsonsTextArray().join(" ")+"\n",this.hparsons.hiddenSuffix&&(t.suffix=this.hparsons.hiddenSuffix),Promise.resolve(t)}async logCurrentAnswer(){if(this.unit_results){let t={scheme:"execution",correct:0==this.failed&&0!=this.passed?"T":"F",answer:this.hparsons.hparsonsInput.getParsonsTextArray(),percent:this.percent},e={event:"hparsonsAnswer",div_id:this.hparsons.divid,act:JSON.stringify(t),percent:this.percent||0,correct:t.correct,answer:JSON.stringify({blocks:t.answer})};await this.hparsons.logBookEvent(e)}}autograde(t){var e=this.hparsons.unittest.split(/\n/);this.passed=0,this.failed=0;var s="";e=e.filter((function(t){return t.indexOf("assert")>-1}));for(let r of e){let e=r.split(/\s+/);e.shift();let o=e.shift(),n=e.shift(),i=e.join(" "),[a,l]=o.split(",");s+=this.testOneAssert(a,l,n,i,t),s+="\n"}let r=100*this.passed/(this.passed+this.failed);return this.percent=r,r=r.toLocaleString(void 0,{maximumFractionDigits:2}),s+=`You passed ${this.passed} out of ${this.passed+this.failed} tests for ${r}%`,this.unit_results=`percent:${r}:passed:${this.passed}:failed:${this.failed}`,s}testOneAssert(t,e,s,r,o){let n,i="";try{n=o.values[t][e]}catch(s){return"NO_DATA"==r?(this.passed++,i=`Passed: No data in row ${t}, column ${e}`,i):(i=`Failed: Not enough data to check row ${t} or column ${e}`,i)}return{"==":function(t,e){return t==e},"!=":function(t,e){return t!=e},">":function(t,e){return t>e},"<":function(t,e){return t>e}}[s](n,r)?(i=`Pass: ${n} ${s} ${r} in row ${t} column ${o.columns[e]}`,this.passed++):(i=`Failed ${n} ${s} ${r} in row ${t} column ${o.columns[e]}`,this.failed++),i}}function d(t,e,s){let r,o=t.values;0===o.length&&(o=[t.columns.map((t=>null))],r=[0]);var n=new c.A(e,{data:o,trimRows:r,width:"100%",height:s,autoRowSize:!0,autoColumnSize:{useHeaders:!0},rowHeaders:!1,colHeaders:t.columns,editor:!1,maxRows:100,filters:!1,dropdownMenu:!1,licenseKey:"non-commercial-and-evaluation"});let i=40;if(t.values.length>0)for(let t=0;t<o.length&&(i+=n.getRowHeight(t),!(i>s));t++);return n.updateSettings({height:i}),n}var p,m=s(70669);void 0===p&&(p={});class g extends r.A{constructor(t){super(t);var e=t.orig.querySelector("textarea");this.reuse=this.parseBooleanAttribute(e,"data-reuse"),this.randomize=this.parseBooleanAttribute(e,"data-randomize"),this.isBlockGrading=this.parseBooleanAttribute(e,"data-blockanswer"),this.language=e.getAttribute("data-language"),void 0===this.language&&e.textContent.includes('span class="process-math"')&&(this.language="math"),this.isBlockGrading&&(this.blockAnswer=e.getAttribute("data-blockanswer").split(" ")),this.divid=t.orig.id,this.containerDiv=t.orig,this.useRunestoneServices=t.useRunestoneServices;var s=super.localStorageKey();this.storageId=s,this.origElem=e;let r=t.orig.querySelector(".hp_question");r&&r.classList.add("exercise-statement"),this.origText=this.origElem.textContent,this.code=e.textContent||"\n\n\n\n\n",this.dburl=e.getAttribute("data-dburl"),this.runButton=null,this.saveButton=null,this.loadButton=null,this.outerDiv=null,this.controlDiv=null,this.processContent(this.code),this.microParsonToRaw=new Map,this.simulatedSolution=[],this.isBlockGrading?this.feedbackController=new i(this):this.feedbackController=new u(this),this.createEditor(),this.createControls(),this.createOutput(),this.feedbackController.customizeUI(),e.getAttribute("data-caption")?this.caption=e.getAttribute("data-caption"):this.caption="MicroParsons",this.addCaption("runestone"),this.indicate_component_ready(),this.feedbackController.init(),this.checkServer("hparsonsAnswer",!0)}processContent(t){this.hiddenPrefix=this.processSingleContent(t,"--hiddenprefix--"),this.originalBlocks=this.processSingleContent(t,"--blocks--").split("\n").slice(1,-1),this.hiddenSuffix=this.processSingleContent(t,"--hiddensuffix--"),this.unittest=this.processSingleContent(t,"--unittest--")}processSingleContent(t,e){let s=t.indexOf(e);if(s>-1){let r=t.substring(s+e.length),o=r.indexOf("\n--");return r=o>-1?r.substring(0,o+1):r,r}}createEditor(){this.outerDiv=document.createElement("div"),this.origElem.replaceWith(this.outerDiv),this.outerDiv.id=`${this.divid}-container`,this.outerDiv.addEventListener("micro-parsons",(t=>{["input","reset"].includes(t.detail.type)&&(this.logHorizontalParsonsEvent(t.detail),this.feedbackController.clearFeedback())}));const t={selector:`#${this.divid}-container`,id:`${this.divid}-hparsons`,reuse:this.reuse,randomize:this.randomize,parsonsBlocks:[...this.originalBlocks],language:this.language};(0,m.z)(t),this.hparsonsInput=this.outerDiv.querySelector("micro-parsons"),this.renderMathInBlocks(),void 0!==this.language&&"math"!==this.language||this.outerDiv.querySelectorAll(".hparsons-tip").forEach((t=>{t.textContent.includes("our code")&&(t.textContent=t.textContent.replace("our code","our answer"))}))}createOutput(){this.feedbackController.createOutput()}createControls(){var t=document.createElement("div");t.classList.add("hp_actions"),this.runButton=document.createElement("button"),this.runButton.classList.add("btn","btn-success","run-button"),t.appendChild(this.runButton),this.runButton.setAttribute("type","button"),this.runButton.textContent="Run";var e,s=this;this.runButton.onclick=()=>{s.feedbackController.runButtonHandler(),s.setLocalStorage()},(e=document.createElement("button")).textContent="Reset",e.classList.add("btn","btn-warning","run-button"),t.appendChild(e),this.resetButton=e,this.resetButton.onclick=()=>{s.hparsonsInput.resetInput(),s.setLocalStorage(),s.feedbackController.reset(),s.renderMathInBlocks()},e.setAttribute("type","button"),this.outerDiv.appendChild(t),this.controlDiv=t}decodeHTMLEntities(t){const e=document.createElement("textarea");return e.innerHTML=t,e.value}renderMathInBlocks(){"math"===this.language&&setTimeout((()=>{document.querySelectorAll(`#${this.divid}-container .parsons-block`).forEach((t=>{t.innerHTML=this.decodeHTMLEntities(t.innerHTML)})),window.MathJax&&MathJax.typesetPromise&&MathJax.typesetPromise().then((()=>this.simulateSolution()))}),0)}simulateSolution(){if(this.simulatedSolution.length>0&&this.microParsonToRaw instanceof Map&&this.microParsonToRaw.size>0)return this.feedbackController.solution=this.simulatedSolution,void(this.feedbackController.grader.solution=this.simulatedSolution);this.microParsonToRaw=new Map;const t=Array.from(this.outerDiv.querySelectorAll("micro-parsons .parsons-block"));if(!this.blockAnswer||0===t.length)return;const e=this.hparsonsInput.getParsonsTextArray(),s=this.originalBlocks,r=this.blockAnswer.map(Number);this.simulatedSolution=r.map((t=>e[t])),e.forEach(((t,e)=>this.microParsonToRaw.set(t,s[e].trim()))),this.feedbackController.solution=this.simulatedSolution,this.feedbackController.grader.solution=this.simulatedSolution}localData(){var t=localStorage.getItem(this.storageId);return null!==t&&"{"==t.charAt(0)?JSON.parse(t):{}}restoreAnswers(t){t.answer&&this.hparsonsInput.restoreAnswer(t.answer.blocks),t.count&&(this.feedbackController.checkCount=t.count)}checkLocalStorage(){if(this.graderactive)return;let t=this.localData();t.answer&&this.hparsonsInput.restoreAnswer(t.answer),t.count&&(this.feedbackController.checkCount=t.count),t.simulatedSolution&&(this.simulatedSolution=t.simulatedSolution),t.microParsonToRaw?this.microParsonToRaw=new Map(Object.entries(t.microParsonToRaw)):this.microParsonToRaw=new Map}setLocalStorage(t){let e={};if(null==t){let t=this.hparsonsInput.getParsonsTextArray();"math"===this.language?(t=t.map((t=>this.microParsonToRaw.get(t))),e={answer:t,simulatedSolution:this.simulatedSolution,microParsonToRaw:Object.fromEntries(this.microParsonToRaw)}):e={answer:t},this.isBlockGrading&&(e.count=this.feedbackController.checkCount)}else e=t;localStorage.setItem(this.storageId,JSON.stringify(e))}logHorizontalParsonsEvent(t){let e={event:"hparsons",div_id:this.divid,act:JSON.stringify(t)};this.logBookEvent(e)}}document.addEventListener("runestone:login-complete",(function(){document.querySelectorAll("[data-component=hparsons]").forEach((function(t){t.closest("[data-component=timedAssessment]")||(p[t.id]=new g({orig:t,useRunestoneServices:eBookConfig.useRunestoneServices}))}))})),void 0===window.component_factory&&(window.component_factory={}),window.component_factory.hparsons=function(t){return new g(t)}},75794:()=>{$.i18n().load({en:{msg_parson_check_me:"Check",msg_parson_reset:"Reset",msg_parson_help:"Help me",msg_parson_too_short:"Your answer is too short. Add more blocks.",msg_parson_drag_from_here:"Drag from here",msg_parson_drag_to_here:"Drop blocks here",msg_parson_correct_first_try:"Perfect! It took you only one try to solve this. Great job!",msg_parson_correct:"Perfect! It took you $1 tries to solve this. Click Reset to try to solve it in one attempt.",msg_parson_correct_runnable:"Click Run below to test out your solution.",msg_parson_wrong_indent:"This block is not indented correctly. Either indent it more by dragging it right or reduce the indention by dragging it left.",msg_parson_wrong_indents:"These blocks are not indented correctly. To indent a block more, drag it to the right. To reduce the indention, drag it to the left.",msg_parson_wrong_order:"Highlighted blocks in your answer are wrong or are in the wrong order. This can be fixed by moving, removing, or replacing highlighted blocks.",msg_parson_arrow_navigate:"Arrow keys to navigate. Space to select / deselect block to move.",msg_parson_help_info:"Click on the Help Me button if you want to make the problem easier",msg_parson_not_solution:"Disabled an unneeded code block (one that is not part of the solution).",msg_parson_provided_indent:"Provided the indentation.",msg_parson_combined_blocks:"Combined two code blocks into one.",msg_parson_remove_incorrect:"Will remove an incorrect code block from answer area",msg_parson_will_combine:"Will combine two blocks",msg_parson_atleast_three_attempts:"You must make at least three distinct full attempts at a solution before you can get help",msg_parson_three_blocks_left:"There are only 3 correct blocks left. You should be able to put them in order",msg_parson_will_provide_indent:"Will provide indentation"}})}}]);
|
|
//# sourceMappingURL=486.78d96ffc5c65634b.js.map
|