@@ -3120,46 +3120,103 @@ class ParsonsInput {
31203120 _initSortable = () => {
31213121 this._dragSortable.destroy();
31223122 this._dropSortable.destroy();
3123- this._dragSortable = new Sortable(this._dragArea, {
3124- group: {
3125- name: 'shared',
3126- // pull: 'clone',
3127- // put: false
3128- },
3129- // sort: false,
3130- direction: 'horizontal',
3131- animation: 150,
3132- draggable: '.parsons-block',
3133- });
3134- this._dropSortable = new Sortable(this._dropArea, {
3135- group: 'shared',
3136- direction: 'horizontal',
3137- animation: 150,
3138- draggable: '.parsons-block',
3139- onAdd: (event) => {
3140- const inputEvent = {
3141- 'event-type': 'parsons-input',
3142- action: 'add',
3143- position: [-1, this._getBlockPosition(event.item)],
3144- answer: this._getTextArray(),
3145- };
3146- this.parentElement.logEvent(inputEvent);
3147- },
3148- onStart: (event) => {
3149- this._prevPosition = this._getBlockPosition(event.item);
3150- },
3151- onEnd: (event) => {
3152- let endposition = this._getBlockPosition(event.item);
3153- const action = endposition == -1 ? 'remove' : 'move';
3154- const inputEvent = {
3155- 'event-type': 'parsons-input',
3156- action: action,
3157- position: [this._prevPosition, endposition],
3158- answer: this._getTextArray(),
3159- };
3160- this.parentElement.logEvent(inputEvent);
3161- },
3162- });
3123+ if (this.reusable) {
3124+ this._dragSortable = new Sortable(this._dragArea, {
3125+ group: {
3126+ name: 'shared',
3127+ pull: 'clone',
3128+ put: false
3129+ },
3130+ sort: false,
3131+ direction: 'horizontal',
3132+ animation: 150,
3133+ draggable: '.parsons-block',
3134+ });
3135+ this._dropSortable = new Sortable(this._dropArea, {
3136+ group: 'shared',
3137+ direction: 'horizontal',
3138+ animation: 150,
3139+ draggable: '.parsons-block',
3140+ onAdd: (event) => {
3141+ const inputEvent = {
3142+ 'event-type': 'parsons-input',
3143+ action: 'add',
3144+ position: [-1, this._getBlockPosition(event.item)],
3145+ answer: this._getTextArray(),
3146+ };
3147+ this.parentElement.logEvent(inputEvent);
3148+ },
3149+ onStart: (event) => {
3150+ this._prevPosition = this._getBlockPosition(event.item);
3151+ },
3152+ onEnd: (event) => {
3153+ let endposition;
3154+ let action = 'move';
3155+ const upperbound = this._dropArea.getBoundingClientRect().top;
3156+ const lowerbound = this._dropArea.getBoundingClientRect().bottom;
3157+ if (event.originalEvent.clientY > lowerbound || event.originalEvent.clientY < upperbound) {
3158+ const item = event.item;
3159+ if (item.parentNode) {
3160+ item.parentNode.removeChild(item);
3161+ }
3162+ endposition = -1;
3163+ action = 'remove';
3164+ }
3165+ else {
3166+ endposition = this._getBlockPosition(event.item);
3167+ }
3168+ const inputEvent = {
3169+ 'event-type': 'parsons-input',
3170+ action: action,
3171+ position: [this._prevPosition, endposition],
3172+ answer: this._getTextArray(),
3173+ };
3174+ this.parentElement.logEvent(inputEvent);
3175+ },
3176+ });
3177+ }
3178+ else {
3179+ this._dragSortable = new Sortable(this._dragArea, {
3180+ group: {
3181+ name: 'shared',
3182+ // pull: 'clone',
3183+ // put: false
3184+ },
3185+ // sort: false,
3186+ direction: 'horizontal',
3187+ animation: 150,
3188+ draggable: '.parsons-block',
3189+ });
3190+ this._dropSortable = new Sortable(this._dropArea, {
3191+ group: 'shared',
3192+ direction: 'horizontal',
3193+ animation: 150,
3194+ draggable: '.parsons-block',
3195+ onAdd: (event) => {
3196+ const inputEvent = {
3197+ 'event-type': 'parsons-input',
3198+ action: 'add',
3199+ position: [-1, this._getBlockPosition(event.item)],
3200+ answer: this._getTextArray(),
3201+ };
3202+ this.parentElement.logEvent(inputEvent);
3203+ },
3204+ onStart: (event) => {
3205+ this._prevPosition = this._getBlockPosition(event.item);
3206+ },
3207+ onEnd: (event) => {
3208+ let endposition = this._getBlockPosition(event.item);
3209+ const action = endposition == -1 ? 'remove' : 'move';
3210+ const inputEvent = {
3211+ 'event-type': 'parsons-input',
3212+ action: action,
3213+ position: [this._prevPosition, endposition],
3214+ answer: this._getTextArray(),
3215+ };
3216+ this.parentElement.logEvent(inputEvent);
3217+ },
3218+ });
3219+ }
31633220 };
31643221 updateTestStatus = (result) => {
31653222 if (this._dropArea.classList.contains(result)) {
@@ -15358,6 +15415,7 @@ class HParsonsElement extends HTMLElement {
1535815415 this.root.append(this.inputDiv);
1535915416 const reusable = this.getAttribute('reuse-blocks') ? true : false;
1536015417 this.hparsonsInput = new ParsonsInput(this, reusable);
15418+ // console.log(reusable)
1536115419 // a div wrapping the input and the test case status
1536215420 // init regex input based on the input type
1536315421 this._parsonsData = new Array();
0 commit comments