@examind/block-sdk 0.2.5 → 0.3.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.
package/dist/index.js CHANGED
@@ -264,6 +264,7 @@ var FillInTheBlankSpaceNodeHandler = class extends NodeHandler {
264
264
  `id="${node.id}"`,
265
265
  `data-x-type="${node.spaceType}"`,
266
266
  `data-x-matches="${node.matches}"`,
267
+ `data-x-use-regex="${!!node.useRegex}"`,
267
268
  `data-x-case-sensitive="${!!node.caseSensitive}"`,
268
269
  `data-x-errors-allowed="${node.errorsAllowed ?? 0}"`,
269
270
  `data-x-min-decimals="${node.minDecimals ?? ""}"`,
@@ -347,7 +348,9 @@ var FinancialStatementQuestionNodeHandler = class extends NodeHandler {
347
348
  const amountHintAttr = row.isAmountHint ? ' data-x-is-amount-hint="true"' : "";
348
349
  rowElements.push(
349
350
  `<x-line id="${row.id}" data-x-depth="${row.depth}"${entryHintAttr}${amountHintAttr}>`,
350
- `<x-entry>${row.entry}</x-entry>`,
351
+ `<x-entry>${createHtmlFromNestedEditor(row.entry, {
352
+ parentNode: node
353
+ })}</x-entry>`,
351
354
  `<x-amount>${createHtmlFromNestedEditor(row.amount, {
352
355
  parentNode: node
353
356
  })}</x-amount>`,
@@ -362,7 +365,12 @@ var FinancialStatementQuestionNodeHandler = class extends NodeHandler {
362
365
  return "";
363
366
  }
364
367
  const distractorElements = node.distractors.map(
365
- (distractor) => `<x-distractor id="${distractor.id}">${distractor.entry}</x-distractor>`
368
+ (distractor) => `<x-distractor id="${distractor.id}">${createHtmlFromNestedEditor(
369
+ distractor.entry,
370
+ {
371
+ parentNode: node
372
+ }
373
+ )}</x-distractor>`
366
374
  );
367
375
  return `<x-distractors>${distractorElements.join("")}</x-distractors>`;
368
376
  }
@@ -812,6 +820,9 @@ var TableCellNodeHandler = class extends NodeHandler {
812
820
  } else if (!hasColspan && tableCellNode.width) {
813
821
  styles.push(`width: ${tableCellNode.width}px;`);
814
822
  }
823
+ if (tableCellNode.format) {
824
+ styles.push(`text-align: ${tableCellNode.format};`);
825
+ }
815
826
  if (tableCellNode.backgroundColor) {
816
827
  styles.push(
817
828
  `background-color: ${tableCellNode.backgroundColor};`
@@ -1111,6 +1122,25 @@ var CustomQuestionNodeHandler2 = class extends NodeHandler2 {
1111
1122
  // src/importFromHtml/DivNodeHandler.ts
1112
1123
  var import_node_html_parser3 = require("node-html-parser");
1113
1124
 
1125
+ // src/utils/styleUtils.ts
1126
+ var extractStyleValue = (styleAttr, property, isNumeric = false, unit = "") => {
1127
+ const regex = new RegExp(
1128
+ `${property}:[ ]*([^;]+)${unit ? unit : ""}`,
1129
+ "i"
1130
+ );
1131
+ const match = styleAttr.match(regex);
1132
+ if (!match || !match[1]) return null;
1133
+ const value = match[1].trim();
1134
+ return isNumeric ? parseFloat(value) : value;
1135
+ };
1136
+ var extractFormat = (cellAlign) => {
1137
+ if (!cellAlign) return "";
1138
+ if (cellAlign === "left") return "left";
1139
+ if (cellAlign === "right") return "right";
1140
+ if (cellAlign === "center") return "center";
1141
+ return "";
1142
+ };
1143
+
1114
1144
  // src/importFromHtml/createNestedNodesFromHtml.ts
1115
1145
  var import_node_html_parser2 = require("node-html-parser");
1116
1146
  var wrapInlinesInParagraph = (inlineNodes, format = "") => {
@@ -1124,24 +1154,13 @@ var appendInlinesInParagraphIfNotEmptyBR = (results, inlineNodes, format) => {
1124
1154
  return;
1125
1155
  results.push(wrapInlinesInParagraph(inlineNodes, format));
1126
1156
  };
1127
- var extractFormatFromStyle = (styleAttribute) => {
1128
- if (!styleAttribute) return "";
1129
- const textAlignMatch = styleAttribute.match(
1130
- /text-align:\s*(left|right|center)/i
1131
- );
1132
- if (textAlignMatch) {
1133
- const alignment = textAlignMatch[1].toLowerCase();
1134
- if (alignment === "left") return "left";
1135
- if (alignment === "right") return "right";
1136
- if (alignment === "center") return "center";
1137
- }
1138
- return "";
1139
- };
1140
1157
  var createNestedNodesFromHtml = (node) => {
1141
- const parentStyleAttribute = node instanceof import_node_html_parser2.HTMLElement ? node.getAttribute("style") : null;
1142
- const format = extractFormatFromStyle(parentStyleAttribute);
1158
+ const divParentStyleAttribute = node instanceof import_node_html_parser2.HTMLElement && node.tagName === "DIV" ? node.getAttribute("style") : null;
1159
+ const divParentFormat = extractFormat(
1160
+ extractStyleValue(divParentStyleAttribute ?? "", "text-align")
1161
+ );
1143
1162
  if (node.childNodes.length === 1 && node.childNodes[0] instanceof import_node_html_parser2.HTMLElement && node.childNodes[0].tagName === "BR") {
1144
- return [createEmptyParagraphNode(format)];
1163
+ return [createEmptyParagraphNode(divParentFormat)];
1145
1164
  }
1146
1165
  const results = [];
1147
1166
  let inlineNodes = [];
@@ -1155,7 +1174,7 @@ var createNestedNodesFromHtml = (node) => {
1155
1174
  appendInlinesInParagraphIfNotEmptyBR(
1156
1175
  results,
1157
1176
  inlineNodes,
1158
- format
1177
+ divParentFormat
1159
1178
  );
1160
1179
  inlineNodes = [];
1161
1180
  results.push(processedChild);
@@ -1164,8 +1183,13 @@ var createNestedNodesFromHtml = (node) => {
1164
1183
  }
1165
1184
  }
1166
1185
  }
1167
- appendInlinesInParagraphIfNotEmptyBR(results, inlineNodes, format);
1168
- if (results.length === 0) return [createEmptyParagraphNode(format)];
1186
+ appendInlinesInParagraphIfNotEmptyBR(
1187
+ results,
1188
+ inlineNodes,
1189
+ divParentFormat
1190
+ );
1191
+ if (results.length === 0)
1192
+ return [createEmptyParagraphNode(divParentFormat)];
1169
1193
  else return results;
1170
1194
  };
1171
1195
 
@@ -1492,6 +1516,7 @@ var FillInTheBlankSpaceNodeHandler2 = class extends NodeHandler2 {
1492
1516
  processTextSpace(node, baseNode) {
1493
1517
  return {
1494
1518
  ...baseNode,
1519
+ useRegex: node.getAttribute("data-x-use-regex") === "true",
1495
1520
  caseSensitive: node.getAttribute("data-x-case-sensitive") === "true",
1496
1521
  errorsAllowed: node.getAttribute("data-x-errors-allowed") ? Number(node.getAttribute("data-x-errors-allowed")) : void 0
1497
1522
  };
@@ -1558,9 +1583,7 @@ var FinancialStatementQuestionNodeHandler2 = class extends NodeHandler2 {
1558
1583
  continue;
1559
1584
  jsonNode.distractors.push({
1560
1585
  id: distractorsChild.getAttribute("id") || (0, import_nanoid4.nanoid)(),
1561
- entry: this.getChildNodesTextContent(
1562
- distractorsChild.childNodes
1563
- )
1586
+ entry: createNestedEditorFromHtml(distractorsChild)
1564
1587
  });
1565
1588
  }
1566
1589
  }
@@ -1614,7 +1637,9 @@ var FinancialStatementQuestionNodeHandler2 = class extends NodeHandler2 {
1614
1637
  role: "line-item",
1615
1638
  id: lineNode.getAttribute("id") || "",
1616
1639
  depth: Number(lineNode.getAttribute("data-x-depth") || 0),
1617
- entry: lineNode.querySelector(TAG_X_ENTRY)?.textContent || "",
1640
+ entry: createNestedEditorFromHtml(
1641
+ lineNode.querySelector(TAG_X_ENTRY)
1642
+ ),
1618
1643
  amount: createNestedEditorFromHtml(
1619
1644
  lineNode.querySelector(TAG_X_AMOUNT)
1620
1645
  ),
@@ -2223,18 +2248,6 @@ var SpanNodeHandler = class extends NodeHandler2 {
2223
2248
  // src/importFromHtml/TableCellNodeHandler.ts
2224
2249
  var import_node_html_parser26 = require("node-html-parser");
2225
2250
 
2226
- // src/utils/styleUtils.ts
2227
- var extractStyleValue = (styleAttr, property, isNumeric = false, unit = "") => {
2228
- const regex = new RegExp(
2229
- `${property}:[ ]*([^;]+)${unit ? unit : ""}`,
2230
- "i"
2231
- );
2232
- const match = styleAttr.match(regex);
2233
- if (!match || !match[1]) return null;
2234
- const value = match[1].trim();
2235
- return isNumeric ? parseFloat(value) : value;
2236
- };
2237
-
2238
2251
  // src/importFromHtml/createTableNodes.ts
2239
2252
  function createEmptyTableNode() {
2240
2253
  return {
@@ -2306,6 +2319,9 @@ var TableCellNodeHandler2 = class extends NodeHandler2 {
2306
2319
  if (verticalAlign !== null) {
2307
2320
  cellNode.verticalAlign = verticalAlign;
2308
2321
  }
2322
+ cellNode.format = extractFormat(
2323
+ extractStyleValue(styleAttr, "text-align")
2324
+ );
2309
2325
  cellNode.children = createNestedNodesFromHtml(node);
2310
2326
  return cellNode;
2311
2327
  }
package/dist/index.mjs CHANGED
@@ -237,6 +237,7 @@ var FillInTheBlankSpaceNodeHandler = class extends NodeHandler {
237
237
  `id="${node.id}"`,
238
238
  `data-x-type="${node.spaceType}"`,
239
239
  `data-x-matches="${node.matches}"`,
240
+ `data-x-use-regex="${!!node.useRegex}"`,
240
241
  `data-x-case-sensitive="${!!node.caseSensitive}"`,
241
242
  `data-x-errors-allowed="${node.errorsAllowed ?? 0}"`,
242
243
  `data-x-min-decimals="${node.minDecimals ?? ""}"`,
@@ -320,7 +321,9 @@ var FinancialStatementQuestionNodeHandler = class extends NodeHandler {
320
321
  const amountHintAttr = row.isAmountHint ? ' data-x-is-amount-hint="true"' : "";
321
322
  rowElements.push(
322
323
  `<x-line id="${row.id}" data-x-depth="${row.depth}"${entryHintAttr}${amountHintAttr}>`,
323
- `<x-entry>${row.entry}</x-entry>`,
324
+ `<x-entry>${createHtmlFromNestedEditor(row.entry, {
325
+ parentNode: node
326
+ })}</x-entry>`,
324
327
  `<x-amount>${createHtmlFromNestedEditor(row.amount, {
325
328
  parentNode: node
326
329
  })}</x-amount>`,
@@ -335,7 +338,12 @@ var FinancialStatementQuestionNodeHandler = class extends NodeHandler {
335
338
  return "";
336
339
  }
337
340
  const distractorElements = node.distractors.map(
338
- (distractor) => `<x-distractor id="${distractor.id}">${distractor.entry}</x-distractor>`
341
+ (distractor) => `<x-distractor id="${distractor.id}">${createHtmlFromNestedEditor(
342
+ distractor.entry,
343
+ {
344
+ parentNode: node
345
+ }
346
+ )}</x-distractor>`
339
347
  );
340
348
  return `<x-distractors>${distractorElements.join("")}</x-distractors>`;
341
349
  }
@@ -785,6 +793,9 @@ var TableCellNodeHandler = class extends NodeHandler {
785
793
  } else if (!hasColspan && tableCellNode.width) {
786
794
  styles.push(`width: ${tableCellNode.width}px;`);
787
795
  }
796
+ if (tableCellNode.format) {
797
+ styles.push(`text-align: ${tableCellNode.format};`);
798
+ }
788
799
  if (tableCellNode.backgroundColor) {
789
800
  styles.push(
790
801
  `background-color: ${tableCellNode.backgroundColor};`
@@ -1084,6 +1095,25 @@ var CustomQuestionNodeHandler2 = class extends NodeHandler2 {
1084
1095
  // src/importFromHtml/DivNodeHandler.ts
1085
1096
  import { HTMLElement as HTMLElement3 } from "node-html-parser";
1086
1097
 
1098
+ // src/utils/styleUtils.ts
1099
+ var extractStyleValue = (styleAttr, property, isNumeric = false, unit = "") => {
1100
+ const regex = new RegExp(
1101
+ `${property}:[ ]*([^;]+)${unit ? unit : ""}`,
1102
+ "i"
1103
+ );
1104
+ const match = styleAttr.match(regex);
1105
+ if (!match || !match[1]) return null;
1106
+ const value = match[1].trim();
1107
+ return isNumeric ? parseFloat(value) : value;
1108
+ };
1109
+ var extractFormat = (cellAlign) => {
1110
+ if (!cellAlign) return "";
1111
+ if (cellAlign === "left") return "left";
1112
+ if (cellAlign === "right") return "right";
1113
+ if (cellAlign === "center") return "center";
1114
+ return "";
1115
+ };
1116
+
1087
1117
  // src/importFromHtml/createNestedNodesFromHtml.ts
1088
1118
  import { HTMLElement as HTMLElement2 } from "node-html-parser";
1089
1119
  var wrapInlinesInParagraph = (inlineNodes, format = "") => {
@@ -1097,24 +1127,13 @@ var appendInlinesInParagraphIfNotEmptyBR = (results, inlineNodes, format) => {
1097
1127
  return;
1098
1128
  results.push(wrapInlinesInParagraph(inlineNodes, format));
1099
1129
  };
1100
- var extractFormatFromStyle = (styleAttribute) => {
1101
- if (!styleAttribute) return "";
1102
- const textAlignMatch = styleAttribute.match(
1103
- /text-align:\s*(left|right|center)/i
1104
- );
1105
- if (textAlignMatch) {
1106
- const alignment = textAlignMatch[1].toLowerCase();
1107
- if (alignment === "left") return "left";
1108
- if (alignment === "right") return "right";
1109
- if (alignment === "center") return "center";
1110
- }
1111
- return "";
1112
- };
1113
1130
  var createNestedNodesFromHtml = (node) => {
1114
- const parentStyleAttribute = node instanceof HTMLElement2 ? node.getAttribute("style") : null;
1115
- const format = extractFormatFromStyle(parentStyleAttribute);
1131
+ const divParentStyleAttribute = node instanceof HTMLElement2 && node.tagName === "DIV" ? node.getAttribute("style") : null;
1132
+ const divParentFormat = extractFormat(
1133
+ extractStyleValue(divParentStyleAttribute ?? "", "text-align")
1134
+ );
1116
1135
  if (node.childNodes.length === 1 && node.childNodes[0] instanceof HTMLElement2 && node.childNodes[0].tagName === "BR") {
1117
- return [createEmptyParagraphNode(format)];
1136
+ return [createEmptyParagraphNode(divParentFormat)];
1118
1137
  }
1119
1138
  const results = [];
1120
1139
  let inlineNodes = [];
@@ -1128,7 +1147,7 @@ var createNestedNodesFromHtml = (node) => {
1128
1147
  appendInlinesInParagraphIfNotEmptyBR(
1129
1148
  results,
1130
1149
  inlineNodes,
1131
- format
1150
+ divParentFormat
1132
1151
  );
1133
1152
  inlineNodes = [];
1134
1153
  results.push(processedChild);
@@ -1137,8 +1156,13 @@ var createNestedNodesFromHtml = (node) => {
1137
1156
  }
1138
1157
  }
1139
1158
  }
1140
- appendInlinesInParagraphIfNotEmptyBR(results, inlineNodes, format);
1141
- if (results.length === 0) return [createEmptyParagraphNode(format)];
1159
+ appendInlinesInParagraphIfNotEmptyBR(
1160
+ results,
1161
+ inlineNodes,
1162
+ divParentFormat
1163
+ );
1164
+ if (results.length === 0)
1165
+ return [createEmptyParagraphNode(divParentFormat)];
1142
1166
  else return results;
1143
1167
  };
1144
1168
 
@@ -1465,6 +1489,7 @@ var FillInTheBlankSpaceNodeHandler2 = class extends NodeHandler2 {
1465
1489
  processTextSpace(node, baseNode) {
1466
1490
  return {
1467
1491
  ...baseNode,
1492
+ useRegex: node.getAttribute("data-x-use-regex") === "true",
1468
1493
  caseSensitive: node.getAttribute("data-x-case-sensitive") === "true",
1469
1494
  errorsAllowed: node.getAttribute("data-x-errors-allowed") ? Number(node.getAttribute("data-x-errors-allowed")) : void 0
1470
1495
  };
@@ -1531,9 +1556,7 @@ var FinancialStatementQuestionNodeHandler2 = class extends NodeHandler2 {
1531
1556
  continue;
1532
1557
  jsonNode.distractors.push({
1533
1558
  id: distractorsChild.getAttribute("id") || nanoid4(),
1534
- entry: this.getChildNodesTextContent(
1535
- distractorsChild.childNodes
1536
- )
1559
+ entry: createNestedEditorFromHtml(distractorsChild)
1537
1560
  });
1538
1561
  }
1539
1562
  }
@@ -1587,7 +1610,9 @@ var FinancialStatementQuestionNodeHandler2 = class extends NodeHandler2 {
1587
1610
  role: "line-item",
1588
1611
  id: lineNode.getAttribute("id") || "",
1589
1612
  depth: Number(lineNode.getAttribute("data-x-depth") || 0),
1590
- entry: lineNode.querySelector(TAG_X_ENTRY)?.textContent || "",
1613
+ entry: createNestedEditorFromHtml(
1614
+ lineNode.querySelector(TAG_X_ENTRY)
1615
+ ),
1591
1616
  amount: createNestedEditorFromHtml(
1592
1617
  lineNode.querySelector(TAG_X_AMOUNT)
1593
1618
  ),
@@ -2196,18 +2221,6 @@ var SpanNodeHandler = class extends NodeHandler2 {
2196
2221
  // src/importFromHtml/TableCellNodeHandler.ts
2197
2222
  import { HTMLElement as HTMLElement26 } from "node-html-parser";
2198
2223
 
2199
- // src/utils/styleUtils.ts
2200
- var extractStyleValue = (styleAttr, property, isNumeric = false, unit = "") => {
2201
- const regex = new RegExp(
2202
- `${property}:[ ]*([^;]+)${unit ? unit : ""}`,
2203
- "i"
2204
- );
2205
- const match = styleAttr.match(regex);
2206
- if (!match || !match[1]) return null;
2207
- const value = match[1].trim();
2208
- return isNumeric ? parseFloat(value) : value;
2209
- };
2210
-
2211
2224
  // src/importFromHtml/createTableNodes.ts
2212
2225
  function createEmptyTableNode() {
2213
2226
  return {
@@ -2279,6 +2292,9 @@ var TableCellNodeHandler2 = class extends NodeHandler2 {
2279
2292
  if (verticalAlign !== null) {
2280
2293
  cellNode.verticalAlign = verticalAlign;
2281
2294
  }
2295
+ cellNode.format = extractFormat(
2296
+ extractStyleValue(styleAttr, "text-align")
2297
+ );
2282
2298
  cellNode.children = createNestedNodesFromHtml(node);
2283
2299
  return cellNode;
2284
2300
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@examind/block-sdk",
3
- "version": "0.2.5",
3
+ "version": "0.3.0",
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.5"
24
+ "@examind/block-types": "^0.3.0"
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.5"
39
+ "@examind/block-types": "0.3.0"
40
40
  },
41
41
  "dependencies": {
42
42
  "lodash-es": "4.17.21"