@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
@@ -23,11 +23,13 @@ import { NodeType } from '../../model/ast/NodeType';
23
23
  import { BitType } from '../../model/enum/BitType';
24
24
  import { BitmarkVersion, DEFAULT_BITMARK_VERSION } from '../../model/enum/BitmarkVersion';
25
25
  import { BodyBitType } from '../../model/enum/BodyBitType';
26
+ import { ExampleType } from '../../model/enum/ExampleType';
26
27
  import { PropertyKey } from '../../model/enum/PropertyKey';
27
28
  import { ResourceType } from '../../model/enum/ResourceType';
28
29
  import { TextFormat } from '../../model/enum/TextFormat';
29
30
  import { TextParser } from '../../parser/text/TextParser';
30
31
  import { ArrayUtils } from '../../utils/ArrayUtils';
32
+ import { BooleanUtils } from '../../utils/BooleanUtils';
31
33
  import { StringUtils } from '../../utils/StringUtils';
32
34
  import { UrlUtils } from '../../utils/UrlUtils';
33
35
  const DEFAULT_OPTIONS = {
@@ -187,6 +189,7 @@ class JsonGenerator {
187
189
  // bitmarkAst -> bits
188
190
  // bitmarkAst -> bits -> bitsValue
189
191
  enter_bitsValue(node, _parent, _route) {
192
+ var _a, _b, _c;
190
193
  const bit = node.value;
191
194
  // Reset
192
195
  this.bitWrapperJson = {
@@ -195,6 +198,39 @@ class JsonGenerator {
195
198
  this.json.push(this.bitWrapperJson);
196
199
  this.bitJson = this.createBitJson(bit);
197
200
  this.bitWrapperJson.bit = this.bitJson;
201
+ // Handle example at the root level - this is bit dependent; configuration is in the bit metadata
202
+ // There is same logic here to select the correct default value of the example is the default is
203
+ // required, and this is bit depenedent.
204
+ // This is ugly, but it is even uglier if the defaults at set in the AST.
205
+ const meta = BitType.getMetadata(bit.bitType);
206
+ const hasRootExample = !!(meta === null || meta === void 0 ? void 0 : meta.rootExampleType);
207
+ const isBoolean = (meta === null || meta === void 0 ? void 0 : meta.rootExampleType) === ExampleType.boolean;
208
+ if (hasRootExample) {
209
+ // Calculate the value of the default example
210
+ let defaultExample;
211
+ if (isBoolean) {
212
+ // Boolean example
213
+ defaultExample = true;
214
+ if (bit.bitType === BitType.trueFalse1) {
215
+ if (((_b = (_a = bit.cardNode) === null || _a === void 0 ? void 0 : _a.statement) === null || _b === void 0 ? void 0 : _b.isCorrect) !== undefined) {
216
+ defaultExample = bit.cardNode.statement.isCorrect;
217
+ }
218
+ }
219
+ }
220
+ else {
221
+ // String example
222
+ defaultExample = (_c = ArrayUtils.asSingle(bit.sampleSolution)) !== null && _c !== void 0 ? _c : '';
223
+ }
224
+ const exampleRes = this.toExample(bit, {
225
+ defaultExample,
226
+ isBoolean,
227
+ });
228
+ this.bitJson.isExample = exampleRes.isExample;
229
+ this.bitJson.example = exampleRes.example;
230
+ }
231
+ else if (bit.isExample) {
232
+ this.bitJson.isExample = true;
233
+ }
198
234
  }
199
235
  exit_bitsValue(_node, _parent, _route) {
200
236
  // Clean up the bit JSON, removing any unwanted values
@@ -360,8 +396,8 @@ class JsonGenerator {
360
396
  enter_statement(node, parent, _route) {
361
397
  var _a, _b;
362
398
  const statement = node.value;
363
- // Ignore statement that is not at the bit level as it is handled elsewhere
364
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
399
+ // Ignore statement that is not at the cardNode level as it is handled elsewhere
400
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.cardNode)
365
401
  return;
366
402
  if (statement) {
367
403
  this.bitJson.statement = (_a = statement.text) !== null && _a !== void 0 ? _a : '';
@@ -370,7 +406,7 @@ class JsonGenerator {
370
406
  }
371
407
  // bitmarkAst -> bits -> bitsValue -> cardNode -> statements -> statementsValue
372
408
  enter_statements(node, parent, _route) {
373
- var _a, _b, _c, _d;
409
+ var _a, _b, _c;
374
410
  const statements = node.value;
375
411
  // Ignore statements that are not at the card node level as they are handled elsewhere
376
412
  if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.cardNode)
@@ -379,18 +415,19 @@ class JsonGenerator {
379
415
  if (statements) {
380
416
  for (const s of statements) {
381
417
  // Create the statement
382
- 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));
418
+ const statementJson = Object.assign(Object.assign({ statement: (_a = s.text) !== null && _a !== void 0 ? _a : '', isCorrect: !!s.isCorrect }, this.toItemLeadHintInstruction(s)), this.toExample(s, {
419
+ defaultExample: !!s.isCorrect,
420
+ isBoolean: true,
421
+ }));
383
422
  // Delete unwanted properties
384
- if (((_c = s.itemLead) === null || _c === void 0 ? void 0 : _c.item) == null)
423
+ if (((_b = s.itemLead) === null || _b === void 0 ? void 0 : _b.item) == null)
385
424
  delete statementJson.item;
386
- if (((_d = s.itemLead) === null || _d === void 0 ? void 0 : _d.lead) == null)
425
+ if (((_c = s.itemLead) === null || _c === void 0 ? void 0 : _c.lead) == null)
387
426
  delete statementJson.lead;
388
427
  if ((s === null || s === void 0 ? void 0 : s.hint) == null)
389
428
  delete statementJson.hint;
390
429
  if ((s === null || s === void 0 ? void 0 : s.instruction) == null)
391
430
  delete statementJson.instruction;
392
- if ((s === null || s === void 0 ? void 0 : s.example) == null)
393
- delete statementJson.example;
394
431
  statementsJson.push(statementJson);
395
432
  }
396
433
  }
@@ -404,13 +441,16 @@ class JsonGenerator {
404
441
  var _a, _b, _c;
405
442
  const choices = node.value;
406
443
  // Ignore choices that are not at the bit level as they are handled elsewhere as quizzes
407
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
444
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.cardNode)
408
445
  return;
409
446
  const choicesJson = [];
410
447
  if (choices) {
411
448
  for (const c of choices) {
412
449
  // Create the choice
413
- 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));
450
+ 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, {
451
+ defaultExample: !!c.isCorrect,
452
+ isBoolean: true,
453
+ }));
414
454
  // Delete unwanted properties
415
455
  if (((_c = c.itemLead) === null || _c === void 0 ? void 0 : _c.lead) == null)
416
456
  delete choiceJson.lead;
@@ -426,14 +466,17 @@ class JsonGenerator {
426
466
  enter_responses(node, parent, _route) {
427
467
  var _a, _b, _c;
428
468
  const responses = node.value;
429
- // Ignore responses that are not at the bit level as they are handled elsewhere as quizzes
430
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
469
+ // Ignore responses that are not at the correct level as they are handled elsewhere as quizzes
470
+ if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.cardNode)
431
471
  return;
432
472
  const responsesJson = [];
433
473
  if (responses) {
434
474
  for (const r of responses) {
435
475
  // Create the response
436
- 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));
476
+ 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, {
477
+ defaultExample: !!r.isCorrect,
478
+ isBoolean: true,
479
+ }));
437
480
  // Delete unwanted properties
438
481
  if (((_c = r.itemLead) === null || _c === void 0 ? void 0 : _c.lead) == null)
439
482
  delete responseJson.lead;
@@ -446,7 +489,7 @@ class JsonGenerator {
446
489
  }
447
490
  // bitmarkAst -> bits -> bitsValue -> cardNode -> quizzes
448
491
  enter_quizzes(node, _parent, _route) {
449
- var _a, _b, _c, _d, _e, _f, _g;
492
+ var _a, _b, _c, _d, _e, _f, _g, _h;
450
493
  const quizzes = node.value;
451
494
  const quizzesJson = [];
452
495
  if (quizzes) {
@@ -456,7 +499,10 @@ class JsonGenerator {
456
499
  if (q.choices) {
457
500
  for (const c of q.choices) {
458
501
  // Create the choice
459
- 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));
502
+ 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, {
503
+ defaultExample: !!c.isCorrect,
504
+ isBoolean: true,
505
+ }));
460
506
  // Delete unwanted properties
461
507
  if (((_c = q.itemLead) === null || _c === void 0 ? void 0 : _c.lead) == null)
462
508
  delete choiceJson.lead;
@@ -466,9 +512,12 @@ class JsonGenerator {
466
512
  // Responses
467
513
  const responsesJson = [];
468
514
  if (q.responses) {
469
- for (const c of q.responses) {
515
+ for (const r of q.responses) {
470
516
  // Create the choice
471
- 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));
517
+ 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, {
518
+ defaultExample: !!r.isCorrect,
519
+ isBoolean: true,
520
+ }));
472
521
  // Delete unwanted properties
473
522
  if (((_f = q.itemLead) === null || _f === void 0 ? void 0 : _f.lead) == null)
474
523
  delete responseJson.lead;
@@ -476,9 +525,9 @@ class JsonGenerator {
476
525
  }
477
526
  }
478
527
  // Create the quiz
479
- 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 });
528
+ 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 });
480
529
  // Delete unwanted properties
481
- if (((_g = q.itemLead) === null || _g === void 0 ? void 0 : _g.lead) == null)
530
+ if (((_h = q.itemLead) === null || _h === void 0 ? void 0 : _h.lead) == null)
482
531
  delete quizJson.lead;
483
532
  quizzesJson.push(quizJson);
484
533
  }
@@ -527,7 +576,10 @@ class JsonGenerator {
527
576
  if (pairs) {
528
577
  for (const p of pairs) {
529
578
  // Create the question
530
- 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 });
579
+ 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, {
580
+ defaultExample: true,
581
+ isBoolean: true,
582
+ }));
531
583
  // Delete unwanted properties
532
584
  if (((_e = p.itemLead) === null || _e === void 0 ? void 0 : _e.lead) == null)
533
585
  delete pairJson.lead;
@@ -552,7 +604,7 @@ class JsonGenerator {
552
604
  }
553
605
  // bitmarkAst -> bits -> bitsValue -> cardNode -> matrix
554
606
  enter_matrix(node, _parent, _route) {
555
- var _a, _b, _c, _d, _e, _f;
607
+ var _a, _b, _c, _d, _e, _f, _g;
556
608
  const matrix = node.value;
557
609
  const matrixJsonArray = [];
558
610
  if (matrix) {
@@ -562,23 +614,24 @@ class JsonGenerator {
562
614
  if (m.cells) {
563
615
  for (const c of m.cells) {
564
616
  // Create the choice
565
- const matrixCellJson = Object.assign(Object.assign({ values: (_a = c.values) !== null && _a !== void 0 ? _a : [] }, this.toItemLeadHintInstruction(c)), this.toExampleAndIsExample(c.example));
617
+ const matrixCellJson = Object.assign(Object.assign({ values: (_a = c.values) !== null && _a !== void 0 ? _a : [] }, this.toItemLeadHintInstruction(c)), this.toExample(c, {
618
+ defaultExample: true,
619
+ isBoolean: true,
620
+ }));
566
621
  // Delete unwanted properties
567
622
  if (((_b = c.itemLead) === null || _b === void 0 ? void 0 : _b.lead) == null)
568
623
  delete matrixCellJson.lead;
569
624
  if (c.hint == null)
570
625
  delete matrixCellJson.hint;
571
- if (c.example == null)
572
- delete matrixCellJson.isExample;
573
- if (c.example == null)
574
- delete matrixCellJson.example;
575
626
  matrixCellsJson.push(matrixCellJson);
576
627
  }
577
628
  }
578
629
  // Create the matrix
579
- 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 });
630
+ 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)), {
631
+ // ...this.toExample(m.example, m.isExample),
632
+ 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 });
580
633
  // Delete unwanted properties
581
- if (((_f = m.itemLead) === null || _f === void 0 ? void 0 : _f.lead) == null)
634
+ if (((_g = m.itemLead) === null || _g === void 0 ? void 0 : _g.lead) == null)
582
635
  delete matrixJson.lead;
583
636
  if (m.instruction == null)
584
637
  delete matrixJson.instruction;
@@ -597,9 +650,12 @@ class JsonGenerator {
597
650
  if (questions) {
598
651
  for (const q of questions) {
599
652
  // Create the question
600
- const questionJson = Object.assign(Object.assign(Object.assign({ question: (_a = q.question) !== null && _a !== void 0 ? _a : '', partialAnswer: (_b = 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)), {
653
+ const questionJson = Object.assign(Object.assign(Object.assign({ question: (_a = q.question) !== null && _a !== void 0 ? _a : '', partialAnswer: (_b = ArrayUtils.asSingle(q.partialAnswer)) !== null && _b !== void 0 ? _b : '', sampleSolution: (_c = q.sampleSolution) !== null && _c !== void 0 ? _c : '' }, this.toItemLeadHintInstruction(q)), {
601
654
  // isCaseSensitive: q.isCaseSensitive ?? true,
602
- isShortAnswer: (_d = q.isShortAnswer) !== null && _d !== void 0 ? _d : true });
655
+ isShortAnswer: (_d = q.isShortAnswer) !== null && _d !== void 0 ? _d : true }), this.toExample(q, {
656
+ defaultExample: q.sampleSolution || '',
657
+ isBoolean: false,
658
+ }));
603
659
  // Delete unwanted properties
604
660
  if (((_e = q.itemLead) === null || _e === void 0 ? void 0 : _e.lead) == null)
605
661
  delete questionJson.lead;
@@ -695,16 +751,6 @@ class JsonGenerator {
695
751
  return;
696
752
  this.bitJson.instruction = this.toTextAstOrString(instruction);
697
753
  }
698
- // bitmarkAst -> bits -> bitsValue -> example
699
- leaf_example(node, parent, _route) {
700
- const example = node.value;
701
- // Ignore example that is not at the bit level as it are handled elsewhere
702
- if ((parent === null || parent === void 0 ? void 0 : parent.key) !== NodeType.bitsValue)
703
- return;
704
- const res = this.toExampleAndIsExample(example);
705
- this.bitJson.isExample = res.isExample;
706
- this.bitJson.example = res.example;
707
- }
708
754
  // bitmarkAst -> bits -> footer -> footerText
709
755
  leaf_footerText(node, _parent, _route) {
710
756
  const footer = node.value;
@@ -810,20 +856,27 @@ class JsonGenerator {
810
856
  createGapJson(gap) {
811
857
  var _a;
812
858
  const data = gap.data;
859
+ const defaultExample = data.solutions && data.solutions.length > 0 ? data.solutions[0] : '';
813
860
  // Create the gap
814
- 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 });
861
+ 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, {
862
+ defaultExample,
863
+ isBoolean: false,
864
+ })), { solutions: data.solutions });
815
865
  // Remove unwanted properties
816
866
  if (!gapJson.lead)
817
867
  delete gapJson.lead;
818
868
  return gapJson;
819
869
  }
820
870
  createSelectJson(select) {
821
- var _a, _b, _c;
871
+ var _a, _b, _c, _d;
822
872
  const data = select.data;
823
873
  // Create the select options
824
874
  const options = [];
825
875
  for (const option of data.options) {
826
- 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));
876
+ 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, {
877
+ defaultExample: !!option.isCorrect,
878
+ isBoolean: true,
879
+ }));
827
880
  // Remove unwanted properties
828
881
  if (!optionJson.item)
829
882
  delete optionJson.item;
@@ -831,28 +884,27 @@ class JsonGenerator {
831
884
  delete optionJson.lead;
832
885
  if (!optionJson.instruction)
833
886
  delete optionJson.instruction;
834
- if (!optionJson.example)
835
- delete optionJson.example;
836
- if (!optionJson.isExample)
837
- delete optionJson.isExample;
838
887
  if (!optionJson.isCaseSensitive)
839
888
  delete optionJson.isCaseSensitive;
840
889
  options.push(optionJson);
841
890
  }
842
891
  // Create the select
843
- 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));
892
+ 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 });
844
893
  // Remove unwanted properties
845
894
  if (!selectJson.lead)
846
895
  delete selectJson.lead;
847
896
  return selectJson;
848
897
  }
849
898
  createHighlightJson(highlight) {
850
- var _a, _b, _c, _d;
899
+ var _a, _b, _c, _d, _e;
851
900
  const data = highlight.data;
852
901
  // Create the highlight options
853
902
  const texts = [];
854
903
  for (const text of data.texts) {
855
- 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));
904
+ 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, {
905
+ defaultExample: !!text.isCorrect,
906
+ isBoolean: true,
907
+ }));
856
908
  // Remove unwanted properties
857
909
  if (!textJson.item)
858
910
  delete textJson.item;
@@ -860,16 +912,12 @@ class JsonGenerator {
860
912
  delete textJson.lead;
861
913
  if (!textJson.hint)
862
914
  delete textJson.hint;
863
- if (!textJson.example)
864
- delete textJson.example;
865
- if (!textJson.isExample)
866
- delete textJson.isExample;
867
915
  if (!textJson.isCaseSensitive)
868
916
  delete textJson.isCaseSensitive;
869
917
  texts.push(textJson);
870
918
  }
871
919
  // Create the select
872
- 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));
920
+ 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 });
873
921
  // Remove unwanted properties
874
922
  if (!highlightJson.lead)
875
923
  delete highlightJson.lead;
@@ -1407,19 +1455,27 @@ class JsonGenerator {
1407
1455
  instruction: this.toTextAstOrString((_f = item.instruction) !== null && _f !== void 0 ? _f : ''),
1408
1456
  };
1409
1457
  }
1410
- toExampleAndIsExample(exampleIn) {
1411
- let isExample = false;
1412
- let example = this.textDefault;
1413
- if (exampleIn === true) {
1414
- isExample = true;
1458
+ toExample(node, options) {
1459
+ const { isExample, example, isDefaultExample } = node;
1460
+ const { defaultExample, isBoolean } = options;
1461
+ if (!isExample) {
1462
+ return {
1463
+ isExample: false,
1464
+ example: null,
1465
+ };
1466
+ }
1467
+ let exampleValue;
1468
+ if (isDefaultExample) {
1469
+ exampleValue = isBoolean
1470
+ ? BooleanUtils.toBoolean(defaultExample)
1471
+ : this.toTextAstOrString(defaultExample);
1415
1472
  }
1416
- else if (exampleIn) {
1417
- isExample = true;
1418
- example = this.toTextAstOrString(exampleIn);
1473
+ else {
1474
+ exampleValue = isBoolean ? BooleanUtils.toBoolean(example) : this.toTextAstOrString(example);
1419
1475
  }
1420
1476
  return {
1421
- isExample,
1422
- example,
1477
+ isExample: true,
1478
+ example: exampleValue,
1423
1479
  };
1424
1480
  }
1425
1481
  addProperty(
@@ -1605,8 +1661,8 @@ class JsonGenerator {
1605
1661
  hint: undefined,
1606
1662
  instruction: undefined,
1607
1663
  // Example
1608
- example: undefined,
1609
1664
  isExample: undefined,
1665
+ example: undefined,
1610
1666
  // Partner .conversion-xxx only
1611
1667
  partner: undefined,
1612
1668
  // Extra Properties
@@ -1665,7 +1721,6 @@ class JsonGenerator {
1665
1721
  case BitType._error:
1666
1722
  break;
1667
1723
  case BitType.article:
1668
- case BitType.highlightText:
1669
1724
  case BitType.message:
1670
1725
  case BitType.sampleSolution:
1671
1726
  case BitType.page:
@@ -1681,12 +1736,19 @@ class JsonGenerator {
1681
1736
  if (bitJson.isExample == null)
1682
1737
  bitJson.isExample = false;
1683
1738
  if (bitJson.example == null)
1684
- bitJson.example = this.textDefault;
1739
+ bitJson.example = null;
1685
1740
  if (bitJson.body == null)
1686
1741
  bitJson.body = this.bodyDefault;
1687
1742
  break;
1743
+ // Default, but with no 'example' at the bit level.
1744
+ case BitType.cloze:
1745
+ case BitType.clozeInstructionGrouped:
1746
+ case BitType.clozeSolutionGrouped:
1688
1747
  case BitType.multipleChoice1:
1689
1748
  case BitType.multipleResponse1:
1749
+ case BitType.multipleChoiceText:
1750
+ case BitType.highlightText:
1751
+ case BitType.clozeAndMultipleChoiceText:
1690
1752
  case BitType.sequence:
1691
1753
  if (bitJson.item == null)
1692
1754
  bitJson.item = this.textDefault;
@@ -1696,11 +1758,25 @@ class JsonGenerator {
1696
1758
  bitJson.instruction = this.textDefault;
1697
1759
  if (bitJson.isExample == null)
1698
1760
  bitJson.isExample = false;
1699
- if (bitJson.example == null)
1700
- bitJson.example = this.textDefault;
1701
1761
  if (bitJson.body == null)
1702
1762
  bitJson.body = this.bodyDefault;
1703
1763
  break;
1764
+ // Default with a card (and hence a footer possibility)
1765
+ case BitType.multipleChoice:
1766
+ case BitType.multipleResponse:
1767
+ if (bitJson.item == null)
1768
+ bitJson.item = this.textDefault;
1769
+ if (bitJson.hint == null)
1770
+ bitJson.hint = this.textDefault;
1771
+ if (bitJson.instruction == null)
1772
+ bitJson.instruction = this.textDefault;
1773
+ if (bitJson.isExample == null)
1774
+ bitJson.isExample = false;
1775
+ if (bitJson.body == null)
1776
+ bitJson.body = this.bodyDefault;
1777
+ if (bitJson.footer == null)
1778
+ bitJson.footer = this.textDefault;
1779
+ break;
1704
1780
  case BitType.essay:
1705
1781
  if (bitJson.item == null)
1706
1782
  bitJson.item = this.textDefault;
@@ -1711,7 +1787,7 @@ class JsonGenerator {
1711
1787
  if (bitJson.isExample == null)
1712
1788
  bitJson.isExample = false;
1713
1789
  if (bitJson.example == null)
1714
- bitJson.example = this.textDefault;
1790
+ bitJson.example = null;
1715
1791
  if (bitJson.body == null)
1716
1792
  bitJson.body = this.bodyDefault;
1717
1793
  if (bitJson.partialAnswer == null)
@@ -1729,6 +1805,8 @@ class JsonGenerator {
1729
1805
  bitJson.instruction = this.textDefault;
1730
1806
  if (bitJson.isExample == null)
1731
1807
  bitJson.isExample = false;
1808
+ if (bitJson.example == null)
1809
+ bitJson.example = null;
1732
1810
  if (bitJson.isCorrect == null)
1733
1811
  bitJson.isCorrect = false;
1734
1812
  if (bitJson.body == null)
@@ -1743,6 +1821,8 @@ class JsonGenerator {
1743
1821
  bitJson.hint = this.textDefault;
1744
1822
  if (bitJson.instruction == null)
1745
1823
  bitJson.instruction = this.textDefault;
1824
+ if (bitJson.isExample == null)
1825
+ bitJson.isExample = false;
1746
1826
  if (bitJson.labelFalse == null)
1747
1827
  bitJson.labelFalse = '';
1748
1828
  if (bitJson.labelTrue == null)
@@ -1758,7 +1838,7 @@ class JsonGenerator {
1758
1838
  if (bitJson.isExample == null)
1759
1839
  bitJson.isExample = false;
1760
1840
  if (bitJson.example == null)
1761
- bitJson.example = this.textDefault;
1841
+ bitJson.example = null;
1762
1842
  if (bitJson.toc == null)
1763
1843
  bitJson.toc = true; // Always set on chapter bits?
1764
1844
  if (bitJson.progress == null)
@@ -1768,19 +1848,6 @@ class JsonGenerator {
1768
1848
  if (bitJson.body == null)
1769
1849
  bitJson.body = this.bodyDefault;
1770
1850
  break;
1771
- case BitType.multipleChoice:
1772
- case BitType.multipleResponse:
1773
- if (bitJson.item == null)
1774
- bitJson.item = this.textDefault;
1775
- if (bitJson.hint == null)
1776
- bitJson.hint = this.textDefault;
1777
- if (bitJson.instruction == null)
1778
- bitJson.instruction = this.textDefault;
1779
- if (bitJson.body == null)
1780
- bitJson.body = this.bodyDefault;
1781
- if (bitJson.footer == null)
1782
- bitJson.footer = this.textDefault;
1783
- break;
1784
1851
  case BitType.interview:
1785
1852
  case BitType.interviewInstructionGrouped:
1786
1853
  if (bitJson.item == null)
@@ -1789,6 +1856,8 @@ class JsonGenerator {
1789
1856
  bitJson.hint = this.textDefault;
1790
1857
  if (bitJson.instruction == null)
1791
1858
  bitJson.instruction = this.textDefault;
1859
+ if (bitJson.isExample == null)
1860
+ bitJson.isExample = false;
1792
1861
  if (bitJson.body == null)
1793
1862
  bitJson.body = this.bodyDefault;
1794
1863
  if (bitJson.footer == null)
@@ -1833,7 +1902,7 @@ class JsonGenerator {
1833
1902
  if (bitJson.isExample == null)
1834
1903
  bitJson.isExample = false;
1835
1904
  if (bitJson.example == null)
1836
- bitJson.example = this.textDefault;
1905
+ bitJson.example = null;
1837
1906
  if (bitJson.isTracked == null)
1838
1907
  bitJson.isTracked = true;
1839
1908
  if (bitJson.isInfoOnly == null)
@@ -1853,7 +1922,7 @@ class JsonGenerator {
1853
1922
  if (bitJson.isExample == null)
1854
1923
  bitJson.isExample = false;
1855
1924
  if (bitJson.example == null)
1856
- bitJson.example = this.textDefault;
1925
+ bitJson.example = null;
1857
1926
  if (bitJson.body == null)
1858
1927
  bitJson.body = this.bodyDefault;
1859
1928
  break;
@@ -1955,7 +2024,7 @@ class JsonGenerator {
1955
2024
  if (bitJson.instruction == null)
1956
2025
  delete bitJson.instruction;
1957
2026
  // Example
1958
- if (bitJson.example == null)
2027
+ if (bitJson.example === undefined)
1959
2028
  delete bitJson.example;
1960
2029
  if (bitJson.isExample == null)
1961
2030
  delete bitJson.isExample;