@examind/block-sdk 0.2.3 → 0.2.4
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.
- package/dist/index.js +62 -58
- package/dist/index.mjs +62 -58
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -114,6 +114,56 @@ function isSerializedParagraphNode(node) {
|
|
|
114
114
|
return node?.type === "paragraph" && "textFormat" in node && typeof node.textFormat === "number" && "textStyle" in node && typeof node.textStyle === "string";
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
// src/typeGuards/isSerializedFillInTheBlankQuestionNode.ts
|
|
118
|
+
function isSerializedFillInTheBlankQuestionNode(node) {
|
|
119
|
+
return node?.type === "fill-in-the-blank-question" && "id" in node && typeof node.id === "string" && "pointsPerSpace" in node && typeof node.pointsPerSpace === "number" && "content" in node;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/typeGuards/isSerializedFinancialStatementQuestionNode.ts
|
|
123
|
+
function isSerializedFinancialStatementQuestionNode(node) {
|
|
124
|
+
return node?.type === "financial-statement-question" && "id" in node && typeof node.id === "string" && "points" in node && typeof node.points === "number" && "header" in node && "columnHeaders" in node && Array.isArray(node.columnHeaders) && "rows" in node && Array.isArray(node.rows) && "distractors" in node && Array.isArray(node.distractors);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/typeGuards/isSerializedImageNode.ts
|
|
128
|
+
var isSerializedImageNode = (node) => {
|
|
129
|
+
return node?.type === "image" && "altText" in node && typeof node.altText === "string" && "caption" in node && "showCaption" in node && typeof node.showCaption === "boolean" && "src" in node && typeof node.src === "string" && "width" in node && typeof node.width === "string" && "align" in node && typeof node.align === "string" && "showBorder" in node && typeof node.showBorder === "boolean";
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// src/typeGuards/isSerializedJournalEntryQuestionNode.ts
|
|
133
|
+
function isSerializedJournalEntryQuestionNode(node) {
|
|
134
|
+
return node?.type === "journal-entry-question" && "id" in node && typeof node.id === "string" && "points" in node && typeof node.points === "number" && "lineItems" in node && Array.isArray(node.lineItems);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/typeGuards/isSerializedMatchingQuestionNode.ts
|
|
138
|
+
function isSerializedMatchingQuestionNode(node) {
|
|
139
|
+
return node?.type === "matching-question" && "id" in node && typeof node.id === "string" && "pointsPerMatch" in node && typeof node.pointsPerMatch === "number" && "items" in node && Array.isArray(node.items);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/typeGuards/isSerializedMultipleOptionQuestionNode.ts
|
|
143
|
+
function isSerializedMultipleOptionQuestionNode(node) {
|
|
144
|
+
return node?.type === "multiple-option-question" && "id" in node && typeof node.id === "string" && "questionType" in node && typeof node.questionType === "string" && "points" in node && typeof node.points === "number" && "options" in node && Array.isArray(node.options);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/typeGuards/isSerializedShortAnswerQuestionNode.ts
|
|
148
|
+
function isSerializedShortAnswerQuestionNode(node) {
|
|
149
|
+
return node?.type === "short-answer-question" && "id" in node && typeof node.id === "string" && "points" in node && typeof node.points === "number" && "maxWords" in node && typeof node.maxWords === "number" && "notes" in node;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/typeGuards/isSerializedTableCellNode.ts
|
|
153
|
+
function isSerializedTableCellNode(node) {
|
|
154
|
+
return node?.type === "tablecell" && "headerState" in node && typeof node.headerState === "number";
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// src/exportToHtml/shouldAvoidWrap.ts
|
|
158
|
+
function shouldAvoidParagraphWrap(parentNode) {
|
|
159
|
+
if (parentNode === void 0) return false;
|
|
160
|
+
return isSerializedFillInTheBlankQuestionNode(parentNode) || isSerializedFinancialStatementQuestionNode(parentNode) || isSerializedJournalEntryQuestionNode(parentNode) || isSerializedMatchingQuestionNode(parentNode) || isSerializedMultipleOptionQuestionNode(parentNode) || isSerializedShortAnswerQuestionNode(parentNode) || isSerializedTableCellNode(parentNode) || isSerializedImageNode(parentNode);
|
|
161
|
+
}
|
|
162
|
+
function shouldAvoidDivWrap(parentNode) {
|
|
163
|
+
if (parentNode === void 0) return false;
|
|
164
|
+
return isSerializedImageNode(parentNode);
|
|
165
|
+
}
|
|
166
|
+
|
|
117
167
|
// src/exportToHtml/createHtmlFromNestedNodes.ts
|
|
118
168
|
function createHtmlFromNestedNodes(nodes, metadata) {
|
|
119
169
|
const children = [];
|
|
@@ -122,8 +172,8 @@ function createHtmlFromNestedNodes(nodes, metadata) {
|
|
|
122
172
|
const isParagraph = isSerializedParagraphNode(child);
|
|
123
173
|
const element = traverse(child, metadata);
|
|
124
174
|
if (element) {
|
|
125
|
-
if (
|
|
126
|
-
children.push("<br>");
|
|
175
|
+
if (shouldAvoidParagraphWrap(metadata?.parentNode)) {
|
|
176
|
+
if (prevWasParagraph && isParagraph) children.push("<br>");
|
|
127
177
|
}
|
|
128
178
|
children.push(element);
|
|
129
179
|
prevWasParagraph = isParagraph;
|
|
@@ -140,8 +190,10 @@ function createHtmlFromNestedEditor(editor, metadata) {
|
|
|
140
190
|
}
|
|
141
191
|
|
|
142
192
|
// src/exportToHtml/ExcelQuestionNodeHandler.ts
|
|
143
|
-
var htmlOrNullIfEmpty = (editor) => {
|
|
144
|
-
const html = createHtmlFromNestedEditor(editor
|
|
193
|
+
var htmlOrNullIfEmpty = (editor, node) => {
|
|
194
|
+
const html = createHtmlFromNestedEditor(editor, {
|
|
195
|
+
parentNode: node
|
|
196
|
+
});
|
|
145
197
|
return !html || html === "<p></p>" ? null : html;
|
|
146
198
|
};
|
|
147
199
|
var ExcelQuestionNodeHandler = class extends NodeHandler {
|
|
@@ -151,14 +203,14 @@ var ExcelQuestionNodeHandler = class extends NodeHandler {
|
|
|
151
203
|
...node.data,
|
|
152
204
|
parts: node.data.parts.map((p) => ({
|
|
153
205
|
...p,
|
|
154
|
-
objective: htmlOrNullIfEmpty(p.objective),
|
|
155
|
-
instructions: htmlOrNullIfEmpty(p.instructions),
|
|
206
|
+
objective: htmlOrNullIfEmpty(p.objective, node),
|
|
207
|
+
instructions: htmlOrNullIfEmpty(p.instructions, node),
|
|
156
208
|
tasks: p.tasks.map((t) => ({
|
|
157
209
|
...t,
|
|
158
|
-
instructions: htmlOrNullIfEmpty(t.instructions),
|
|
210
|
+
instructions: htmlOrNullIfEmpty(t.instructions, node),
|
|
159
211
|
steps: t.steps.map((s) => ({
|
|
160
212
|
...s,
|
|
161
|
-
description: htmlOrNullIfEmpty(s.description)
|
|
213
|
+
description: htmlOrNullIfEmpty(s.description, node)
|
|
162
214
|
}))
|
|
163
215
|
}))
|
|
164
216
|
}))
|
|
@@ -180,11 +232,6 @@ var ExcelWorksheetLinkNodeHandler = class extends NodeHandler {
|
|
|
180
232
|
}
|
|
181
233
|
};
|
|
182
234
|
|
|
183
|
-
// src/typeGuards/isSerializedFillInTheBlankQuestionNode.ts
|
|
184
|
-
function isSerializedFillInTheBlankQuestionNode(node) {
|
|
185
|
-
return node?.type === "fill-in-the-blank-question" && "id" in node && typeof node.id === "string" && "pointsPerSpace" in node && typeof node.pointsPerSpace === "number" && "content" in node;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
235
|
// src/exportToHtml/FillInTheBlankQuestionNodeHandler.ts
|
|
189
236
|
var FillInTheBlankQuestionNodeHandler = class extends NodeHandler {
|
|
190
237
|
processNode(node) {
|
|
@@ -240,11 +287,6 @@ var FillInTheBlankSpaceNodeHandler = class extends NodeHandler {
|
|
|
240
287
|
}
|
|
241
288
|
};
|
|
242
289
|
|
|
243
|
-
// src/typeGuards/isSerializedFinancialStatementQuestionNode.ts
|
|
244
|
-
function isSerializedFinancialStatementQuestionNode(node) {
|
|
245
|
-
return node?.type === "financial-statement-question" && "id" in node && typeof node.id === "string" && "points" in node && typeof node.points === "number" && "header" in node && "columnHeaders" in node && Array.isArray(node.columnHeaders) && "rows" in node && Array.isArray(node.rows) && "distractors" in node && Array.isArray(node.distractors);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
290
|
// src/exportToHtml/FinancialStatementQuestionNodeHandler.ts
|
|
249
291
|
var isHeading = (row) => {
|
|
250
292
|
return row.type === "Heading";
|
|
@@ -374,11 +416,6 @@ var HorizontalRuleNodeHandler = class extends NodeHandler {
|
|
|
374
416
|
var IMAGE_CONTAINER_ATTRIBUTE = "data-block-image-container";
|
|
375
417
|
var IMAGE_CONTAINER_CLASS = "block-image-container";
|
|
376
418
|
|
|
377
|
-
// src/typeGuards/isSerializedImageNode.ts
|
|
378
|
-
var isSerializedImageNode = (node) => {
|
|
379
|
-
return node?.type === "image" && "altText" in node && typeof node.altText === "string" && "caption" in node && "showCaption" in node && typeof node.showCaption === "boolean" && "src" in node && typeof node.src === "string" && "width" in node && typeof node.width === "string" && "align" in node && typeof node.align === "string" && "showBorder" in node && typeof node.showBorder === "boolean";
|
|
380
|
-
};
|
|
381
|
-
|
|
382
419
|
// src/exportToHtml/ImageNodeHandler.ts
|
|
383
420
|
var ImageNodeHandler = class extends NodeHandler {
|
|
384
421
|
alignItemsAttribute(node) {
|
|
@@ -449,11 +486,6 @@ var ImageNodeHandler = class extends NodeHandler {
|
|
|
449
486
|
}
|
|
450
487
|
};
|
|
451
488
|
|
|
452
|
-
// src/typeGuards/isSerializedJournalEntryQuestionNode.ts
|
|
453
|
-
function isSerializedJournalEntryQuestionNode(node) {
|
|
454
|
-
return node?.type === "journal-entry-question" && "id" in node && typeof node.id === "string" && "points" in node && typeof node.points === "number" && "lineItems" in node && Array.isArray(node.lineItems);
|
|
455
|
-
}
|
|
456
|
-
|
|
457
489
|
// src/exportToHtml/createHtmlFromOnePerLineDistractorNodes.ts
|
|
458
490
|
function createHtmlFromOnePerLineDistractorNodes(distractorNodes, parentNode) {
|
|
459
491
|
const distractors = distractorNodes.map((node) => {
|
|
@@ -594,11 +626,6 @@ var ListNodeHandler = class extends NodeHandler {
|
|
|
594
626
|
}
|
|
595
627
|
};
|
|
596
628
|
|
|
597
|
-
// src/typeGuards/isSerializedMatchingQuestionNode.ts
|
|
598
|
-
function isSerializedMatchingQuestionNode(node) {
|
|
599
|
-
return node?.type === "matching-question" && "id" in node && typeof node.id === "string" && "pointsPerMatch" in node && typeof node.pointsPerMatch === "number" && "items" in node && Array.isArray(node.items);
|
|
600
|
-
}
|
|
601
|
-
|
|
602
629
|
// src/exportToHtml/MatchingQuestionNodeHandler.ts
|
|
603
630
|
var MatchingQuestionNodeHandler = class extends NodeHandler {
|
|
604
631
|
processNode(node) {
|
|
@@ -635,11 +662,6 @@ var MatchingQuestionNodeHandler = class extends NodeHandler {
|
|
|
635
662
|
}
|
|
636
663
|
};
|
|
637
664
|
|
|
638
|
-
// src/typeGuards/isSerializedMultipleOptionQuestionNode.ts
|
|
639
|
-
function isSerializedMultipleOptionQuestionNode(node) {
|
|
640
|
-
return node?.type === "multiple-option-question" && "id" in node && typeof node.id === "string" && "questionType" in node && typeof node.questionType === "string" && "points" in node && typeof node.points === "number" && "options" in node && Array.isArray(node.options);
|
|
641
|
-
}
|
|
642
|
-
|
|
643
665
|
// src/exportToHtml/MultipleOptionQuestionNodeHandler.ts
|
|
644
666
|
var MultipleOptionQuestionNodeHandler = class extends NodeHandler {
|
|
645
667
|
processNode(node) {
|
|
@@ -699,26 +721,8 @@ var MultipleOptionQuestionNodeHandler = class extends NodeHandler {
|
|
|
699
721
|
}
|
|
700
722
|
};
|
|
701
723
|
|
|
702
|
-
// src/typeGuards/isSerializedShortAnswerQuestionNode.ts
|
|
703
|
-
function isSerializedShortAnswerQuestionNode(node) {
|
|
704
|
-
return node?.type === "short-answer-question" && "id" in node && typeof node.id === "string" && "points" in node && typeof node.points === "number" && "maxWords" in node && typeof node.maxWords === "number" && "notes" in node;
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
// src/typeGuards/isSerializedTableCellNode.ts
|
|
708
|
-
function isSerializedTableCellNode(node) {
|
|
709
|
-
return node?.type === "tablecell" && "headerState" in node && typeof node.headerState === "number";
|
|
710
|
-
}
|
|
711
|
-
|
|
712
724
|
// src/exportToHtml/ParagraphNodeHandler.ts
|
|
713
725
|
var ParagraphNodeHandler = class extends NodeHandler {
|
|
714
|
-
shouldAvoidParagraphWrap(node) {
|
|
715
|
-
if (node === void 0) return false;
|
|
716
|
-
return isSerializedFillInTheBlankQuestionNode(node) || isSerializedFinancialStatementQuestionNode(node) || isSerializedJournalEntryQuestionNode(node) || isSerializedMatchingQuestionNode(node) || isSerializedMultipleOptionQuestionNode(node) || isSerializedShortAnswerQuestionNode(node) || isSerializedTableCellNode(node) || isSerializedImageNode(node);
|
|
717
|
-
}
|
|
718
|
-
shouldAvoidDivWrap(node) {
|
|
719
|
-
if (node === void 0) return false;
|
|
720
|
-
return isSerializedImageNode(node);
|
|
721
|
-
}
|
|
722
726
|
processNode(node, metadata) {
|
|
723
727
|
if (!isSerializedParagraphNode(node)) return null;
|
|
724
728
|
const children = [];
|
|
@@ -732,8 +736,8 @@ var ParagraphNodeHandler = class extends NodeHandler {
|
|
|
732
736
|
}
|
|
733
737
|
});
|
|
734
738
|
const attribute = node.format ? ` style="text-align: ${ELEMENT_TYPE_TO_FORMAT[node.format]};"` : "";
|
|
735
|
-
if (
|
|
736
|
-
if (attribute && !
|
|
739
|
+
if (shouldAvoidParagraphWrap(metadata?.parentNode))
|
|
740
|
+
if (attribute && !shouldAvoidDivWrap(metadata?.parentNode))
|
|
737
741
|
return `<div${attribute}>${children.join("")}</div>`;
|
|
738
742
|
else return children.join("");
|
|
739
743
|
return `<p${attribute}>${children.join("")}</p>`;
|
package/dist/index.mjs
CHANGED
|
@@ -87,6 +87,56 @@ function isSerializedParagraphNode(node) {
|
|
|
87
87
|
return node?.type === "paragraph" && "textFormat" in node && typeof node.textFormat === "number" && "textStyle" in node && typeof node.textStyle === "string";
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
// src/typeGuards/isSerializedFillInTheBlankQuestionNode.ts
|
|
91
|
+
function isSerializedFillInTheBlankQuestionNode(node) {
|
|
92
|
+
return node?.type === "fill-in-the-blank-question" && "id" in node && typeof node.id === "string" && "pointsPerSpace" in node && typeof node.pointsPerSpace === "number" && "content" in node;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/typeGuards/isSerializedFinancialStatementQuestionNode.ts
|
|
96
|
+
function isSerializedFinancialStatementQuestionNode(node) {
|
|
97
|
+
return node?.type === "financial-statement-question" && "id" in node && typeof node.id === "string" && "points" in node && typeof node.points === "number" && "header" in node && "columnHeaders" in node && Array.isArray(node.columnHeaders) && "rows" in node && Array.isArray(node.rows) && "distractors" in node && Array.isArray(node.distractors);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/typeGuards/isSerializedImageNode.ts
|
|
101
|
+
var isSerializedImageNode = (node) => {
|
|
102
|
+
return node?.type === "image" && "altText" in node && typeof node.altText === "string" && "caption" in node && "showCaption" in node && typeof node.showCaption === "boolean" && "src" in node && typeof node.src === "string" && "width" in node && typeof node.width === "string" && "align" in node && typeof node.align === "string" && "showBorder" in node && typeof node.showBorder === "boolean";
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// src/typeGuards/isSerializedJournalEntryQuestionNode.ts
|
|
106
|
+
function isSerializedJournalEntryQuestionNode(node) {
|
|
107
|
+
return node?.type === "journal-entry-question" && "id" in node && typeof node.id === "string" && "points" in node && typeof node.points === "number" && "lineItems" in node && Array.isArray(node.lineItems);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/typeGuards/isSerializedMatchingQuestionNode.ts
|
|
111
|
+
function isSerializedMatchingQuestionNode(node) {
|
|
112
|
+
return node?.type === "matching-question" && "id" in node && typeof node.id === "string" && "pointsPerMatch" in node && typeof node.pointsPerMatch === "number" && "items" in node && Array.isArray(node.items);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/typeGuards/isSerializedMultipleOptionQuestionNode.ts
|
|
116
|
+
function isSerializedMultipleOptionQuestionNode(node) {
|
|
117
|
+
return node?.type === "multiple-option-question" && "id" in node && typeof node.id === "string" && "questionType" in node && typeof node.questionType === "string" && "points" in node && typeof node.points === "number" && "options" in node && Array.isArray(node.options);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/typeGuards/isSerializedShortAnswerQuestionNode.ts
|
|
121
|
+
function isSerializedShortAnswerQuestionNode(node) {
|
|
122
|
+
return node?.type === "short-answer-question" && "id" in node && typeof node.id === "string" && "points" in node && typeof node.points === "number" && "maxWords" in node && typeof node.maxWords === "number" && "notes" in node;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/typeGuards/isSerializedTableCellNode.ts
|
|
126
|
+
function isSerializedTableCellNode(node) {
|
|
127
|
+
return node?.type === "tablecell" && "headerState" in node && typeof node.headerState === "number";
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/exportToHtml/shouldAvoidWrap.ts
|
|
131
|
+
function shouldAvoidParagraphWrap(parentNode) {
|
|
132
|
+
if (parentNode === void 0) return false;
|
|
133
|
+
return isSerializedFillInTheBlankQuestionNode(parentNode) || isSerializedFinancialStatementQuestionNode(parentNode) || isSerializedJournalEntryQuestionNode(parentNode) || isSerializedMatchingQuestionNode(parentNode) || isSerializedMultipleOptionQuestionNode(parentNode) || isSerializedShortAnswerQuestionNode(parentNode) || isSerializedTableCellNode(parentNode) || isSerializedImageNode(parentNode);
|
|
134
|
+
}
|
|
135
|
+
function shouldAvoidDivWrap(parentNode) {
|
|
136
|
+
if (parentNode === void 0) return false;
|
|
137
|
+
return isSerializedImageNode(parentNode);
|
|
138
|
+
}
|
|
139
|
+
|
|
90
140
|
// src/exportToHtml/createHtmlFromNestedNodes.ts
|
|
91
141
|
function createHtmlFromNestedNodes(nodes, metadata) {
|
|
92
142
|
const children = [];
|
|
@@ -95,8 +145,8 @@ function createHtmlFromNestedNodes(nodes, metadata) {
|
|
|
95
145
|
const isParagraph = isSerializedParagraphNode(child);
|
|
96
146
|
const element = traverse(child, metadata);
|
|
97
147
|
if (element) {
|
|
98
|
-
if (
|
|
99
|
-
children.push("<br>");
|
|
148
|
+
if (shouldAvoidParagraphWrap(metadata?.parentNode)) {
|
|
149
|
+
if (prevWasParagraph && isParagraph) children.push("<br>");
|
|
100
150
|
}
|
|
101
151
|
children.push(element);
|
|
102
152
|
prevWasParagraph = isParagraph;
|
|
@@ -113,8 +163,10 @@ function createHtmlFromNestedEditor(editor, metadata) {
|
|
|
113
163
|
}
|
|
114
164
|
|
|
115
165
|
// src/exportToHtml/ExcelQuestionNodeHandler.ts
|
|
116
|
-
var htmlOrNullIfEmpty = (editor) => {
|
|
117
|
-
const html = createHtmlFromNestedEditor(editor
|
|
166
|
+
var htmlOrNullIfEmpty = (editor, node) => {
|
|
167
|
+
const html = createHtmlFromNestedEditor(editor, {
|
|
168
|
+
parentNode: node
|
|
169
|
+
});
|
|
118
170
|
return !html || html === "<p></p>" ? null : html;
|
|
119
171
|
};
|
|
120
172
|
var ExcelQuestionNodeHandler = class extends NodeHandler {
|
|
@@ -124,14 +176,14 @@ var ExcelQuestionNodeHandler = class extends NodeHandler {
|
|
|
124
176
|
...node.data,
|
|
125
177
|
parts: node.data.parts.map((p) => ({
|
|
126
178
|
...p,
|
|
127
|
-
objective: htmlOrNullIfEmpty(p.objective),
|
|
128
|
-
instructions: htmlOrNullIfEmpty(p.instructions),
|
|
179
|
+
objective: htmlOrNullIfEmpty(p.objective, node),
|
|
180
|
+
instructions: htmlOrNullIfEmpty(p.instructions, node),
|
|
129
181
|
tasks: p.tasks.map((t) => ({
|
|
130
182
|
...t,
|
|
131
|
-
instructions: htmlOrNullIfEmpty(t.instructions),
|
|
183
|
+
instructions: htmlOrNullIfEmpty(t.instructions, node),
|
|
132
184
|
steps: t.steps.map((s) => ({
|
|
133
185
|
...s,
|
|
134
|
-
description: htmlOrNullIfEmpty(s.description)
|
|
186
|
+
description: htmlOrNullIfEmpty(s.description, node)
|
|
135
187
|
}))
|
|
136
188
|
}))
|
|
137
189
|
}))
|
|
@@ -153,11 +205,6 @@ var ExcelWorksheetLinkNodeHandler = class extends NodeHandler {
|
|
|
153
205
|
}
|
|
154
206
|
};
|
|
155
207
|
|
|
156
|
-
// src/typeGuards/isSerializedFillInTheBlankQuestionNode.ts
|
|
157
|
-
function isSerializedFillInTheBlankQuestionNode(node) {
|
|
158
|
-
return node?.type === "fill-in-the-blank-question" && "id" in node && typeof node.id === "string" && "pointsPerSpace" in node && typeof node.pointsPerSpace === "number" && "content" in node;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
208
|
// src/exportToHtml/FillInTheBlankQuestionNodeHandler.ts
|
|
162
209
|
var FillInTheBlankQuestionNodeHandler = class extends NodeHandler {
|
|
163
210
|
processNode(node) {
|
|
@@ -213,11 +260,6 @@ var FillInTheBlankSpaceNodeHandler = class extends NodeHandler {
|
|
|
213
260
|
}
|
|
214
261
|
};
|
|
215
262
|
|
|
216
|
-
// src/typeGuards/isSerializedFinancialStatementQuestionNode.ts
|
|
217
|
-
function isSerializedFinancialStatementQuestionNode(node) {
|
|
218
|
-
return node?.type === "financial-statement-question" && "id" in node && typeof node.id === "string" && "points" in node && typeof node.points === "number" && "header" in node && "columnHeaders" in node && Array.isArray(node.columnHeaders) && "rows" in node && Array.isArray(node.rows) && "distractors" in node && Array.isArray(node.distractors);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
263
|
// src/exportToHtml/FinancialStatementQuestionNodeHandler.ts
|
|
222
264
|
var isHeading = (row) => {
|
|
223
265
|
return row.type === "Heading";
|
|
@@ -347,11 +389,6 @@ var HorizontalRuleNodeHandler = class extends NodeHandler {
|
|
|
347
389
|
var IMAGE_CONTAINER_ATTRIBUTE = "data-block-image-container";
|
|
348
390
|
var IMAGE_CONTAINER_CLASS = "block-image-container";
|
|
349
391
|
|
|
350
|
-
// src/typeGuards/isSerializedImageNode.ts
|
|
351
|
-
var isSerializedImageNode = (node) => {
|
|
352
|
-
return node?.type === "image" && "altText" in node && typeof node.altText === "string" && "caption" in node && "showCaption" in node && typeof node.showCaption === "boolean" && "src" in node && typeof node.src === "string" && "width" in node && typeof node.width === "string" && "align" in node && typeof node.align === "string" && "showBorder" in node && typeof node.showBorder === "boolean";
|
|
353
|
-
};
|
|
354
|
-
|
|
355
392
|
// src/exportToHtml/ImageNodeHandler.ts
|
|
356
393
|
var ImageNodeHandler = class extends NodeHandler {
|
|
357
394
|
alignItemsAttribute(node) {
|
|
@@ -422,11 +459,6 @@ var ImageNodeHandler = class extends NodeHandler {
|
|
|
422
459
|
}
|
|
423
460
|
};
|
|
424
461
|
|
|
425
|
-
// src/typeGuards/isSerializedJournalEntryQuestionNode.ts
|
|
426
|
-
function isSerializedJournalEntryQuestionNode(node) {
|
|
427
|
-
return node?.type === "journal-entry-question" && "id" in node && typeof node.id === "string" && "points" in node && typeof node.points === "number" && "lineItems" in node && Array.isArray(node.lineItems);
|
|
428
|
-
}
|
|
429
|
-
|
|
430
462
|
// src/exportToHtml/createHtmlFromOnePerLineDistractorNodes.ts
|
|
431
463
|
function createHtmlFromOnePerLineDistractorNodes(distractorNodes, parentNode) {
|
|
432
464
|
const distractors = distractorNodes.map((node) => {
|
|
@@ -567,11 +599,6 @@ var ListNodeHandler = class extends NodeHandler {
|
|
|
567
599
|
}
|
|
568
600
|
};
|
|
569
601
|
|
|
570
|
-
// src/typeGuards/isSerializedMatchingQuestionNode.ts
|
|
571
|
-
function isSerializedMatchingQuestionNode(node) {
|
|
572
|
-
return node?.type === "matching-question" && "id" in node && typeof node.id === "string" && "pointsPerMatch" in node && typeof node.pointsPerMatch === "number" && "items" in node && Array.isArray(node.items);
|
|
573
|
-
}
|
|
574
|
-
|
|
575
602
|
// src/exportToHtml/MatchingQuestionNodeHandler.ts
|
|
576
603
|
var MatchingQuestionNodeHandler = class extends NodeHandler {
|
|
577
604
|
processNode(node) {
|
|
@@ -608,11 +635,6 @@ var MatchingQuestionNodeHandler = class extends NodeHandler {
|
|
|
608
635
|
}
|
|
609
636
|
};
|
|
610
637
|
|
|
611
|
-
// src/typeGuards/isSerializedMultipleOptionQuestionNode.ts
|
|
612
|
-
function isSerializedMultipleOptionQuestionNode(node) {
|
|
613
|
-
return node?.type === "multiple-option-question" && "id" in node && typeof node.id === "string" && "questionType" in node && typeof node.questionType === "string" && "points" in node && typeof node.points === "number" && "options" in node && Array.isArray(node.options);
|
|
614
|
-
}
|
|
615
|
-
|
|
616
638
|
// src/exportToHtml/MultipleOptionQuestionNodeHandler.ts
|
|
617
639
|
var MultipleOptionQuestionNodeHandler = class extends NodeHandler {
|
|
618
640
|
processNode(node) {
|
|
@@ -672,26 +694,8 @@ var MultipleOptionQuestionNodeHandler = class extends NodeHandler {
|
|
|
672
694
|
}
|
|
673
695
|
};
|
|
674
696
|
|
|
675
|
-
// src/typeGuards/isSerializedShortAnswerQuestionNode.ts
|
|
676
|
-
function isSerializedShortAnswerQuestionNode(node) {
|
|
677
|
-
return node?.type === "short-answer-question" && "id" in node && typeof node.id === "string" && "points" in node && typeof node.points === "number" && "maxWords" in node && typeof node.maxWords === "number" && "notes" in node;
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
// src/typeGuards/isSerializedTableCellNode.ts
|
|
681
|
-
function isSerializedTableCellNode(node) {
|
|
682
|
-
return node?.type === "tablecell" && "headerState" in node && typeof node.headerState === "number";
|
|
683
|
-
}
|
|
684
|
-
|
|
685
697
|
// src/exportToHtml/ParagraphNodeHandler.ts
|
|
686
698
|
var ParagraphNodeHandler = class extends NodeHandler {
|
|
687
|
-
shouldAvoidParagraphWrap(node) {
|
|
688
|
-
if (node === void 0) return false;
|
|
689
|
-
return isSerializedFillInTheBlankQuestionNode(node) || isSerializedFinancialStatementQuestionNode(node) || isSerializedJournalEntryQuestionNode(node) || isSerializedMatchingQuestionNode(node) || isSerializedMultipleOptionQuestionNode(node) || isSerializedShortAnswerQuestionNode(node) || isSerializedTableCellNode(node) || isSerializedImageNode(node);
|
|
690
|
-
}
|
|
691
|
-
shouldAvoidDivWrap(node) {
|
|
692
|
-
if (node === void 0) return false;
|
|
693
|
-
return isSerializedImageNode(node);
|
|
694
|
-
}
|
|
695
699
|
processNode(node, metadata) {
|
|
696
700
|
if (!isSerializedParagraphNode(node)) return null;
|
|
697
701
|
const children = [];
|
|
@@ -705,8 +709,8 @@ var ParagraphNodeHandler = class extends NodeHandler {
|
|
|
705
709
|
}
|
|
706
710
|
});
|
|
707
711
|
const attribute = node.format ? ` style="text-align: ${ELEMENT_TYPE_TO_FORMAT[node.format]};"` : "";
|
|
708
|
-
if (
|
|
709
|
-
if (attribute && !
|
|
712
|
+
if (shouldAvoidParagraphWrap(metadata?.parentNode))
|
|
713
|
+
if (attribute && !shouldAvoidDivWrap(metadata?.parentNode))
|
|
710
714
|
return `<div${attribute}>${children.join("")}</div>`;
|
|
711
715
|
else return children.join("");
|
|
712
716
|
return `<p${attribute}>${children.join("")}</p>`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@examind/block-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"@comment version": [
|
|
5
5
|
"Don't specify package version here. It will be injected by publish workflow."
|
|
6
6
|
],
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"nanoid": ">=3.0.0",
|
|
23
23
|
"node-html-parser": ">=6.0.0",
|
|
24
|
-
"@examind/block-types": "^0.2.
|
|
24
|
+
"@examind/block-types": "^0.2.4"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@eslint/js": "^9.17.0",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"tsup": "^8.3.5",
|
|
37
37
|
"typescript": "^5.7.2",
|
|
38
38
|
"typescript-eslint": "^8.18.2",
|
|
39
|
-
"@examind/block-types": "0.2.
|
|
39
|
+
"@examind/block-types": "0.2.4"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"lodash-es": "4.17.21"
|