@examind/block-sdk 0.1.21 → 0.1.22
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 +43 -22
- package/dist/index.mjs +43 -22
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -289,7 +289,10 @@ var ImageNodeHandler = class extends NodeHandler {
|
|
|
289
289
|
return styleProps.length ? `style="${styleProps.join(" ")}"` : null;
|
|
290
290
|
}
|
|
291
291
|
captionStyleAttribute(node) {
|
|
292
|
-
const styleProps = this.fillStyleWidth(
|
|
292
|
+
const styleProps = this.fillStyleWidth(
|
|
293
|
+
["text-align: center;"],
|
|
294
|
+
node
|
|
295
|
+
);
|
|
293
296
|
return styleProps.length ? `style="${styleProps.join(" ")}"` : null;
|
|
294
297
|
}
|
|
295
298
|
imageAttributes(node) {
|
|
@@ -304,6 +307,12 @@ var ImageNodeHandler = class extends NodeHandler {
|
|
|
304
307
|
const attributes = [this.captionStyleAttribute(node)].filter(Boolean).join(" ");
|
|
305
308
|
return attributes;
|
|
306
309
|
}
|
|
310
|
+
captionHtml(node) {
|
|
311
|
+
if (!node.showCaption) {
|
|
312
|
+
return "";
|
|
313
|
+
}
|
|
314
|
+
return `<p ${this.captionAttributes(node)}>${createHtmlFromNestedEditor(node.caption, { parentNode: node })}</p>`;
|
|
315
|
+
}
|
|
307
316
|
wrapContainer(node, imageHtml, captionHtml) {
|
|
308
317
|
const styles = [
|
|
309
318
|
"display: flex;",
|
|
@@ -319,7 +328,7 @@ var ImageNodeHandler = class extends NodeHandler {
|
|
|
319
328
|
return this.wrapContainer(
|
|
320
329
|
node,
|
|
321
330
|
`<img ${this.imageAttributes(node)} />`,
|
|
322
|
-
|
|
331
|
+
this.captionHtml(node)
|
|
323
332
|
);
|
|
324
333
|
}
|
|
325
334
|
};
|
|
@@ -598,7 +607,11 @@ var ELEMENT_TYPE_TO_FORMAT = {
|
|
|
598
607
|
var ParagraphNodeHandler = class extends NodeHandler {
|
|
599
608
|
shouldAvoidParagraphWrap(node) {
|
|
600
609
|
if (node === void 0) return false;
|
|
601
|
-
return isSerializedFillInTheBlankQuestionNode(node) || isSerializedFinancialStatementQuestionNode(node) || isSerializedJournalEntryQuestionNode(node) || isSerializedMatchingQuestionNode(node) || isSerializedMultipleOptionQuestionNode(node) || isSerializedShortAnswerQuestionNode(node) || isSerializedTableCellNode(node);
|
|
610
|
+
return isSerializedFillInTheBlankQuestionNode(node) || isSerializedFinancialStatementQuestionNode(node) || isSerializedJournalEntryQuestionNode(node) || isSerializedMatchingQuestionNode(node) || isSerializedMultipleOptionQuestionNode(node) || isSerializedShortAnswerQuestionNode(node) || isSerializedTableCellNode(node) || isSerializedImageNode(node);
|
|
611
|
+
}
|
|
612
|
+
shouldAvoidDivWrap(node) {
|
|
613
|
+
if (node === void 0) return false;
|
|
614
|
+
return isSerializedImageNode(node);
|
|
602
615
|
}
|
|
603
616
|
processNode(node, metadata) {
|
|
604
617
|
if (!isSerializedParagraphNode(node)) return null;
|
|
@@ -614,7 +627,7 @@ var ParagraphNodeHandler = class extends NodeHandler {
|
|
|
614
627
|
});
|
|
615
628
|
const attribute = node.format ? ` style="text-align: ${ELEMENT_TYPE_TO_FORMAT[node.format]};"` : "";
|
|
616
629
|
if (this.shouldAvoidParagraphWrap(metadata?.parentNode))
|
|
617
|
-
if (attribute)
|
|
630
|
+
if (attribute && !this.shouldAvoidDivWrap(metadata?.parentNode))
|
|
618
631
|
return `<div${attribute}>${children.join("")}</div>`;
|
|
619
632
|
else return children.join("");
|
|
620
633
|
return `<p${attribute}>${children.join("")}</p>`;
|
|
@@ -998,6 +1011,31 @@ var createNestedNodesFromHtml = (node) => {
|
|
|
998
1011
|
};
|
|
999
1012
|
|
|
1000
1013
|
// src/importFromHtml/createImageNode.ts
|
|
1014
|
+
var createCaptionNode = (caption) => {
|
|
1015
|
+
if (!caption) {
|
|
1016
|
+
return [];
|
|
1017
|
+
}
|
|
1018
|
+
const captionNode = createEmptyParagraphNode("center");
|
|
1019
|
+
captionNode.children = caption.split("\n").reduce((nodes, line, index, lines) => {
|
|
1020
|
+
nodes.push({
|
|
1021
|
+
detail: 0,
|
|
1022
|
+
format: 0,
|
|
1023
|
+
mode: "normal",
|
|
1024
|
+
style: "",
|
|
1025
|
+
text: line,
|
|
1026
|
+
type: "text",
|
|
1027
|
+
version: 1
|
|
1028
|
+
});
|
|
1029
|
+
if (index < lines.length - 1) {
|
|
1030
|
+
nodes.push({
|
|
1031
|
+
type: "linebreak",
|
|
1032
|
+
version: 1
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
return nodes;
|
|
1036
|
+
}, []);
|
|
1037
|
+
return [captionNode];
|
|
1038
|
+
};
|
|
1001
1039
|
function createImageNode(src, altText, width, align, showBorder, caption) {
|
|
1002
1040
|
return {
|
|
1003
1041
|
src,
|
|
@@ -1009,24 +1047,7 @@ function createImageNode(src, altText, width, align, showBorder, caption) {
|
|
|
1009
1047
|
caption: {
|
|
1010
1048
|
editorState: {
|
|
1011
1049
|
root: {
|
|
1012
|
-
children: caption
|
|
1013
|
-
nodes.push({
|
|
1014
|
-
detail: 0,
|
|
1015
|
-
format: 0,
|
|
1016
|
-
mode: "normal",
|
|
1017
|
-
style: "",
|
|
1018
|
-
text: line,
|
|
1019
|
-
type: "text",
|
|
1020
|
-
version: 1
|
|
1021
|
-
});
|
|
1022
|
-
if (index < lines.length - 1) {
|
|
1023
|
-
nodes.push({
|
|
1024
|
-
type: "linebreak",
|
|
1025
|
-
version: 1
|
|
1026
|
-
});
|
|
1027
|
-
}
|
|
1028
|
-
return nodes;
|
|
1029
|
-
}, []) : [],
|
|
1050
|
+
children: createCaptionNode(caption),
|
|
1030
1051
|
direction: null,
|
|
1031
1052
|
format: "",
|
|
1032
1053
|
indent: 0,
|
package/dist/index.mjs
CHANGED
|
@@ -262,7 +262,10 @@ var ImageNodeHandler = class extends NodeHandler {
|
|
|
262
262
|
return styleProps.length ? `style="${styleProps.join(" ")}"` : null;
|
|
263
263
|
}
|
|
264
264
|
captionStyleAttribute(node) {
|
|
265
|
-
const styleProps = this.fillStyleWidth(
|
|
265
|
+
const styleProps = this.fillStyleWidth(
|
|
266
|
+
["text-align: center;"],
|
|
267
|
+
node
|
|
268
|
+
);
|
|
266
269
|
return styleProps.length ? `style="${styleProps.join(" ")}"` : null;
|
|
267
270
|
}
|
|
268
271
|
imageAttributes(node) {
|
|
@@ -277,6 +280,12 @@ var ImageNodeHandler = class extends NodeHandler {
|
|
|
277
280
|
const attributes = [this.captionStyleAttribute(node)].filter(Boolean).join(" ");
|
|
278
281
|
return attributes;
|
|
279
282
|
}
|
|
283
|
+
captionHtml(node) {
|
|
284
|
+
if (!node.showCaption) {
|
|
285
|
+
return "";
|
|
286
|
+
}
|
|
287
|
+
return `<p ${this.captionAttributes(node)}>${createHtmlFromNestedEditor(node.caption, { parentNode: node })}</p>`;
|
|
288
|
+
}
|
|
280
289
|
wrapContainer(node, imageHtml, captionHtml) {
|
|
281
290
|
const styles = [
|
|
282
291
|
"display: flex;",
|
|
@@ -292,7 +301,7 @@ var ImageNodeHandler = class extends NodeHandler {
|
|
|
292
301
|
return this.wrapContainer(
|
|
293
302
|
node,
|
|
294
303
|
`<img ${this.imageAttributes(node)} />`,
|
|
295
|
-
|
|
304
|
+
this.captionHtml(node)
|
|
296
305
|
);
|
|
297
306
|
}
|
|
298
307
|
};
|
|
@@ -571,7 +580,11 @@ var ELEMENT_TYPE_TO_FORMAT = {
|
|
|
571
580
|
var ParagraphNodeHandler = class extends NodeHandler {
|
|
572
581
|
shouldAvoidParagraphWrap(node) {
|
|
573
582
|
if (node === void 0) return false;
|
|
574
|
-
return isSerializedFillInTheBlankQuestionNode(node) || isSerializedFinancialStatementQuestionNode(node) || isSerializedJournalEntryQuestionNode(node) || isSerializedMatchingQuestionNode(node) || isSerializedMultipleOptionQuestionNode(node) || isSerializedShortAnswerQuestionNode(node) || isSerializedTableCellNode(node);
|
|
583
|
+
return isSerializedFillInTheBlankQuestionNode(node) || isSerializedFinancialStatementQuestionNode(node) || isSerializedJournalEntryQuestionNode(node) || isSerializedMatchingQuestionNode(node) || isSerializedMultipleOptionQuestionNode(node) || isSerializedShortAnswerQuestionNode(node) || isSerializedTableCellNode(node) || isSerializedImageNode(node);
|
|
584
|
+
}
|
|
585
|
+
shouldAvoidDivWrap(node) {
|
|
586
|
+
if (node === void 0) return false;
|
|
587
|
+
return isSerializedImageNode(node);
|
|
575
588
|
}
|
|
576
589
|
processNode(node, metadata) {
|
|
577
590
|
if (!isSerializedParagraphNode(node)) return null;
|
|
@@ -587,7 +600,7 @@ var ParagraphNodeHandler = class extends NodeHandler {
|
|
|
587
600
|
});
|
|
588
601
|
const attribute = node.format ? ` style="text-align: ${ELEMENT_TYPE_TO_FORMAT[node.format]};"` : "";
|
|
589
602
|
if (this.shouldAvoidParagraphWrap(metadata?.parentNode))
|
|
590
|
-
if (attribute)
|
|
603
|
+
if (attribute && !this.shouldAvoidDivWrap(metadata?.parentNode))
|
|
591
604
|
return `<div${attribute}>${children.join("")}</div>`;
|
|
592
605
|
else return children.join("");
|
|
593
606
|
return `<p${attribute}>${children.join("")}</p>`;
|
|
@@ -971,6 +984,31 @@ var createNestedNodesFromHtml = (node) => {
|
|
|
971
984
|
};
|
|
972
985
|
|
|
973
986
|
// src/importFromHtml/createImageNode.ts
|
|
987
|
+
var createCaptionNode = (caption) => {
|
|
988
|
+
if (!caption) {
|
|
989
|
+
return [];
|
|
990
|
+
}
|
|
991
|
+
const captionNode = createEmptyParagraphNode("center");
|
|
992
|
+
captionNode.children = caption.split("\n").reduce((nodes, line, index, lines) => {
|
|
993
|
+
nodes.push({
|
|
994
|
+
detail: 0,
|
|
995
|
+
format: 0,
|
|
996
|
+
mode: "normal",
|
|
997
|
+
style: "",
|
|
998
|
+
text: line,
|
|
999
|
+
type: "text",
|
|
1000
|
+
version: 1
|
|
1001
|
+
});
|
|
1002
|
+
if (index < lines.length - 1) {
|
|
1003
|
+
nodes.push({
|
|
1004
|
+
type: "linebreak",
|
|
1005
|
+
version: 1
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
return nodes;
|
|
1009
|
+
}, []);
|
|
1010
|
+
return [captionNode];
|
|
1011
|
+
};
|
|
974
1012
|
function createImageNode(src, altText, width, align, showBorder, caption) {
|
|
975
1013
|
return {
|
|
976
1014
|
src,
|
|
@@ -982,24 +1020,7 @@ function createImageNode(src, altText, width, align, showBorder, caption) {
|
|
|
982
1020
|
caption: {
|
|
983
1021
|
editorState: {
|
|
984
1022
|
root: {
|
|
985
|
-
children: caption
|
|
986
|
-
nodes.push({
|
|
987
|
-
detail: 0,
|
|
988
|
-
format: 0,
|
|
989
|
-
mode: "normal",
|
|
990
|
-
style: "",
|
|
991
|
-
text: line,
|
|
992
|
-
type: "text",
|
|
993
|
-
version: 1
|
|
994
|
-
});
|
|
995
|
-
if (index < lines.length - 1) {
|
|
996
|
-
nodes.push({
|
|
997
|
-
type: "linebreak",
|
|
998
|
-
version: 1
|
|
999
|
-
});
|
|
1000
|
-
}
|
|
1001
|
-
return nodes;
|
|
1002
|
-
}, []) : [],
|
|
1023
|
+
children: createCaptionNode(caption),
|
|
1003
1024
|
direction: null,
|
|
1004
1025
|
format: "",
|
|
1005
1026
|
indent: 0,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@examind/block-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.22",
|
|
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.1.
|
|
24
|
+
"@examind/block-types": "^0.1.22"
|
|
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.1.
|
|
39
|
+
"@examind/block-types": "0.1.22"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"lodash-es": "4.17.21"
|