1- // import 'handsontable/dist/handsontable.full.css';
21import RunestoneBase from "../../common/js/runestonebase.js" ;
32import "../css/hparsons.css" ;
43import "../css/hljs-xcode.css" ;
54import BlockFeedback from "./BlockFeedback.js" ;
65import SQLFeedback from "./SQLFeedback.js" ;
6+ import { InitMicroParsons } from 'micro-parsons/micro-parsons/micro-parsons.js' ;
7+ import 'micro-parsons/micro-parsons/micro-parsons.css' ;
78
89export var hpList ;
910// Dictionary that contains all instances of horizontal Parsons problem objects
1011if ( hpList === undefined ) hpList = { } ;
1112
12- // The following js library is a custom element for micro parsons (horizontal parsons) input.
13- // Currently it is not published as an npm package yet, and edits should be made through: https://github.com/amy21206/micro-parsons-element.
14- // It will be replaced by importing the corresponding package in the future.
15- import "./micro-parsons.js" ;
1613
17- export default class SQLHParsons extends RunestoneBase {
14+ export default class HParsons extends RunestoneBase {
1815 constructor ( opts ) {
1916 super ( opts ) ;
2017 // copied from activecode
@@ -67,7 +64,7 @@ export default class SQLHParsons extends RunestoneBase {
6764 if ( $ ( orig ) . data ( "caption" ) ) {
6865 this . caption = $ ( orig ) . data ( "caption" ) ;
6966 } else {
70- this . caption = "HorizontalParsons " ;
67+ this . caption = "MicroParsons " ;
7168 }
7269 this . addCaption ( "runestone" ) ;
7370 this . indicate_component_ready ( ) ;
@@ -78,22 +75,9 @@ export default class SQLHParsons extends RunestoneBase {
7875
7976 // copied from activecode, already modified to add parsons
8077 createEditor ( ) {
81- // console.log('test create editor hparsons')
8278 this . outerDiv = document . createElement ( "div" ) ;
8379 $ ( this . origElem ) . replaceWith ( this . outerDiv ) ;
84- let parsonsHTML = `<micro-parsons id='${ this . divid } -hparsons'` ;
85- parsonsHTML += ` input-type='parsons' ` ;
86- if ( this . reuse ) {
87- parsonsHTML += ` reuse-blocks="true"` ;
88- }
89- if ( this . randomize ) {
90- parsonsHTML += ` randomize="true"` ;
91- }
92- if ( this . language ) {
93- parsonsHTML += ` language="` + this . language + `"` ;
94- }
95- parsonsHTML += `>` ;
96- this . outerDiv . innerHTML = parsonsHTML ;
80+ this . outerDiv . id = `${ this . divid } -container` ;
9781 this . outerDiv . addEventListener ( "micro-parsons" , ( ev ) => {
9882 this . logHorizontalParsonsEvent ( ev . detail ) ;
9983 this . feedbackController . clearFeedback ( ) ;
@@ -109,9 +93,17 @@ export default class SQLHParsons extends RunestoneBase {
10993 : blocksString ;
11094 blocks = blocksString . split ( "\n" ) ;
11195 }
112- this . hparsonsInput = $ ( this . outerDiv ) . find ( "micro-parsons" ) [ 0 ] ;
11396 this . originalBlocks = blocks . slice ( 1 , - 1 ) ;
114- this . hparsonsInput . parsonsData = blocks . slice ( 1 , - 1 ) ;
97+ const props = {
98+ selector : `#${ this . divid } -container` ,
99+ id : `${ this . divid } -hparsons` ,
100+ reuse : this . reuse ,
101+ randomize : this . randomize ,
102+ parsonsBlocks : blocks . slice ( 1 , - 1 ) ,
103+ language : this . language
104+ }
105+ InitMicroParsons ( props ) ;
106+ this . hparsonsInput = $ ( this . outerDiv ) . find ( "micro-parsons" ) [ 0 ] ;
115107 }
116108
117109 createOutput ( ) {
@@ -152,8 +144,6 @@ export default class SQLHParsons extends RunestoneBase {
152144 }
153145
154146 logHorizontalParsonsEvent ( hparsonsEvent ) {
155- // TODO: might need to find another way to change "act".
156- // The event string is probably too long.
157147 let ev = {
158148 event : "hparsons" ,
159149 div_id : this . divid ,
@@ -173,7 +163,7 @@ $(document).on("runestone:login-complete", function () {
173163 if ( $ ( this ) . closest ( "[data-component=timedAssessment]" ) . length == 0 ) {
174164 // If this element exists within a timed component, don't render it here
175165 // try {
176- hpList [ this . id ] = new SQLHParsons ( {
166+ hpList [ this . id ] = new HParsons ( {
177167 orig : this ,
178168 useRunestoneServices : eBookConfig . useRunestoneServices ,
179169 } ) ;
@@ -189,5 +179,5 @@ if (typeof window.component_factory === "undefined") {
189179 window . component_factory = { } ;
190180}
191181window . component_factory [ "hparsons" ] = function ( opts ) {
192- return new SQLHParsons ( opts ) ;
182+ return new HParsons ( opts ) ;
193183} ;
0 commit comments