@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
@@ -40,84 +40,55 @@ class Builder extends BaseBuilder_1.BaseBuilder {
40
40
  */
41
41
  bit(data) {
42
42
  var _a;
43
- const { bitType, textFormat, resourceType, id, externalId, spaceId, padletId, aiGenerated, releaseVersion, ageRange, language, computerLanguage, subtype, coverImage, publisher, publications, author, subject, date, location, theme, kind, action, thumbImage, focusX, focusY, duration, referenceProperty, deeplink, externalLink, externalLinkText, videoCallLink, bot, list, textReference, isTracked, isInfoOnly, labelTrue, labelFalse, book, quotedPerson, partialAnswer, levelProperty, title, subtitle, level, toc, progress, anchor, reference, referenceEnd, item, lead, hint, instruction, example, partner, extraProperties, resource, body, sampleSolution, statement, responses, choices, footer, markup, parser, } = data;
43
+ const { bitType, textFormat, resourceType, id, externalId, spaceId, padletId, aiGenerated, releaseVersion, ageRange, language, computerLanguage, subtype, coverImage, publisher, publications, author, subject, date, location, theme, kind, action, thumbImage, focusX, focusY, duration, referenceProperty, deeplink, externalLink, externalLinkText, videoCallLink, bot, list, textReference, isTracked, isInfoOnly, labelTrue, labelFalse, book, quotedPerson, partialAnswer, levelProperty, title, subtitle, level, toc, progress, anchor, reference, referenceEnd, item, lead, hint, instruction, isDefaultExample, example, partner, extraProperties, resource, body, sampleSolution, footer, markup, parser, } = data;
44
+ // Set the card node data
45
+ const cardNode = this.cardNode(data);
44
46
  // NOTE: Node order is important and is defined here
45
- const node = {
46
- bitType,
47
- textFormat: (_a = TextFormat_1.TextFormat.fromValue(textFormat)) !== null && _a !== void 0 ? _a : TextFormat_1.TextFormat.bitmarkMinusMinus,
48
- resourceType: BitUtils_1.BitUtils.calculateValidResourceType(bitType, resourceType, resource),
49
- id: this.toAstProperty(PropertyKey_1.PropertyKey.id, id),
50
- externalId: this.toAstProperty(PropertyKey_1.PropertyKey.externalId, externalId),
51
- spaceId: this.toAstProperty(PropertyKey_1.PropertyKey.spaceId, spaceId),
52
- padletId: this.toAstProperty(PropertyKey_1.PropertyKey.padletId, padletId),
53
- aiGenerated: this.toAstProperty(PropertyKey_1.PropertyKey.aiGenerated, aiGenerated),
54
- releaseVersion: this.toAstProperty(PropertyKey_1.PropertyKey.releaseVersion, releaseVersion),
55
- book,
56
- ageRange: this.toAstProperty(PropertyKey_1.PropertyKey.ageRange, ageRange),
57
- language: this.toAstProperty(PropertyKey_1.PropertyKey.language, language),
58
- computerLanguage: this.toAstProperty(PropertyKey_1.PropertyKey.computerLanguage, computerLanguage),
59
- subtype: this.toAstProperty(PropertyKey_1.PropertyKey.subtype, subtype),
60
- coverImage: this.toAstProperty(PropertyKey_1.PropertyKey.coverImage, coverImage),
61
- publisher: this.toAstProperty(PropertyKey_1.PropertyKey.publisher, publisher),
62
- publications: this.toAstProperty(PropertyKey_1.PropertyKey.publications, publications),
63
- author: this.toAstProperty(PropertyKey_1.PropertyKey.author, author),
64
- subject: this.toAstProperty(PropertyKey_1.PropertyKey.subject, subject),
65
- date: this.toAstProperty(PropertyKey_1.PropertyKey.date, date),
66
- location: this.toAstProperty(PropertyKey_1.PropertyKey.location, location),
67
- theme: this.toAstProperty(PropertyKey_1.PropertyKey.theme, theme),
68
- kind: this.toAstProperty(PropertyKey_1.PropertyKey.kind, kind),
69
- action: this.toAstProperty(PropertyKey_1.PropertyKey.action, action),
70
- thumbImage: this.toAstProperty(PropertyKey_1.PropertyKey.thumbImage, thumbImage),
71
- focusX: this.toAstProperty(PropertyKey_1.PropertyKey.focusX, focusX),
72
- focusY: this.toAstProperty(PropertyKey_1.PropertyKey.focusY, focusY),
73
- deeplink: this.toAstProperty(PropertyKey_1.PropertyKey.deeplink, deeplink),
74
- externalLink: this.toAstProperty(PropertyKey_1.PropertyKey.externalLink, externalLink),
75
- externalLinkText: this.toAstProperty(PropertyKey_1.PropertyKey.externalLinkText, externalLinkText),
76
- videoCallLink: this.toAstProperty(PropertyKey_1.PropertyKey.videoCallLink, videoCallLink),
77
- bot: this.toAstProperty(PropertyKey_1.PropertyKey.bot, bot),
78
- duration: this.toAstProperty(PropertyKey_1.PropertyKey.duration, duration),
79
- referenceProperty: this.toAstProperty(PropertyKey_1.PropertyKey.reference, referenceProperty),
80
- list: this.toAstProperty(PropertyKey_1.PropertyKey.list, list),
81
- textReference: this.toAstProperty(PropertyKey_1.PropertyKey.textReference, textReference),
82
- isTracked: this.toAstProperty(PropertyKey_1.PropertyKey.isTracked, isTracked),
83
- isInfoOnly: this.toAstProperty(PropertyKey_1.PropertyKey.isInfoOnly, isInfoOnly),
84
- labelTrue: this.toAstProperty(PropertyKey_1.PropertyKey.labelTrue, labelTrue),
85
- labelFalse: this.toAstProperty(PropertyKey_1.PropertyKey.labelFalse, labelFalse),
86
- quotedPerson: this.toAstProperty(PropertyKey_1.PropertyKey.quotedPerson, quotedPerson),
87
- partialAnswer: this.toAstProperty(PropertyKey_1.PropertyKey.partialAnswer, partialAnswer),
88
- levelProperty: this.toAstProperty(PropertyKey_1.PropertyKey.level, levelProperty),
89
- title,
90
- subtitle,
91
- level: NumberUtils_1.NumberUtils.asNumber(level),
92
- toc: this.toAstProperty(PropertyKey_1.PropertyKey.toc, toc),
93
- progress: this.toAstProperty(PropertyKey_1.PropertyKey.progress, progress),
94
- anchor,
47
+ const node = Object.assign(Object.assign({ bitType, textFormat: (_a = TextFormat_1.TextFormat.fromValue(textFormat)) !== null && _a !== void 0 ? _a : TextFormat_1.TextFormat.bitmarkMinusMinus, resourceType: BitUtils_1.BitUtils.calculateValidResourceType(bitType, resourceType, resource), id: this.toAstProperty(PropertyKey_1.PropertyKey.id, id), externalId: this.toAstProperty(PropertyKey_1.PropertyKey.externalId, externalId), spaceId: this.toAstProperty(PropertyKey_1.PropertyKey.spaceId, spaceId), padletId: this.toAstProperty(PropertyKey_1.PropertyKey.padletId, padletId), aiGenerated: this.toAstProperty(PropertyKey_1.PropertyKey.aiGenerated, aiGenerated), releaseVersion: this.toAstProperty(PropertyKey_1.PropertyKey.releaseVersion, releaseVersion), book, ageRange: this.toAstProperty(PropertyKey_1.PropertyKey.ageRange, ageRange), language: this.toAstProperty(PropertyKey_1.PropertyKey.language, language), computerLanguage: this.toAstProperty(PropertyKey_1.PropertyKey.computerLanguage, computerLanguage), subtype: this.toAstProperty(PropertyKey_1.PropertyKey.subtype, subtype), coverImage: this.toAstProperty(PropertyKey_1.PropertyKey.coverImage, coverImage), publisher: this.toAstProperty(PropertyKey_1.PropertyKey.publisher, publisher), publications: this.toAstProperty(PropertyKey_1.PropertyKey.publications, publications), author: this.toAstProperty(PropertyKey_1.PropertyKey.author, author), subject: this.toAstProperty(PropertyKey_1.PropertyKey.subject, subject), date: this.toAstProperty(PropertyKey_1.PropertyKey.date, date), location: this.toAstProperty(PropertyKey_1.PropertyKey.location, location), theme: this.toAstProperty(PropertyKey_1.PropertyKey.theme, theme), kind: this.toAstProperty(PropertyKey_1.PropertyKey.kind, kind), action: this.toAstProperty(PropertyKey_1.PropertyKey.action, action), thumbImage: this.toAstProperty(PropertyKey_1.PropertyKey.thumbImage, thumbImage), focusX: this.toAstProperty(PropertyKey_1.PropertyKey.focusX, focusX), focusY: this.toAstProperty(PropertyKey_1.PropertyKey.focusY, focusY), deeplink: this.toAstProperty(PropertyKey_1.PropertyKey.deeplink, deeplink), externalLink: this.toAstProperty(PropertyKey_1.PropertyKey.externalLink, externalLink), externalLinkText: this.toAstProperty(PropertyKey_1.PropertyKey.externalLinkText, externalLinkText), videoCallLink: this.toAstProperty(PropertyKey_1.PropertyKey.videoCallLink, videoCallLink), bot: this.toAstProperty(PropertyKey_1.PropertyKey.bot, bot), duration: this.toAstProperty(PropertyKey_1.PropertyKey.duration, duration), referenceProperty: this.toAstProperty(PropertyKey_1.PropertyKey.reference, referenceProperty), list: this.toAstProperty(PropertyKey_1.PropertyKey.list, list), textReference: this.toAstProperty(PropertyKey_1.PropertyKey.textReference, textReference), isTracked: this.toAstProperty(PropertyKey_1.PropertyKey.isTracked, isTracked), isInfoOnly: this.toAstProperty(PropertyKey_1.PropertyKey.isInfoOnly, isInfoOnly), labelTrue: this.toAstProperty(PropertyKey_1.PropertyKey.labelTrue, labelTrue), labelFalse: this.toAstProperty(PropertyKey_1.PropertyKey.labelFalse, labelFalse), quotedPerson: this.toAstProperty(PropertyKey_1.PropertyKey.quotedPerson, quotedPerson), partialAnswer: this.toAstProperty(PropertyKey_1.PropertyKey.partialAnswer, partialAnswer), levelProperty: this.toAstProperty(PropertyKey_1.PropertyKey.level, levelProperty), title,
48
+ subtitle, level: NumberUtils_1.NumberUtils.asNumber(level), toc: this.toAstProperty(PropertyKey_1.PropertyKey.toc, toc), progress: this.toAstProperty(PropertyKey_1.PropertyKey.progress, progress), anchor,
95
49
  reference,
96
- referenceEnd,
97
- itemLead: this.itemLead(item, lead),
98
- hint,
99
- instruction,
100
- example: this.toExample(example),
101
- partner,
50
+ referenceEnd, itemLead: this.itemLead(item, lead), hint,
51
+ instruction }, this.toExample(isDefaultExample, example)), { partner,
102
52
  resource,
103
- body,
104
- sampleSolution: ArrayUtils_1.ArrayUtils.asArray(sampleSolution),
105
- statement,
106
- responses,
107
- choices,
108
- cardNode: this.cardNode(data),
53
+ body, sampleSolution: ArrayUtils_1.ArrayUtils.asArray(sampleSolution), cardNode,
109
54
  footer,
110
55
  markup,
111
- parser,
56
+ parser,
112
57
  // Must always be last in the AST so key clashes are avoided correctly with other properties
113
- extraProperties: this.parseExtraProperties(extraProperties),
114
- };
58
+ extraProperties: this.parseExtraProperties(extraProperties) });
59
+ // If isDefaultExample is set at the bit level, push the default example down the tree to the relevant nodes
60
+ if (isDefaultExample) {
61
+ if (cardNode) {
62
+ this.setDefaultExamplesFlags(true, cardNode.choices);
63
+ this.setDefaultExamplesFlags(false, cardNode.responses, cardNode.statements, cardNode.statement, cardNode.pairs);
64
+ if (cardNode.quizzes) {
65
+ for (const quiz of cardNode.quizzes) {
66
+ this.setDefaultExamplesFlags(true, quiz.choices);
67
+ this.setDefaultExamplesFlags(false, quiz.responses);
68
+ }
69
+ }
70
+ if (cardNode.matrix) {
71
+ for (const m of cardNode.matrix) {
72
+ this.setDefaultExamplesFlags(false, m.cells);
73
+ }
74
+ }
75
+ }
76
+ if (body) {
77
+ this.setDefaultExamplesBodyBits(body);
78
+ }
79
+ // this.setDefaultExampleBit(bitType, node);
80
+ }
115
81
  // Set default values
116
82
  this.setDefaultBitValues(node);
83
+ // Set the 'isExample' flags
84
+ this.setIsExampleFlags(node);
117
85
  // Add the version to the parser info
118
86
  this.addVersionToParserInfo(node);
119
87
  // Remove Unset Optionals
120
- ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node);
88
+ ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node, {
89
+ ignoreAllFalse: true,
90
+ ignoreEmptyString: ['example'],
91
+ });
121
92
  // Validate and correct invalid bits as much as possible
122
93
  return NodeValidator_1.NodeValidator.validateBit(node);
123
94
  }
@@ -128,19 +99,14 @@ class Builder extends BaseBuilder_1.BaseBuilder {
128
99
  * @returns
129
100
  */
130
101
  choice(data) {
131
- const { text, isCorrect, item, lead, hint, instruction, example, isCaseSensitive } = data;
102
+ const { text, isCorrect, item, lead, hint, instruction, isCaseSensitive, isDefaultExample, example } = data;
132
103
  // NOTE: Node order is important and is defined here
133
- const node = {
134
- text,
135
- isCorrect,
136
- itemLead: this.itemLead(item, lead),
137
- hint,
138
- instruction,
139
- example: this.toExample(example),
140
- isCaseSensitive,
141
- };
104
+ const node = Object.assign(Object.assign({ text, isCorrect: !!isCorrect, itemLead: this.itemLead(item, lead), hint,
105
+ instruction }, this.toExampleBoolean(isDefaultExample, example)), { isCaseSensitive });
142
106
  // Remove Unset Optionals
143
- ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node);
107
+ ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node, {
108
+ ignoreAllFalse: true,
109
+ });
144
110
  return node;
145
111
  }
146
112
  /**
@@ -150,19 +116,14 @@ class Builder extends BaseBuilder_1.BaseBuilder {
150
116
  * @returns
151
117
  */
152
118
  response(data) {
153
- const { text, isCorrect, item, lead, hint, instruction, example, isCaseSensitive } = data;
119
+ const { text, isCorrect, item, lead, hint, instruction, isCaseSensitive, isDefaultExample, example } = data;
154
120
  // NOTE: Node order is important and is defined here
155
- const node = {
156
- text,
157
- isCorrect,
158
- itemLead: this.itemLead(item, lead),
159
- hint,
160
- instruction,
161
- example: this.toExample(example),
162
- isCaseSensitive,
163
- };
121
+ const node = Object.assign(Object.assign({ text, isCorrect: !!isCorrect, itemLead: this.itemLead(item, lead), hint,
122
+ instruction }, this.toExampleBoolean(isDefaultExample, example)), { isCaseSensitive });
164
123
  // Remove Unset Optionals
165
- ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node);
124
+ ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node, {
125
+ ignoreAllFalse: true,
126
+ });
166
127
  return node;
167
128
  }
168
129
  /**
@@ -194,13 +155,16 @@ class Builder extends BaseBuilder_1.BaseBuilder {
194
155
  * @returns
195
156
  */
196
157
  quiz(data) {
197
- const { choices, responses, item, lead, hint, instruction, example } = data;
158
+ const { choices, responses, item, lead, hint, instruction, isDefaultExample } = data;
159
+ if (isDefaultExample) {
160
+ this.setDefaultExamplesFlags(true, choices);
161
+ this.setDefaultExamplesFlags(false, responses);
162
+ }
198
163
  // NOTE: Node order is important and is defined here
199
164
  const node = {
200
165
  itemLead: this.itemLead(item, lead),
201
166
  hint,
202
167
  instruction,
203
- example: this.toExample(example),
204
168
  choices,
205
169
  responses,
206
170
  };
@@ -235,22 +199,18 @@ class Builder extends BaseBuilder_1.BaseBuilder {
235
199
  * @returns
236
200
  */
237
201
  pair(data) {
238
- const { key, keyAudio, keyImage, values, item, lead, hint, instruction, example, isCaseSensitive, isShortAnswer } = data;
202
+ const { key, keyAudio, keyImage, values, item, lead, hint, instruction, isCaseSensitive, isShortAnswer, isDefaultExample, example, } = data;
239
203
  // NOTE: Node order is important and is defined here
240
- const node = {
241
- key,
204
+ const node = Object.assign(Object.assign({ key,
242
205
  keyAudio,
243
- keyImage,
244
- itemLead: this.itemLead(item, lead),
245
- hint,
246
- instruction,
247
- example: this.toExample(example),
248
- isCaseSensitive,
206
+ keyImage, itemLead: this.itemLead(item, lead), hint,
207
+ instruction }, this.toExample(isDefaultExample, example)), { isCaseSensitive,
249
208
  isShortAnswer,
250
- values,
251
- };
209
+ values });
252
210
  // Remove Unset Optionals
253
- ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node);
211
+ ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node, {
212
+ ignoreAllFalse: true,
213
+ });
254
214
  return node;
255
215
  }
256
216
  /**
@@ -260,20 +220,31 @@ class Builder extends BaseBuilder_1.BaseBuilder {
260
220
  * @returns
261
221
  */
262
222
  matrix(data) {
263
- const { key, cells, item, lead, hint, instruction, example, isCaseSensitive, isShortAnswer } = data;
223
+ const { key, cells, item, lead, hint, instruction, isCaseSensitive, isShortAnswer, isDefaultExample } = data;
224
+ let isExample = false;
225
+ // Set isExample for matrix based on isExample for cells
226
+ for (const c of cells !== null && cells !== void 0 ? cells : []) {
227
+ if (isDefaultExample && !c.isExample) {
228
+ c.isDefaultExample = true;
229
+ c.isExample = true;
230
+ }
231
+ isExample = c.isExample ? true : isExample;
232
+ }
264
233
  // NOTE: Node order is important and is defined here
265
234
  const node = {
266
235
  key,
267
236
  itemLead: this.itemLead(item, lead),
268
237
  hint,
269
238
  instruction,
270
- example: this.toExample(example),
271
239
  isCaseSensitive,
272
240
  isShortAnswer,
241
+ isExample,
273
242
  cells,
274
243
  };
275
244
  // Remove Unset Optionals
276
- ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node);
245
+ ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node, {
246
+ ignoreAllFalse: true,
247
+ });
277
248
  return node;
278
249
  }
279
250
  /**
@@ -283,17 +254,14 @@ class Builder extends BaseBuilder_1.BaseBuilder {
283
254
  * @returns
284
255
  */
285
256
  matrixCell(data) {
286
- const { values, item, lead, hint, instruction, example } = data;
257
+ const { values, item, lead, hint, instruction, isDefaultExample, example } = data;
287
258
  // NOTE: Node order is important and is defined here
288
- const node = {
289
- values,
290
- itemLead: this.itemLead(item, lead),
291
- hint,
292
- instruction,
293
- example: this.toExample(example),
294
- };
259
+ const node = Object.assign({ values, itemLead: this.itemLead(item, lead), hint,
260
+ instruction }, this.toExample(isDefaultExample, example));
295
261
  // Remove Unset Optionals
296
- ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node);
262
+ ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node, {
263
+ ignoreAllFalse: true,
264
+ });
297
265
  return node;
298
266
  }
299
267
  /**
@@ -303,21 +271,19 @@ class Builder extends BaseBuilder_1.BaseBuilder {
303
271
  * @returns
304
272
  */
305
273
  question(data) {
306
- const { question, partialAnswer, item, lead, hint, instruction, example, isCaseSensitive, isShortAnswer, sampleSolution, } = data;
274
+ const { question, partialAnswer, item, lead, hint, instruction, isCaseSensitive, isShortAnswer, sampleSolution, isDefaultExample, example, } = data;
307
275
  // NOTE: Node order is important and is defined here
308
- const node = {
309
- itemLead: this.itemLead(item, lead),
310
- question,
276
+ const node = Object.assign(Object.assign({ itemLead: this.itemLead(item, lead), question,
311
277
  partialAnswer,
312
278
  hint,
313
- instruction,
314
- example: this.toExample(example),
315
- isCaseSensitive,
279
+ instruction }, this.toExample(isDefaultExample, example)), { isCaseSensitive,
316
280
  isShortAnswer,
317
- sampleSolution,
318
- };
281
+ sampleSolution });
319
282
  // Remove Unset Optionals
320
- ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node, { ignoreEmptyString: ['question'], ignoreFalse: ['isShortAnswer'] });
283
+ ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node, {
284
+ ignoreEmptyString: ['question'],
285
+ ignoreAllFalse: true,
286
+ });
321
287
  return node;
322
288
  }
323
289
  /**
@@ -371,21 +337,18 @@ class Builder extends BaseBuilder_1.BaseBuilder {
371
337
  * @returns
372
338
  */
373
339
  gap(data) {
374
- const { solutions, item, lead, hint, instruction, example, isCaseSensitive } = data;
340
+ const { solutions, item, lead, hint, instruction, isCaseSensitive, isDefaultExample, example } = data;
341
+ // const defaultExample = Array.isArray(solutions) && solutions.length === 1 ? solutions[0] : null;
375
342
  // NOTE: Node order is important and is defined here
376
343
  const node = {
377
344
  type: BodyBitType_1.BodyBitType.gap,
378
- data: {
379
- solutions,
380
- itemLead: this.itemLead(item, lead),
381
- hint,
382
- instruction,
383
- example: this.toExample(example),
384
- isCaseSensitive,
385
- },
345
+ data: Object.assign(Object.assign({ solutions, itemLead: this.itemLead(item, lead), hint,
346
+ instruction }, this.toExample(isDefaultExample, example)), { isCaseSensitive }),
386
347
  };
387
348
  // Remove Unset Optionals
388
- ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node);
349
+ ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node, {
350
+ ignoreAllFalse: true,
351
+ });
389
352
  return node;
390
353
  }
391
354
  /**
@@ -395,7 +358,7 @@ class Builder extends BaseBuilder_1.BaseBuilder {
395
358
  * @returns
396
359
  */
397
360
  select(data) {
398
- const { options, prefix, postfix, item, lead, hint, instruction, example, isCaseSensitive } = data;
361
+ const { options, prefix, postfix, item, lead, hint, instruction, isCaseSensitive } = data;
399
362
  // NOTE: Node order is important and is defined here
400
363
  const node = {
401
364
  type: BodyBitType_1.BodyBitType.select,
@@ -406,12 +369,13 @@ class Builder extends BaseBuilder_1.BaseBuilder {
406
369
  itemLead: this.itemLead(item, lead),
407
370
  hint,
408
371
  instruction,
409
- example: this.toExample(example),
410
372
  isCaseSensitive,
411
373
  },
412
374
  };
413
375
  // Remove Unset Optionals
414
- ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node);
376
+ ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node, {
377
+ ignoreAllFalse: true,
378
+ });
415
379
  return node;
416
380
  }
417
381
  /**
@@ -421,19 +385,14 @@ class Builder extends BaseBuilder_1.BaseBuilder {
421
385
  * @returns
422
386
  */
423
387
  selectOption(data) {
424
- const { text, isCorrect, item, lead, hint, instruction, example, isCaseSensitive } = data;
388
+ const { text, isCorrect, item, lead, hint, instruction, isCaseSensitive, isDefaultExample, example } = data;
425
389
  // NOTE: Node order is important and is defined here
426
- const node = {
427
- text,
428
- isCorrect,
429
- itemLead: this.itemLead(item, lead),
430
- hint,
431
- instruction,
432
- example: this.toExample(example),
433
- isCaseSensitive,
434
- };
390
+ const node = Object.assign(Object.assign({ text, isCorrect: !!isCorrect, itemLead: this.itemLead(item, lead), hint,
391
+ instruction }, this.toExample(isDefaultExample, example)), { isCaseSensitive });
435
392
  // Remove Unset Optionals
436
- ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node);
393
+ ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node, {
394
+ ignoreAllFalse: true,
395
+ });
437
396
  return node;
438
397
  }
439
398
  /**
@@ -443,7 +402,7 @@ class Builder extends BaseBuilder_1.BaseBuilder {
443
402
  * @returns
444
403
  */
445
404
  highlight(data) {
446
- const { texts, prefix, postfix, item, lead, hint, instruction, example, isCaseSensitive } = data;
405
+ const { texts, prefix, postfix, item, lead, hint, instruction, isCaseSensitive } = data;
447
406
  // NOTE: Node order is important and is defined here
448
407
  const node = {
449
408
  type: BodyBitType_1.BodyBitType.highlight,
@@ -454,12 +413,13 @@ class Builder extends BaseBuilder_1.BaseBuilder {
454
413
  itemLead: this.itemLead(item, lead),
455
414
  hint,
456
415
  instruction,
457
- example: this.toExample(example),
458
416
  isCaseSensitive,
459
417
  },
460
418
  };
461
419
  // Remove Unset Optionals
462
- ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node);
420
+ ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node, {
421
+ ignoreAllFalse: true,
422
+ });
463
423
  return node;
464
424
  }
465
425
  /**
@@ -469,20 +429,14 @@ class Builder extends BaseBuilder_1.BaseBuilder {
469
429
  * @returns
470
430
  */
471
431
  highlightText(data) {
472
- const { text, isCorrect, isHighlighted, item, lead, hint, instruction, example, isCaseSensitive } = data;
432
+ const { text, isCorrect, isHighlighted, item, lead, hint, instruction, isCaseSensitive, isDefaultExample, example, } = data;
473
433
  // NOTE: Node order is important and is defined here
474
- const node = {
475
- text,
476
- isCorrect,
477
- isHighlighted,
478
- itemLead: this.itemLead(item, lead),
479
- hint,
480
- instruction,
481
- example: this.toExample(example),
482
- isCaseSensitive,
483
- };
434
+ const node = Object.assign(Object.assign({ text, isCorrect: !!isCorrect, isHighlighted: !!isHighlighted, itemLead: this.itemLead(item, lead), hint,
435
+ instruction }, this.toExample(isDefaultExample, example)), { isCaseSensitive });
484
436
  // Remove Unset Optionals
485
- ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node);
437
+ ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node, {
438
+ ignoreAllFalse: true,
439
+ });
486
440
  return node;
487
441
  }
488
442
  /**
@@ -492,19 +446,14 @@ class Builder extends BaseBuilder_1.BaseBuilder {
492
446
  * @returns
493
447
  */
494
448
  statement(data) {
495
- const { text, isCorrect, item, lead, hint, instruction, example, isCaseSensitive } = data;
449
+ const { text, isCorrect, item, lead, hint, instruction, isCaseSensitive, isDefaultExample, example } = data;
496
450
  // NOTE: Node order is important and is defined here
497
- const node = {
498
- text,
499
- isCorrect,
500
- itemLead: this.itemLead(item, lead),
501
- hint,
502
- instruction,
503
- example: this.toExample(example),
504
- isCaseSensitive,
505
- };
451
+ const node = Object.assign(Object.assign({ text, isCorrect: !!isCorrect, itemLead: this.itemLead(item, lead), hint,
452
+ instruction }, this.toExampleBoolean(isDefaultExample, example)), { isCaseSensitive });
506
453
  // Remove Unset Optionals
507
- ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node);
454
+ ObjectUtils_1.ObjectUtils.removeUnwantedProperties(node, {
455
+ ignoreAllFalse: true,
456
+ });
508
457
  return node;
509
458
  }
510
459
  /**
@@ -557,14 +506,27 @@ class Builder extends BaseBuilder_1.BaseBuilder {
557
506
  }
558
507
  cardNode(data) {
559
508
  let node;
560
- const { heading, elements, questions, statements, quizzes, pairs, matrix, botResponses } = data;
561
- if (heading || elements || questions || statements || quizzes || pairs || matrix || botResponses) {
509
+ const { questions, elements, statement, statements, choices, responses, quizzes, heading, pairs, matrix, botResponses, } = data;
510
+ if (questions ||
511
+ elements ||
512
+ statement ||
513
+ statements ||
514
+ choices ||
515
+ responses ||
516
+ quizzes ||
517
+ heading ||
518
+ pairs ||
519
+ matrix ||
520
+ botResponses) {
562
521
  node = {
563
- heading,
564
- elements,
565
522
  questions,
523
+ elements,
524
+ statement,
566
525
  statements,
526
+ choices,
527
+ responses,
567
528
  quizzes,
529
+ heading,
568
530
  pairs,
569
531
  matrix,
570
532
  botResponses,
@@ -574,6 +536,90 @@ class Builder extends BaseBuilder_1.BaseBuilder {
574
536
  }
575
537
  return node;
576
538
  }
539
+ /**
540
+ * Set every correct answer as an example for Decision node(s)
541
+ *
542
+ * @param answers - array of answers
543
+ * @returns true if any of the answers has an example, otherwise undefined
544
+ */
545
+ setDefaultExamplesFlags(onlyCorrect, ...nodes) {
546
+ if (Array.isArray(nodes)) {
547
+ for (const ds of nodes) {
548
+ if (Array.isArray(ds)) {
549
+ for (const d of ds) {
550
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
551
+ if (!d.isExample && (!onlyCorrect || d.isCorrect)) {
552
+ d.isDefaultExample = true;
553
+ d.isExample = true;
554
+ }
555
+ }
556
+ }
557
+ else if (ds) {
558
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
559
+ if (!ds.isExample && (!onlyCorrect || ds.isCorrect)) {
560
+ ds.isDefaultExample = true;
561
+ ds.isExample = true;
562
+ }
563
+ }
564
+ }
565
+ }
566
+ }
567
+ setDefaultExamplesBodyBits(body) {
568
+ if (!body || !body.bodyParts || body.bodyParts.length === 0)
569
+ return;
570
+ for (const part of body.bodyParts) {
571
+ if (part) {
572
+ switch (part.type) {
573
+ case BodyBitType_1.BodyBitType.gap: {
574
+ const gap = part;
575
+ if (!gap.data.isExample) {
576
+ gap.data.isDefaultExample = true;
577
+ gap.data.isExample = true;
578
+ }
579
+ break;
580
+ }
581
+ case BodyBitType_1.BodyBitType.select: {
582
+ const select = part;
583
+ for (const option of select.data.options) {
584
+ if (!option.isExample && option.isCorrect) {
585
+ option.isDefaultExample = true;
586
+ option.isExample = true;
587
+ }
588
+ }
589
+ break;
590
+ }
591
+ case BodyBitType_1.BodyBitType.highlight: {
592
+ const highlight = part;
593
+ for (const text of highlight.data.texts) {
594
+ if (!text.isExample && text.isCorrect) {
595
+ text.isDefaultExample = true;
596
+ text.isExample = true;
597
+ }
598
+ }
599
+ break;
600
+ }
601
+ }
602
+ }
603
+ }
604
+ }
605
+ // private setDefaultExampleBit(bitType: BitTypeType, node: Bit): void {
606
+ // const { example: exampleIn } = node;
607
+ // const meta = BitType.getMetadata<BitTypeMetadata>(bitType);
608
+ // if (!meta) return;
609
+ // if (exampleIn === null) {
610
+ // // Set the default for the specific bit
611
+ // switch (meta.exampleType) {
612
+ // case ExampleType.boolean:
613
+ // node.example = true;
614
+ // break;
615
+ // case ExampleType.string:
616
+ // node.example = '';
617
+ // break;
618
+ // default:
619
+ // // Ignore at this level
620
+ // }
621
+ // }
622
+ // }
577
623
  parseExtraProperties(extraProperties) {
578
624
  if (!extraProperties)
579
625
  return undefined;
@@ -586,6 +632,126 @@ class Builder extends BaseBuilder_1.BaseBuilder {
586
632
  }
587
633
  return res;
588
634
  }
635
+ /**
636
+ * Set the 'isExample' flags on the bit
637
+ *
638
+ * The flag is set if the bit has an example. The flag is set at each branch level up the tree from
639
+ * where the 'example' exists.
640
+ *
641
+ * @param bit
642
+ */
643
+ setIsExampleFlags(bit) {
644
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
645
+ bit.isExample = false;
646
+ const checkIsExample = (example) => {
647
+ if (!example)
648
+ return false;
649
+ if (example.isDefaultExample || example.example != undefined) {
650
+ example.isExample = true;
651
+ bit.isExample = true;
652
+ }
653
+ else {
654
+ if (example === bit) {
655
+ example.isExample = !!bit.isExample;
656
+ }
657
+ else {
658
+ example.isExample = false;
659
+ }
660
+ }
661
+ return example.isExample;
662
+ };
663
+ const { body, cardNode } = bit;
664
+ // Body bit level
665
+ if (body && body.bodyParts) {
666
+ for (const bodyPart of body.bodyParts) {
667
+ switch (bodyPart.type) {
668
+ case BodyBitType_1.BodyBitType.gap: {
669
+ checkIsExample(bodyPart.data);
670
+ break;
671
+ }
672
+ case BodyBitType_1.BodyBitType.select: {
673
+ const select = bodyPart;
674
+ let hasExample = false;
675
+ for (const option of select.data.options) {
676
+ hasExample = checkIsExample(option) ? true : hasExample;
677
+ }
678
+ select.data.isExample = hasExample;
679
+ break;
680
+ }
681
+ case BodyBitType_1.BodyBitType.highlight: {
682
+ const highlight = bodyPart;
683
+ let hasExample = false;
684
+ for (const text of highlight.data.texts) {
685
+ hasExample = checkIsExample(text) ? true : hasExample;
686
+ }
687
+ highlight.data.isExample = hasExample;
688
+ break;
689
+ }
690
+ }
691
+ }
692
+ }
693
+ // Card level
694
+ if (cardNode) {
695
+ // pairs
696
+ for (const v of (_a = cardNode.pairs) !== null && _a !== void 0 ? _a : []) {
697
+ checkIsExample(v);
698
+ }
699
+ // matrix
700
+ for (const mx of (_b = cardNode.matrix) !== null && _b !== void 0 ? _b : []) {
701
+ let hasExample = false;
702
+ // matrix cell
703
+ for (const v of (_c = mx.cells) !== null && _c !== void 0 ? _c : []) {
704
+ hasExample = checkIsExample(v) ? true : hasExample;
705
+ }
706
+ mx.isExample = hasExample;
707
+ }
708
+ // quizzes
709
+ for (const quiz of (_d = cardNode.quizzes) !== null && _d !== void 0 ? _d : []) {
710
+ let hasExample = false;
711
+ // responses
712
+ for (const v of (_e = quiz.responses) !== null && _e !== void 0 ? _e : []) {
713
+ hasExample = checkIsExample(v) ? true : hasExample;
714
+ }
715
+ // choices
716
+ for (const v of (_f = quiz.choices) !== null && _f !== void 0 ? _f : []) {
717
+ hasExample = checkIsExample(v) ? true : hasExample;
718
+ }
719
+ quiz.isExample = hasExample;
720
+ }
721
+ // responses
722
+ for (const v of (_g = cardNode.responses) !== null && _g !== void 0 ? _g : []) {
723
+ checkIsExample(v);
724
+ }
725
+ // choices
726
+ for (const v of (_h = cardNode.choices) !== null && _h !== void 0 ? _h : []) {
727
+ checkIsExample(v);
728
+ }
729
+ // statements
730
+ for (const v of (_j = cardNode.statements) !== null && _j !== void 0 ? _j : []) {
731
+ checkIsExample(v);
732
+ }
733
+ // statement
734
+ checkIsExample(cardNode.statement);
735
+ // NO: elements
736
+ // questions
737
+ for (const v of (_k = cardNode.questions) !== null && _k !== void 0 ? _k : []) {
738
+ checkIsExample(v);
739
+ }
740
+ }
741
+ // Bit level
742
+ // statement
743
+ checkIsExample(bit.statement);
744
+ // responses
745
+ for (const v of (_l = bit.responses) !== null && _l !== void 0 ? _l : []) {
746
+ checkIsExample(v);
747
+ }
748
+ // choices
749
+ for (const v of (_m = bit.choices) !== null && _m !== void 0 ? _m : []) {
750
+ checkIsExample(v);
751
+ }
752
+ // Bit itself
753
+ checkIsExample(bit);
754
+ }
589
755
  setDefaultBitValues(bit) {
590
756
  // Set AIGenerated == true for all AI generated bits
591
757
  switch (bit.bitType) {