@@ -3163,7 +3163,7 @@ class ParsonsInput {
31633163 newBlock.parentNode?.removeChild(newBlock);
31643164 if (this.parentElement) {
31653165 this.parentElement.temporaryInputEvent = {
3166- 'event-type': 'parsons',
3166+ 'event-type': 'parsons-input ',
31673167 action: RegexEvent.ParsonsInputAction.REMOVE,
31683168 position: [endPosition, -1],
31693169 answer: this._getTextArray()
@@ -3177,7 +3177,7 @@ class ParsonsInput {
31773177 }
31783178 if (this.parentElement && firstBlock) {
31793179 this.parentElement.temporaryInputEvent = {
3180- 'event-type': 'parsons',
3180+ 'event-type': 'parsons-input ',
31813181 action: RegexEvent.ParsonsInputAction.ADD,
31823182 position: [-1, this._getBlockPosition(firstBlock)],
31833183 answer: this._getTextArray(),
@@ -3244,7 +3244,7 @@ class ParsonsInput {
32443244 newBlockCopy.parentNode?.removeChild(newBlockCopy);
32453245 if (this.parentElement) {
32463246 this.parentElement.temporaryInputEvent = {
3247- 'event-type': 'parsons',
3247+ 'event-type': 'parsons-input ',
32483248 action: RegexEvent.ParsonsInputAction.REMOVE,
32493249 position: [endPosition, -1],
32503250 answer: this._getTextArray()
@@ -3254,7 +3254,7 @@ class ParsonsInput {
32543254 };
32553255 if (this.parentElement) {
32563256 this.parentElement.temporaryInputEvent = {
3257- 'event-type': 'parsons',
3257+ 'event-type': 'parsons-input ',
32583258 action: RegexEvent.ParsonsInputAction.ADD,
32593259 position: [-1, this._getBlockPosition(newBlockCopy)],
32603260 answer: this._getTextArray(),
@@ -3271,7 +3271,7 @@ class ParsonsInput {
32713271 newBlock.parentNode?.removeChild(newBlock);
32723272 if (this.parentElement) {
32733273 this.parentElement.temporaryInputEvent = {
3274- 'event-type': 'parsons',
3274+ 'event-type': 'parsons-input ',
32753275 action: RegexEvent.ParsonsInputAction.REMOVE,
32763276 position: [endPosition, -1],
32773277 answer: this._getTextArray(),
@@ -3317,7 +3317,7 @@ class ParsonsInput {
33173317 newBlock.parentNode?.removeChild(newBlock);
33183318 if (this.parentElement) {
33193319 this.parentElement.temporaryInputEvent = {
3320- 'event-type': 'parsons',
3320+ 'event-type': 'parsons-input ',
33213321 action: RegexEvent.ParsonsInputAction.REMOVE,
33223322 position: [endPosition, -1],
33233323 answer: this._getTextArray(),
@@ -3331,7 +3331,7 @@ class ParsonsInput {
33313331 }
33323332 if (this.parentElement && firstBlock) {
33333333 this.parentElement.temporaryInputEvent = {
3334- 'event-type': 'parsons',
3334+ 'event-type': 'parsons-input ',
33353335 action: RegexEvent.ParsonsInputAction.ADD,
33363336 position: [-1, this._getBlockPosition(firstBlock)],
33373337 answer: this._getTextArray(),
@@ -3357,7 +3357,7 @@ class ParsonsInput {
33573357 newBlockCopy.parentNode?.removeChild(newBlockCopy);
33583358 if (this.parentElement) {
33593359 this.parentElement.temporaryInputEvent = {
3360- 'event-type': 'parsons',
3360+ 'event-type': 'parsons-input ',
33613361 action: RegexEvent.ParsonsInputAction.REMOVE,
33623362 position: [endPosition, -1],
33633363 answer: this._getTextArray(),
@@ -3367,7 +3367,7 @@ class ParsonsInput {
33673367 };
33683368 if (this.parentElement) {
33693369 this.parentElement.temporaryInputEvent = {
3370- 'event-type': 'parsons',
3370+ 'event-type': 'parsons-input ',
33713371 action: RegexEvent.ParsonsInputAction.ADD,
33723372 position: [-1, this._getBlockPosition(newBlockCopy)],
33733373 answer: this._getTextArray(),
@@ -3385,7 +3385,7 @@ class ParsonsInput {
33853385 newBlock.parentNode?.removeChild(newBlock);
33863386 if (this.parentElement) {
33873387 this.parentElement.temporaryInputEvent = {
3388- 'event-type': 'parsons',
3388+ 'event-type': 'parsons-input ',
33893389 action: RegexEvent.ParsonsInputAction.REMOVE,
33903390 position: [endPosition, -1],
33913391 answer: this._getTextArray(),
@@ -3408,7 +3408,7 @@ class ParsonsInput {
34083408 // console.log(isExpandable);
34093409 if (this.parentElement) {
34103410 this.parentElement.temporaryInputEvent = {
3411- 'event-type': 'parsons',
3411+ 'event-type': 'parsons-input ',
34123412 action: RegexEvent.ParsonsInputAction.ADD,
34133413 position: [-1, this._getBlockPosition(event.item)],
34143414 answer: this._getTextArray(),
@@ -3441,7 +3441,7 @@ class ParsonsInput {
34413441 newBlock.parentNode?.removeChild(newBlock);
34423442 if (this.parentElement) {
34433443 this.parentElement.temporaryInputEvent = {
3444- 'event-type': 'parsons',
3444+ 'event-type': 'parsons-input ',
34453445 action: RegexEvent.ParsonsInputAction.REMOVE,
34463446 position: [endPosition, -1],
34473447 answer: this._getTextArray(),
@@ -3480,7 +3480,7 @@ class ParsonsInput {
34803480 }
34813481 if (this.parentElement) {
34823482 this.parentElement.temporaryInputEvent = {
3483- 'event-type': 'parsons',
3483+ 'event-type': 'parsons-input ',
34843484 action: action,
34853485 position: [this._prevPosition, endposition],
34863486 answer: this._getTextArray(),
@@ -3565,6 +3565,38 @@ class ParsonsInput {
35653565 }
35663566 }
35673567 };
3568+ restoreAnswer(type, answer) {
3569+ if (type != 'parsons' || !Array.isArray(answer)) {
3570+ return;
3571+ }
3572+ console.log('parsons restore');
3573+ console.log(answer);
3574+ this._dropArea.innerHTML = '';
3575+ for (let i = 0; i < answer.length; ++i) {
3576+ if (typeof answer[i] === 'string') {
3577+ const newBlock = document.createElement('div');
3578+ this._dropArea.appendChild(newBlock);
3579+ newBlock.innerText = answer[i];
3580+ newBlock.style.display = 'inline-block';
3581+ newBlock.classList.add('parsons-block');
3582+ newBlock.onclick = () => {
3583+ // clicking the new block generated by clicking an extendable block to remove that block
3584+ // console.log('expandable new block onclick')
3585+ const endPosition = this._getBlockPosition(newBlock);
3586+ newBlock.parentNode?.removeChild(newBlock);
3587+ if (this.parentElement) {
3588+ this.parentElement.temporaryInputEvent = {
3589+ 'event-type': 'parsons-input',
3590+ action: RegexEvent.ParsonsInputAction.REMOVE,
3591+ position: [endPosition, -1],
3592+ answer: this._getTextArray()
3593+ };
3594+ }
3595+ };
3596+ this.el.dispatchEvent(new Event('regexChanged'));
3597+ }
3598+ }
3599+ }
35683600}
35693601
35703602var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
@@ -15527,7 +15559,7 @@ class TextInput {
1552715559 shortKey: true,
1552815560 }, (range, context) => {
1552915561 const freeKeyboardEvent = {
15530- 'event-type': 'free -input-keyboard',
15562+ 'event-type': 'text -input-keyboard',
1553115563 range: range,
1553215564 keys: ['ctrl', 'c']
1553315565 };
@@ -15541,7 +15573,7 @@ class TextInput {
1554115573 shortKey: true,
1554215574 }, (range, context) => {
1554315575 const freeKeyboardEvent = {
15544- 'event-type': 'free -input-keyboard',
15576+ 'event-type': 'text -input-keyboard',
1554515577 range: range,
1554615578 keys: ['ctrl', 'v']
1554715579 };
@@ -15625,6 +15657,16 @@ class TextInput {
1562515657 'background': '#ff99b3'
1562615658 }, 'silent');
1562715659 };
15660+ restoreAnswer(type, answer) {
15661+ // TODO (misplaced): consider removing expandable blocks
15662+ // TODO: add logging to restoring answer
15663+ if (type != 'text' || typeof answer !== 'string') {
15664+ return;
15665+ }
15666+ console.log('text restore');
15667+ console.log(answer);
15668+ this.quill?.setText(answer);
15669+ }
1562815670}
1562915671
1563015672// import {Quill} from '../types/Quill';
@@ -16775,13 +16817,15 @@ class RegexElement extends HTMLElement {
1677516817 this.negativeTestStringInput.setText(this.negativeInitialTestString);
1677616818 };
1677716819 logEvent = (eventContent) => {
16778- ( {
16820+ const basicEvent = {
1677916821 'student-id': window.regexStudentId || 'stub-id',
1678016822 'course-id': window.regexCourseId || 'stub-course-id',
1678116823 'problem-id': this.problemId,
1678216824 'input-type': this.inputType,
1678316825 'client-timestamp': this._getTimestamp()
16784- });
16826+ };
16827+ const ev = new CustomEvent('regex-element', { bubbles: true, detail: { ...basicEvent, ...eventContent } });
16828+ this.dispatchEvent(ev);
1678516829 // console.log({...basicEvent, ...eventContent});
1678616830 };
1678716831 _getTimestamp = () => {
@@ -16921,7 +16965,7 @@ class RegexElement extends HTMLElement {
1692116965 this.regexInput.removeFormat();
1692216966 // logging free input event
1692316967 this.temporaryInputEvent = {
16924- 'event-type': 'free -input',
16968+ 'event-type': 'text -input',
1692516969 dropped: this.regexInput.droppedText,
1692616970 delta: delta,
1692716971 answer: this.regexInput.getText()
@@ -16995,6 +17039,15 @@ class RegexElement extends HTMLElement {
1699517039 this._testStatusDiv.innerText = '';
1699617040 this.unitTestTable.setError();
1699717041 }
17042+ // restore student answer from outside storage
17043+ restoreAnswer(type, answer) {
17044+ if (type == undefined || answer == undefined) {
17045+ return;
17046+ }
17047+ console.log('regex restore');
17048+ console.log(answer);
17049+ this.regexInput.restoreAnswer(type, answer);
17050+ }
1699817051}
1699917052customElements.define('regex-element', RegexElement);
1700017053
0 commit comments