@gmb/bitmark-parser-generator 1.0.16 → 1.1.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.
Files changed (116) hide show
  1. package/dist/browser/bitmark-parser-generator-antlr.min.js +1 -1
  2. package/dist/browser/bitmark-parser-generator.min.js +1 -1
  3. package/dist/browser/bundle-report.html +2 -2
  4. package/dist/cjs/ast/BaseBuilder.js +63 -15
  5. package/dist/cjs/ast/BaseBuilder.js.map +1 -1
  6. package/dist/cjs/ast/Builder.js +345 -179
  7. package/dist/cjs/ast/Builder.js.map +1 -1
  8. package/dist/cjs/config/bits/articleBitConfig.js +66 -47
  9. package/dist/cjs/config/bits/articleBitConfig.js.map +1 -1
  10. package/dist/cjs/config/bits/essayBitConfig.js +2 -0
  11. package/dist/cjs/config/bits/essayBitConfig.js.map +1 -1
  12. package/dist/cjs/config/bits/imageBitConfig.js +3 -0
  13. package/dist/cjs/config/bits/imageBitConfig.js.map +1 -1
  14. package/dist/cjs/config/bits/sequenceBitConfig.js +2 -0
  15. package/dist/cjs/config/bits/sequenceBitConfig.js.map +1 -1
  16. package/dist/cjs/config/bits/trueFalse1BitConfig.js +2 -0
  17. package/dist/cjs/config/bits/trueFalse1BitConfig.js.map +1 -1
  18. package/dist/cjs/config/properties/examplePropertyConfig.js +1 -1
  19. package/dist/cjs/config/properties/examplePropertyConfig.js.map +1 -1
  20. package/dist/cjs/generated/build-info.js +1 -1
  21. package/dist/cjs/generated/build-info.js.map +1 -1
  22. package/dist/cjs/generator/bitmark/BitmarkGenerator.js +39 -20
  23. package/dist/cjs/generator/bitmark/BitmarkGenerator.js.map +1 -1
  24. package/dist/cjs/generator/json/JsonGenerator.js +157 -88
  25. package/dist/cjs/generator/json/JsonGenerator.js.map +1 -1
  26. package/dist/cjs/model/ast/NodeType.js +2 -1
  27. package/dist/cjs/model/ast/NodeType.js.map +1 -1
  28. package/dist/cjs/model/enum/BitType.js +21 -0
  29. package/dist/cjs/model/enum/BitType.js.map +1 -1
  30. package/dist/cjs/model/enum/ExampleType.js +11 -0
  31. package/dist/cjs/model/enum/ExampleType.js.map +1 -0
  32. package/dist/cjs/parser/bitmark/peg/BitmarkPegParserTypes.js.map +1 -1
  33. package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +23 -7
  34. package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
  35. package/dist/cjs/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js +61 -0
  36. package/dist/cjs/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js.map +1 -0
  37. package/dist/cjs/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js +6 -1
  38. package/dist/cjs/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js.map +1 -1
  39. package/dist/cjs/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js +1 -0
  40. package/dist/cjs/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js.map +1 -1
  41. package/dist/cjs/parser/json/JsonParser.js +35 -33
  42. package/dist/cjs/parser/json/JsonParser.js.map +1 -1
  43. package/dist/cjs/utils/ObjectUtils.js +10 -5
  44. package/dist/cjs/utils/ObjectUtils.js.map +1 -1
  45. package/dist/esm/ast/BaseBuilder.js +63 -15
  46. package/dist/esm/ast/BaseBuilder.js.map +1 -1
  47. package/dist/esm/ast/Builder.js +345 -179
  48. package/dist/esm/ast/Builder.js.map +1 -1
  49. package/dist/esm/config/bits/articleBitConfig.js +66 -47
  50. package/dist/esm/config/bits/articleBitConfig.js.map +1 -1
  51. package/dist/esm/config/bits/essayBitConfig.js +2 -0
  52. package/dist/esm/config/bits/essayBitConfig.js.map +1 -1
  53. package/dist/esm/config/bits/imageBitConfig.js +3 -0
  54. package/dist/esm/config/bits/imageBitConfig.js.map +1 -1
  55. package/dist/esm/config/bits/sequenceBitConfig.js +2 -0
  56. package/dist/esm/config/bits/sequenceBitConfig.js.map +1 -1
  57. package/dist/esm/config/bits/trueFalse1BitConfig.js +2 -0
  58. package/dist/esm/config/bits/trueFalse1BitConfig.js.map +1 -1
  59. package/dist/esm/config/properties/examplePropertyConfig.js +1 -1
  60. package/dist/esm/config/properties/examplePropertyConfig.js.map +1 -1
  61. package/dist/esm/generated/build-info.js +1 -1
  62. package/dist/esm/generated/build-info.js.map +1 -1
  63. package/dist/esm/generator/bitmark/BitmarkGenerator.js +39 -20
  64. package/dist/esm/generator/bitmark/BitmarkGenerator.js.map +1 -1
  65. package/dist/esm/generator/json/JsonGenerator.js +157 -88
  66. package/dist/esm/generator/json/JsonGenerator.js.map +1 -1
  67. package/dist/esm/model/ast/NodeType.js +2 -1
  68. package/dist/esm/model/ast/NodeType.js.map +1 -1
  69. package/dist/esm/model/enum/BitType.js +21 -0
  70. package/dist/esm/model/enum/BitType.js.map +1 -1
  71. package/dist/esm/model/enum/ExampleType.js +8 -0
  72. package/dist/esm/model/enum/ExampleType.js.map +1 -0
  73. package/dist/esm/parser/bitmark/peg/BitmarkPegParserTypes.js.map +1 -1
  74. package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +23 -7
  75. package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
  76. package/dist/esm/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js +58 -0
  77. package/dist/esm/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js.map +1 -0
  78. package/dist/esm/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js +6 -1
  79. package/dist/esm/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.js.map +1 -1
  80. package/dist/esm/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js +1 -0
  81. package/dist/esm/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js.map +1 -1
  82. package/dist/esm/parser/json/JsonParser.js +35 -33
  83. package/dist/esm/parser/json/JsonParser.js.map +1 -1
  84. package/dist/esm/utils/ObjectUtils.js +10 -5
  85. package/dist/esm/utils/ObjectUtils.js.map +1 -1
  86. package/dist/types/ast/BaseBuilder.d.ts +23 -4
  87. package/dist/types/ast/BaseBuilder.d.ts.map +1 -1
  88. package/dist/types/ast/Builder.d.ts +40 -15
  89. package/dist/types/ast/Builder.d.ts.map +1 -1
  90. package/dist/types/generator/bitmark/BitmarkGenerator.d.ts +3 -2
  91. package/dist/types/generator/bitmark/BitmarkGenerator.d.ts.map +1 -1
  92. package/dist/types/generator/json/JsonGenerator.d.ts +12 -5
  93. package/dist/types/generator/json/JsonGenerator.d.ts.map +1 -1
  94. package/dist/types/model/ast/NodeType.d.ts +4 -2
  95. package/dist/types/model/ast/NodeType.d.ts.map +1 -1
  96. package/dist/types/model/ast/Nodes.d.ts +31 -12
  97. package/dist/types/model/ast/Nodes.d.ts.map +1 -1
  98. package/dist/types/model/enum/BitType.d.ts +44 -0
  99. package/dist/types/model/enum/BitType.d.ts.map +1 -1
  100. package/dist/types/model/enum/ExampleType.d.ts +13 -0
  101. package/dist/types/model/enum/ExampleType.d.ts.map +1 -0
  102. package/dist/types/model/json/BitJson.d.ts +15 -15
  103. package/dist/types/model/json/BitJson.d.ts.map +1 -1
  104. package/dist/types/model/json/BodyBitJson.d.ts +12 -10
  105. package/dist/types/model/json/BodyBitJson.d.ts.map +1 -1
  106. package/dist/types/parser/bitmark/peg/BitmarkPegParserTypes.d.ts +4 -1
  107. package/dist/types/parser/bitmark/peg/BitmarkPegParserTypes.d.ts.map +1 -1
  108. package/dist/types/parser/bitmark/peg/contentProcessors/CardContentProcessor.d.ts.map +1 -1
  109. package/dist/types/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.d.ts +5 -0
  110. package/dist/types/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.d.ts.map +1 -0
  111. package/dist/types/parser/bitmark/peg/contentProcessors/PropertyContentProcessor.d.ts.map +1 -1
  112. package/dist/types/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.d.ts.map +1 -1
  113. package/dist/types/parser/json/JsonParser.d.ts.map +1 -1
  114. package/dist/types/utils/ObjectUtils.d.ts +5 -0
  115. package/dist/types/utils/ObjectUtils.d.ts.map +1 -1
  116. package/package.json +1 -1
@@ -26,11 +26,13 @@ const NodeType_1 = require("../../model/ast/NodeType");
26
26
  const BitType_1 = require("../../model/enum/BitType");
27
27
  const BitmarkVersion_1 = require("../../model/enum/BitmarkVersion");
28
28
  const BodyBitType_1 = require("../../model/enum/BodyBitType");
29
+ const ExampleType_1 = require("../../model/enum/ExampleType");
29
30
  const PropertyKey_1 = require("../../model/enum/PropertyKey");
30
31
  const ResourceType_1 = require("../../model/enum/ResourceType");
31
32
  const TextFormat_1 = require("../../model/enum/TextFormat");
32
33
  const TextParser_1 = require("../../parser/text/TextParser");
33
34
  const ArrayUtils_1 = require("../../utils/ArrayUtils");
35
+ const BooleanUtils_1 = require("../../utils/BooleanUtils");
34
36
  const StringUtils_1 = require("../../utils/StringUtils");
35
37
  const UrlUtils_1 = require("../../utils/UrlUtils");
36
38
  const DEFAULT_OPTIONS = {
@@ -190,6 +192,7 @@ class JsonGenerator {
190
192
  // bitmarkAst -> bits
191
193
  // bitmarkAst -> bits -> bitsValue
192
194
  enter_bitsValue(node, _parent, _route) {
195
+ var _a, _b, _c;
193
196
  const bit = node.value;
194
197
  // Reset
195
198
  this.bitWrapperJson = {
@@ -198,6 +201,39 @@ class JsonGenerator {
198
201
  this.json.push(this.bitWrapperJson);
199
202
  this.bitJson = this.createBitJson(bit);
200
203
  this.bitWrapperJson.bit = this.bitJson;
204
+ // Handle example at the root level - this is bit dependent; configuration is in the bit metadata
205
+ // There is same logic here to select the correct default value of the example is the default is
206
+ // required, and this is bit depenedent.
207
+ // This is ugly, but it is even uglier if the defaults at set in the AST.
208
+ const meta = BitType_1.BitType.getMetadata(bit.bitType);
209
+ const hasRootExample = !!(meta === null || meta === void 0 ? void 0 : meta.rootExampleType);
210
+ const isBoolean = (meta === null || meta === void 0 ? void 0 : meta.rootExampleType) === ExampleType_1.ExampleType.boolean;
211
+ if (hasRootExample) {
212
+ // Calculate the value of the default example
213
+ let defaultExample;
214
+ if (isBoolean) {
215
+ // Boolean example
216
+ defaultExample = true;
217
+ if (bit.bitType === BitType_1.BitType.trueFalse1) {
218
+ if (((_b = (_a = bit.cardNode) === null || _a === void 0 ? void 0 : _a.statement) === null || _b === void 0 ? void 0 : _b.isCorrect) !== undefined) {
219
+ defaultExample = bit.cardNode.statement.isCorrect;
220
+ }
221
+ }
222
+ }
223
+ else {
224
+ // String example
225
+ defaultExample = (_c = ArrayUtils_1.ArrayUtils.asSingle(bit.sampleSolution)) !== null && _c !== void 0 ? _c : '';
226
+ }
227
+ const exampleRes = this.toExample(bit, {
228
+ defaultExample,
229
+ isBoolean,
230
+ });
231
+ this.bitJson.isExample = exampleRes.isExample;
232
+ this.bitJson.example = exampleRes.example;
233
+ }
234
+ else if (bit.isExample) {
235
+ this.bitJson.isExample = true;
236
+ }
201
237
  }
202
238
  exit_bitsValue(_node, _parent, _route) {
203
239
  // Clean up the bit JSON, removing any unwanted values
@@ -363,8 +399,8 @@ class JsonGenerator {
363
399
  enter_statement(node, parent, _route) {
364
400
  var _a, _b;
365
401
  const statement = node.value;
366
- // Ignore statement that is not at the bit level as it is handled elsewhere
367
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
402
+ // Ignore statement that is not at the cardNode level as it is handled elsewhere
403
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
368
404
  return;
369
405
  if (statement) {
370
406
  this.bitJson.statement = (_a = statement.text) !== null && _a !== void 0 ? _a : '';
@@ -373,7 +409,7 @@ class JsonGenerator {
373
409
  }
374
410
  // bitmarkAst -> bits -> bitsValue -> cardNode -> statements -> statementsValue
375
411
  enter_statements(node, parent, _route) {
376
- var _a, _b, _c, _d;
412
+ var _a, _b, _c;
377
413
  const statements = node.value;
378
414
  // Ignore statements that are not at the card node level as they are handled elsewhere
379
415
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
@@ -382,18 +418,19 @@ class JsonGenerator {
382
418
  if (statements) {
383
419
  for (const s of statements) {
384
420
  // Create the statement
385
- const statementJson = Object.assign(Object.assign({ statement: (_a = s.text) !== null && _a !== void 0 ? _a : '', isCorrect: (_b = s.isCorrect) !== null && _b !== void 0 ? _b : false }, this.toItemLeadHintInstruction(s)), this.toExampleAndIsExample(s.example));
421
+ const statementJson = Object.assign(Object.assign({ statement: (_a = s.text) !== null && _a !== void 0 ? _a : '', isCorrect: !!s.isCorrect }, this.toItemLeadHintInstruction(s)), this.toExample(s, {
422
+ defaultExample: !!s.isCorrect,
423
+ isBoolean: true,
424
+ }));
386
425
  // Delete unwanted properties
387
- if (((_c = s.itemLead) === null || _c === void 0 ? void 0 : _c.item) == null)
426
+ if (((_b = s.itemLead) === null || _b === void 0 ? void 0 : _b.item) == null)
388
427
  delete statementJson.item;
389
- if (((_d = s.itemLead) === null || _d === void 0 ? void 0 : _d.lead) == null)
428
+ if (((_c = s.itemLead) === null || _c === void 0 ? void 0 : _c.lead) == null)
390
429
  delete statementJson.lead;
391
430
  if ((s === null || s === void 0 ? void 0 : s.hint) == null)
392
431
  delete statementJson.hint;
393
432
  if ((s === null || s === void 0 ? void 0 : s.instruction) == null)
394
433
  delete statementJson.instruction;
395
- if ((s === null || s === void 0 ? void 0 : s.example) == null)
396
- delete statementJson.example;
397
434
  statementsJson.push(statementJson);
398
435
  }
399
436
  }
@@ -407,13 +444,16 @@ class JsonGenerator {
407
444
  var _a, _b, _c;
408
445
  const choices = node.value;
409
446
  // Ignore choices that are not at the bit level as they are handled elsewhere as quizzes
410
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
447
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
411
448
  return;
412
449
  const choicesJson = [];
413
450
  if (choices) {
414
451
  for (const c of choices) {
415
452
  // Create the choice
416
- const choiceJson = Object.assign({ choice: (_a = c.text) !== null && _a !== void 0 ? _a : '', isCorrect: (_b = c.isCorrect) !== null && _b !== void 0 ? _b : false }, this.toItemLeadHintInstruction(c));
453
+ const choiceJson = Object.assign(Object.assign({ choice: (_a = c.text) !== null && _a !== void 0 ? _a : '', isCorrect: (_b = c.isCorrect) !== null && _b !== void 0 ? _b : false }, this.toItemLeadHintInstruction(c)), this.toExample(c, {
454
+ defaultExample: !!c.isCorrect,
455
+ isBoolean: true,
456
+ }));
417
457
  // Delete unwanted properties
418
458
  if (((_c = c.itemLead) === null || _c === void 0 ? void 0 : _c.lead) == null)
419
459
  delete choiceJson.lead;
@@ -429,14 +469,17 @@ class JsonGenerator {
429
469
  enter_responses(node, parent, _route) {
430
470
  var _a, _b, _c;
431
471
  const responses = node.value;
432
- // Ignore responses that are not at the bit level as they are handled elsewhere as quizzes
433
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
472
+ // Ignore responses that are not at the correct level as they are handled elsewhere as quizzes
473
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.cardNode)
434
474
  return;
435
475
  const responsesJson = [];
436
476
  if (responses) {
437
477
  for (const r of responses) {
438
478
  // Create the response
439
- const responseJson = Object.assign({ response: (_a = r.text) !== null && _a !== void 0 ? _a : '', isCorrect: (_b = r.isCorrect) !== null && _b !== void 0 ? _b : false }, this.toItemLeadHintInstruction(r));
479
+ const responseJson = Object.assign(Object.assign({ response: (_a = r.text) !== null && _a !== void 0 ? _a : '', isCorrect: (_b = r.isCorrect) !== null && _b !== void 0 ? _b : false }, this.toItemLeadHintInstruction(r)), this.toExample(r, {
480
+ defaultExample: !!r.isCorrect,
481
+ isBoolean: true,
482
+ }));
440
483
  // Delete unwanted properties
441
484
  if (((_c = r.itemLead) === null || _c === void 0 ? void 0 : _c.lead) == null)
442
485
  delete responseJson.lead;
@@ -449,7 +492,7 @@ class JsonGenerator {
449
492
  }
450
493
  // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes
451
494
  enter_quizzes(node, _parent, _route) {
452
- var _a, _b, _c, _d, _e, _f, _g;
495
+ var _a, _b, _c, _d, _e, _f, _g, _h;
453
496
  const quizzes = node.value;
454
497
  const quizzesJson = [];
455
498
  if (quizzes) {
@@ -459,7 +502,10 @@ class JsonGenerator {
459
502
  if (q.choices) {
460
503
  for (const c of q.choices) {
461
504
  // Create the choice
462
- const choiceJson = Object.assign({ choice: (_a = c.text) !== null && _a !== void 0 ? _a : '', isCorrect: (_b = c.isCorrect) !== null && _b !== void 0 ? _b : false }, this.toItemLeadHintInstruction(c));
505
+ const choiceJson = Object.assign(Object.assign({ choice: (_a = c.text) !== null && _a !== void 0 ? _a : '', isCorrect: (_b = c.isCorrect) !== null && _b !== void 0 ? _b : false }, this.toItemLeadHintInstruction(c)), this.toExample(c, {
506
+ defaultExample: !!c.isCorrect,
507
+ isBoolean: true,
508
+ }));
463
509
  // Delete unwanted properties
464
510
  if (((_c = q.itemLead) === null || _c === void 0 ? void 0 : _c.lead) == null)
465
511
  delete choiceJson.lead;
@@ -469,9 +515,12 @@ class JsonGenerator {
469
515
  // Responses
470
516
  const responsesJson = [];
471
517
  if (q.responses) {
472
- for (const c of q.responses) {
518
+ for (const r of q.responses) {
473
519
  // Create the choice
474
- const responseJson = Object.assign({ response: (_d = c.text) !== null && _d !== void 0 ? _d : '', isCorrect: (_e = c.isCorrect) !== null && _e !== void 0 ? _e : false }, this.toItemLeadHintInstruction(c));
520
+ const responseJson = Object.assign(Object.assign({ response: (_d = r.text) !== null && _d !== void 0 ? _d : '', isCorrect: (_e = r.isCorrect) !== null && _e !== void 0 ? _e : false }, this.toItemLeadHintInstruction(r)), this.toExample(r, {
521
+ defaultExample: !!r.isCorrect,
522
+ isBoolean: true,
523
+ }));
475
524
  // Delete unwanted properties
476
525
  if (((_f = q.itemLead) === null || _f === void 0 ? void 0 : _f.lead) == null)
477
526
  delete responseJson.lead;
@@ -479,9 +528,9 @@ class JsonGenerator {
479
528
  }
480
529
  }
481
530
  // Create the quiz
482
- const quizJson = Object.assign(Object.assign(Object.assign({}, this.toItemLeadHintInstruction(q)), this.toExampleAndIsExample(q.example)), { choices: q.choices ? choicesJson : undefined, responses: q.responses ? responsesJson : undefined });
531
+ const quizJson = Object.assign(Object.assign({}, this.toItemLeadHintInstruction(q)), { isExample: (_g = q.isExample) !== null && _g !== void 0 ? _g : false, choices: q.choices ? choicesJson : undefined, responses: q.responses ? responsesJson : undefined });
483
532
  // Delete unwanted properties
484
- if (((_g = q.itemLead) === null || _g === void 0 ? void 0 : _g.lead) == null)
533
+ if (((_h = q.itemLead) === null || _h === void 0 ? void 0 : _h.lead) == null)
485
534
  delete quizJson.lead;
486
535
  quizzesJson.push(quizJson);
487
536
  }
@@ -530,7 +579,10 @@ class JsonGenerator {
530
579
  if (pairs) {
531
580
  for (const p of pairs) {
532
581
  // Create the question
533
- const pairJson = Object.assign(Object.assign(Object.assign({ key: (_a = p.key) !== null && _a !== void 0 ? _a : '', keyAudio: p.keyAudio ? this.addAudioResource(p.keyAudio) : undefined, keyImage: p.keyImage ? this.addImageResource(p.keyImage) : undefined, values: (_b = p.values) !== null && _b !== void 0 ? _b : [] }, this.toItemLeadHintInstruction(p)), this.toExampleAndIsExample(p.example)), { isCaseSensitive: (_c = p.isCaseSensitive) !== null && _c !== void 0 ? _c : true, isLongAnswer: (_d = !p.isShortAnswer) !== null && _d !== void 0 ? _d : false });
582
+ const pairJson = Object.assign(Object.assign(Object.assign({ key: (_a = p.key) !== null && _a !== void 0 ? _a : '', keyAudio: p.keyAudio ? this.addAudioResource(p.keyAudio) : undefined, keyImage: p.keyImage ? this.addImageResource(p.keyImage) : undefined, values: (_b = p.values) !== null && _b !== void 0 ? _b : [] }, this.toItemLeadHintInstruction(p)), { isCaseSensitive: (_c = p.isCaseSensitive) !== null && _c !== void 0 ? _c : true, isLongAnswer: (_d = !p.isShortAnswer) !== null && _d !== void 0 ? _d : false }), this.toExample(p, {
583
+ defaultExample: true,
584
+ isBoolean: true,
585
+ }));
534
586
  // Delete unwanted properties
535
587
  if (((_e = p.itemLead) === null || _e === void 0 ? void 0 : _e.lead) == null)
536
588
  delete pairJson.lead;
@@ -555,7 +607,7 @@ class JsonGenerator {
555
607
  }
556
608
  // bitmarkAst -> bits -> bitsValue -> cardNode -> matrix
557
609
  enter_matrix(node, _parent, _route) {
558
- var _a, _b, _c, _d, _e, _f;
610
+ var _a, _b, _c, _d, _e, _f, _g;
559
611
  const matrix = node.value;
560
612
  const matrixJsonArray = [];
561
613
  if (matrix) {
@@ -565,23 +617,24 @@ class JsonGenerator {
565
617
  if (m.cells) {
566
618
  for (const c of m.cells) {
567
619
  // Create the choice
568
- const matrixCellJson = Object.assign(Object.assign({ values: (_a = c.values) !== null && _a !== void 0 ? _a : [] }, this.toItemLeadHintInstruction(c)), this.toExampleAndIsExample(c.example));
620
+ const matrixCellJson = Object.assign(Object.assign({ values: (_a = c.values) !== null && _a !== void 0 ? _a : [] }, this.toItemLeadHintInstruction(c)), this.toExample(c, {
621
+ defaultExample: true,
622
+ isBoolean: true,
623
+ }));
569
624
  // Delete unwanted properties
570
625
  if (((_b = c.itemLead) === null || _b === void 0 ? void 0 : _b.lead) == null)
571
626
  delete matrixCellJson.lead;
572
627
  if (c.hint == null)
573
628
  delete matrixCellJson.hint;
574
- if (c.example == null)
575
- delete matrixCellJson.isExample;
576
- if (c.example == null)
577
- delete matrixCellJson.example;
578
629
  matrixCellsJson.push(matrixCellJson);
579
630
  }
580
631
  }
581
632
  // Create the matrix
582
- const matrixJson = Object.assign(Object.assign(Object.assign({ key: (_c = m.key) !== null && _c !== void 0 ? _c : '', cells: matrixCellsJson !== null && matrixCellsJson !== void 0 ? matrixCellsJson : [] }, this.toItemLeadHintInstruction(m)), this.toExampleAndIsExample(m.example)), { isCaseSensitive: (_d = m.isCaseSensitive) !== null && _d !== void 0 ? _d : true, isLongAnswer: (_e = !m.isShortAnswer) !== null && _e !== void 0 ? _e : false });
633
+ const matrixJson = Object.assign(Object.assign({ key: (_c = m.key) !== null && _c !== void 0 ? _c : '', cells: matrixCellsJson !== null && matrixCellsJson !== void 0 ? matrixCellsJson : [] }, this.toItemLeadHintInstruction(m)), {
634
+ // ...this.toExample(m.example, m.isExample),
635
+ isCaseSensitive: (_d = m.isCaseSensitive) !== null && _d !== void 0 ? _d : true, isLongAnswer: (_e = !m.isShortAnswer) !== null && _e !== void 0 ? _e : false, isExample: (_f = m.isExample) !== null && _f !== void 0 ? _f : false });
583
636
  // Delete unwanted properties
584
- if (((_f = m.itemLead) === null || _f === void 0 ? void 0 : _f.lead) == null)
637
+ if (((_g = m.itemLead) === null || _g === void 0 ? void 0 : _g.lead) == null)
585
638
  delete matrixJson.lead;
586
639
  if (m.instruction == null)
587
640
  delete matrixJson.instruction;
@@ -600,9 +653,12 @@ class JsonGenerator {
600
653
  if (questions) {
601
654
  for (const q of questions) {
602
655
  // Create the question
603
- const questionJson = Object.assign(Object.assign(Object.assign({ question: (_a = q.question) !== null && _a !== void 0 ? _a : '', partialAnswer: (_b = ArrayUtils_1.ArrayUtils.asSingle(q.partialAnswer)) !== null && _b !== void 0 ? _b : '', sampleSolution: (_c = q.sampleSolution) !== null && _c !== void 0 ? _c : '' }, this.toItemLeadHintInstruction(q)), this.toExampleAndIsExample(q.example)), {
656
+ const questionJson = Object.assign(Object.assign(Object.assign({ question: (_a = q.question) !== null && _a !== void 0 ? _a : '', partialAnswer: (_b = ArrayUtils_1.ArrayUtils.asSingle(q.partialAnswer)) !== null && _b !== void 0 ? _b : '', sampleSolution: (_c = q.sampleSolution) !== null && _c !== void 0 ? _c : '' }, this.toItemLeadHintInstruction(q)), {
604
657
  // isCaseSensitive: q.isCaseSensitive ?? true,
605
- isShortAnswer: (_d = q.isShortAnswer) !== null && _d !== void 0 ? _d : true });
658
+ isShortAnswer: (_d = q.isShortAnswer) !== null && _d !== void 0 ? _d : true }), this.toExample(q, {
659
+ defaultExample: q.sampleSolution || '',
660
+ isBoolean: false,
661
+ }));
606
662
  // Delete unwanted properties
607
663
  if (((_e = q.itemLead) === null || _e === void 0 ? void 0 : _e.lead) == null)
608
664
  delete questionJson.lead;
@@ -698,16 +754,6 @@ class JsonGenerator {
698
754
  return;
699
755
  this.bitJson.instruction = this.toTextAstOrString(instruction);
700
756
  }
701
- // bitmarkAst -> bits -> bitsValue -> example
702
- leaf_example(node, parent, _route) {
703
- const example = node.value;
704
- // Ignore example that is not at the bit level as it are handled elsewhere
705
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType_1.NodeType.bitsValue)
706
- return;
707
- const res = this.toExampleAndIsExample(example);
708
- this.bitJson.isExample = res.isExample;
709
- this.bitJson.example = res.example;
710
- }
711
757
  // bitmarkAst -> bits -> footer -> footerText
712
758
  leaf_footerText(node, _parent, _route) {
713
759
  const footer = node.value;
@@ -813,20 +859,27 @@ class JsonGenerator {
813
859
  createGapJson(gap) {
814
860
  var _a;
815
861
  const data = gap.data;
862
+ const defaultExample = data.solutions && data.solutions.length > 0 ? data.solutions[0] : '';
816
863
  // Create the gap
817
- const gapJson = Object.assign(Object.assign(Object.assign({ type: 'gap', solutions: data.solutions }, this.toItemLeadHintInstruction(data)), this.toExampleAndIsExample(data.example)), { isCaseSensitive: (_a = data.isCaseSensitive) !== null && _a !== void 0 ? _a : true });
864
+ const gapJson = Object.assign(Object.assign(Object.assign(Object.assign({ type: 'gap' }, this.toItemLeadHintInstruction(data)), { isCaseSensitive: (_a = data.isCaseSensitive) !== null && _a !== void 0 ? _a : true }), this.toExample(data, {
865
+ defaultExample,
866
+ isBoolean: false,
867
+ })), { solutions: data.solutions });
818
868
  // Remove unwanted properties
819
869
  if (!gapJson.lead)
820
870
  delete gapJson.lead;
821
871
  return gapJson;
822
872
  }
823
873
  createSelectJson(select) {
824
- var _a, _b, _c;
874
+ var _a, _b, _c, _d;
825
875
  const data = select.data;
826
876
  // Create the select options
827
877
  const options = [];
828
878
  for (const option of data.options) {
829
- const optionJson = Object.assign(Object.assign({ text: option.text, isCorrect: (_a = option.isCorrect) !== null && _a !== void 0 ? _a : false }, this.toItemLeadHintInstruction(option)), this.toExampleAndIsExample(option.example));
879
+ const optionJson = Object.assign(Object.assign({ text: option.text, isCorrect: (_a = option.isCorrect) !== null && _a !== void 0 ? _a : false }, this.toItemLeadHintInstruction(option)), this.toExample(option, {
880
+ defaultExample: !!option.isCorrect,
881
+ isBoolean: true,
882
+ }));
830
883
  // Remove unwanted properties
831
884
  if (!optionJson.item)
832
885
  delete optionJson.item;
@@ -834,28 +887,27 @@ class JsonGenerator {
834
887
  delete optionJson.lead;
835
888
  if (!optionJson.instruction)
836
889
  delete optionJson.instruction;
837
- if (!optionJson.example)
838
- delete optionJson.example;
839
- if (!optionJson.isExample)
840
- delete optionJson.isExample;
841
890
  if (!optionJson.isCaseSensitive)
842
891
  delete optionJson.isCaseSensitive;
843
892
  options.push(optionJson);
844
893
  }
845
894
  // Create the select
846
- const selectJson = Object.assign(Object.assign({ type: 'select', prefix: (_b = data.prefix) !== null && _b !== void 0 ? _b : '', options, postfix: (_c = data.postfix) !== null && _c !== void 0 ? _c : '' }, this.toItemLeadHintInstruction(data)), this.toExampleAndIsExample(data.example));
895
+ const selectJson = Object.assign(Object.assign({ type: 'select', prefix: (_b = data.prefix) !== null && _b !== void 0 ? _b : '', postfix: (_c = data.postfix) !== null && _c !== void 0 ? _c : '' }, this.toItemLeadHintInstruction(data)), { isExample: (_d = data.isExample) !== null && _d !== void 0 ? _d : false, options });
847
896
  // Remove unwanted properties
848
897
  if (!selectJson.lead)
849
898
  delete selectJson.lead;
850
899
  return selectJson;
851
900
  }
852
901
  createHighlightJson(highlight) {
853
- var _a, _b, _c, _d;
902
+ var _a, _b, _c, _d, _e;
854
903
  const data = highlight.data;
855
904
  // Create the highlight options
856
905
  const texts = [];
857
906
  for (const text of data.texts) {
858
- const textJson = Object.assign(Object.assign({ text: text.text, isCorrect: (_a = text.isCorrect) !== null && _a !== void 0 ? _a : false, isHighlighted: (_b = text.isHighlighted) !== null && _b !== void 0 ? _b : false }, this.toItemLeadHintInstruction(text)), this.toExampleAndIsExample(text.example));
907
+ const textJson = Object.assign(Object.assign({ text: text.text, isCorrect: (_a = text.isCorrect) !== null && _a !== void 0 ? _a : false, isHighlighted: (_b = text.isHighlighted) !== null && _b !== void 0 ? _b : false }, this.toItemLeadHintInstruction(text)), this.toExample(text, {
908
+ defaultExample: !!text.isCorrect,
909
+ isBoolean: true,
910
+ }));
859
911
  // Remove unwanted properties
860
912
  if (!textJson.item)
861
913
  delete textJson.item;
@@ -863,16 +915,12 @@ class JsonGenerator {
863
915
  delete textJson.lead;
864
916
  if (!textJson.hint)
865
917
  delete textJson.hint;
866
- if (!textJson.example)
867
- delete textJson.example;
868
- if (!textJson.isExample)
869
- delete textJson.isExample;
870
918
  if (!textJson.isCaseSensitive)
871
919
  delete textJson.isCaseSensitive;
872
920
  texts.push(textJson);
873
921
  }
874
922
  // Create the select
875
- const highlightJson = Object.assign(Object.assign({ type: 'highlight', prefix: (_c = data.prefix) !== null && _c !== void 0 ? _c : '', texts, postfix: (_d = data.postfix) !== null && _d !== void 0 ? _d : '' }, this.toItemLeadHintInstruction(data)), this.toExampleAndIsExample(data.example));
923
+ const highlightJson = Object.assign(Object.assign({ type: 'highlight', prefix: (_c = data.prefix) !== null && _c !== void 0 ? _c : '', postfix: (_d = data.postfix) !== null && _d !== void 0 ? _d : '' }, this.toItemLeadHintInstruction(data)), { isExample: (_e = data.isExample) !== null && _e !== void 0 ? _e : false, texts });
876
924
  // Remove unwanted properties
877
925
  if (!highlightJson.lead)
878
926
  delete highlightJson.lead;
@@ -1410,19 +1458,27 @@ class JsonGenerator {
1410
1458
  instruction: this.toTextAstOrString((_f = item.instruction) !== null && _f !== void 0 ? _f : ''),
1411
1459
  };
1412
1460
  }
1413
- toExampleAndIsExample(exampleIn) {
1414
- let isExample = false;
1415
- let example = this.textDefault;
1416
- if (exampleIn === true) {
1417
- isExample = true;
1461
+ toExample(node, options) {
1462
+ const { isExample, example, isDefaultExample } = node;
1463
+ const { defaultExample, isBoolean } = options;
1464
+ if (!isExample) {
1465
+ return {
1466
+ isExample: false,
1467
+ example: null,
1468
+ };
1469
+ }
1470
+ let exampleValue;
1471
+ if (isDefaultExample) {
1472
+ exampleValue = isBoolean
1473
+ ? BooleanUtils_1.BooleanUtils.toBoolean(defaultExample)
1474
+ : this.toTextAstOrString(defaultExample);
1418
1475
  }
1419
- else if (exampleIn) {
1420
- isExample = true;
1421
- example = this.toTextAstOrString(exampleIn);
1476
+ else {
1477
+ exampleValue = isBoolean ? BooleanUtils_1.BooleanUtils.toBoolean(example) : this.toTextAstOrString(example);
1422
1478
  }
1423
1479
  return {
1424
- isExample,
1425
- example,
1480
+ isExample: true,
1481
+ example: exampleValue,
1426
1482
  };
1427
1483
  }
1428
1484
  addProperty(
@@ -1608,8 +1664,8 @@ class JsonGenerator {
1608
1664
  hint: undefined,
1609
1665
  instruction: undefined,
1610
1666
  // Example
1611
- example: undefined,
1612
1667
  isExample: undefined,
1668
+ example: undefined,
1613
1669
  // Partner .conversion-xxx only
1614
1670
  partner: undefined,
1615
1671
  // Extra Properties
@@ -1668,7 +1724,6 @@ class JsonGenerator {
1668
1724
  case BitType_1.BitType._error:
1669
1725
  break;
1670
1726
  case BitType_1.BitType.article:
1671
- case BitType_1.BitType.highlightText:
1672
1727
  case BitType_1.BitType.message:
1673
1728
  case BitType_1.BitType.sampleSolution:
1674
1729
  case BitType_1.BitType.page:
@@ -1684,12 +1739,19 @@ class JsonGenerator {
1684
1739
  if (bitJson.isExample == null)
1685
1740
  bitJson.isExample = false;
1686
1741
  if (bitJson.example == null)
1687
- bitJson.example = this.textDefault;
1742
+ bitJson.example = null;
1688
1743
  if (bitJson.body == null)
1689
1744
  bitJson.body = this.bodyDefault;
1690
1745
  break;
1746
+ // Default, but with no 'example' at the bit level.
1747
+ case BitType_1.BitType.cloze:
1748
+ case BitType_1.BitType.clozeInstructionGrouped:
1749
+ case BitType_1.BitType.clozeSolutionGrouped:
1691
1750
  case BitType_1.BitType.multipleChoice1:
1692
1751
  case BitType_1.BitType.multipleResponse1:
1752
+ case BitType_1.BitType.multipleChoiceText:
1753
+ case BitType_1.BitType.highlightText:
1754
+ case BitType_1.BitType.clozeAndMultipleChoiceText:
1693
1755
  case BitType_1.BitType.sequence:
1694
1756
  if (bitJson.item == null)
1695
1757
  bitJson.item = this.textDefault;
@@ -1699,11 +1761,25 @@ class JsonGenerator {
1699
1761
  bitJson.instruction = this.textDefault;
1700
1762
  if (bitJson.isExample == null)
1701
1763
  bitJson.isExample = false;
1702
- if (bitJson.example == null)
1703
- bitJson.example = this.textDefault;
1704
1764
  if (bitJson.body == null)
1705
1765
  bitJson.body = this.bodyDefault;
1706
1766
  break;
1767
+ // Default with a card (and hence a footer possibility)
1768
+ case BitType_1.BitType.multipleChoice:
1769
+ case BitType_1.BitType.multipleResponse:
1770
+ if (bitJson.item == null)
1771
+ bitJson.item = this.textDefault;
1772
+ if (bitJson.hint == null)
1773
+ bitJson.hint = this.textDefault;
1774
+ if (bitJson.instruction == null)
1775
+ bitJson.instruction = this.textDefault;
1776
+ if (bitJson.isExample == null)
1777
+ bitJson.isExample = false;
1778
+ if (bitJson.body == null)
1779
+ bitJson.body = this.bodyDefault;
1780
+ if (bitJson.footer == null)
1781
+ bitJson.footer = this.textDefault;
1782
+ break;
1707
1783
  case BitType_1.BitType.essay:
1708
1784
  if (bitJson.item == null)
1709
1785
  bitJson.item = this.textDefault;
@@ -1714,7 +1790,7 @@ class JsonGenerator {
1714
1790
  if (bitJson.isExample == null)
1715
1791
  bitJson.isExample = false;
1716
1792
  if (bitJson.example == null)
1717
- bitJson.example = this.textDefault;
1793
+ bitJson.example = null;
1718
1794
  if (bitJson.body == null)
1719
1795
  bitJson.body = this.bodyDefault;
1720
1796
  if (bitJson.partialAnswer == null)
@@ -1732,6 +1808,8 @@ class JsonGenerator {
1732
1808
  bitJson.instruction = this.textDefault;
1733
1809
  if (bitJson.isExample == null)
1734
1810
  bitJson.isExample = false;
1811
+ if (bitJson.example == null)
1812
+ bitJson.example = null;
1735
1813
  if (bitJson.isCorrect == null)
1736
1814
  bitJson.isCorrect = false;
1737
1815
  if (bitJson.body == null)
@@ -1746,6 +1824,8 @@ class JsonGenerator {
1746
1824
  bitJson.hint = this.textDefault;
1747
1825
  if (bitJson.instruction == null)
1748
1826
  bitJson.instruction = this.textDefault;
1827
+ if (bitJson.isExample == null)
1828
+ bitJson.isExample = false;
1749
1829
  if (bitJson.labelFalse == null)
1750
1830
  bitJson.labelFalse = '';
1751
1831
  if (bitJson.labelTrue == null)
@@ -1761,7 +1841,7 @@ class JsonGenerator {
1761
1841
  if (bitJson.isExample == null)
1762
1842
  bitJson.isExample = false;
1763
1843
  if (bitJson.example == null)
1764
- bitJson.example = this.textDefault;
1844
+ bitJson.example = null;
1765
1845
  if (bitJson.toc == null)
1766
1846
  bitJson.toc = true; // Always set on chapter bits?
1767
1847
  if (bitJson.progress == null)
@@ -1771,19 +1851,6 @@ class JsonGenerator {
1771
1851
  if (bitJson.body == null)
1772
1852
  bitJson.body = this.bodyDefault;
1773
1853
  break;
1774
- case BitType_1.BitType.multipleChoice:
1775
- case BitType_1.BitType.multipleResponse:
1776
- if (bitJson.item == null)
1777
- bitJson.item = this.textDefault;
1778
- if (bitJson.hint == null)
1779
- bitJson.hint = this.textDefault;
1780
- if (bitJson.instruction == null)
1781
- bitJson.instruction = this.textDefault;
1782
- if (bitJson.body == null)
1783
- bitJson.body = this.bodyDefault;
1784
- if (bitJson.footer == null)
1785
- bitJson.footer = this.textDefault;
1786
- break;
1787
1854
  case BitType_1.BitType.interview:
1788
1855
  case BitType_1.BitType.interviewInstructionGrouped:
1789
1856
  if (bitJson.item == null)
@@ -1792,6 +1859,8 @@ class JsonGenerator {
1792
1859
  bitJson.hint = this.textDefault;
1793
1860
  if (bitJson.instruction == null)
1794
1861
  bitJson.instruction = this.textDefault;
1862
+ if (bitJson.isExample == null)
1863
+ bitJson.isExample = false;
1795
1864
  if (bitJson.body == null)
1796
1865
  bitJson.body = this.bodyDefault;
1797
1866
  if (bitJson.footer == null)
@@ -1836,7 +1905,7 @@ class JsonGenerator {
1836
1905
  if (bitJson.isExample == null)
1837
1906
  bitJson.isExample = false;
1838
1907
  if (bitJson.example == null)
1839
- bitJson.example = this.textDefault;
1908
+ bitJson.example = null;
1840
1909
  if (bitJson.isTracked == null)
1841
1910
  bitJson.isTracked = true;
1842
1911
  if (bitJson.isInfoOnly == null)
@@ -1856,7 +1925,7 @@ class JsonGenerator {
1856
1925
  if (bitJson.isExample == null)
1857
1926
  bitJson.isExample = false;
1858
1927
  if (bitJson.example == null)
1859
- bitJson.example = this.textDefault;
1928
+ bitJson.example = null;
1860
1929
  if (bitJson.body == null)
1861
1930
  bitJson.body = this.bodyDefault;
1862
1931
  break;
@@ -1958,7 +2027,7 @@ class JsonGenerator {
1958
2027
  if (bitJson.instruction == null)
1959
2028
  delete bitJson.instruction;
1960
2029
  // Example
1961
- if (bitJson.example == null)
2030
+ if (bitJson.example === undefined)
1962
2031
  delete bitJson.example;
1963
2032
  if (bitJson.isExample == null)
1964
2033
  delete bitJson.isExample;