@examind/block-sdk 0.1.8 → 0.1.9

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
@@ -332,11 +332,13 @@ var JournalEntryQuestionNodeHandler = class extends NodeHandler {
332
332
  }
333
333
  processDistractors(node) {
334
334
  const distractors = node.lineItems.filter((item) => !item.correct).map((item) => {
335
- const accountContent = createHtmlFromNestedEditor(
335
+ const distractorAccounts = createHtmlFromNestedEditor(
336
336
  item.account,
337
337
  { parentNode: node }
338
338
  );
339
- return `<x-distractor id="${item.id}">${accountContent}</x-distractor>`;
339
+ return distractorAccounts.split("<br>").filter((a) => a.trim()).map(
340
+ (a, i) => `<x-distractor id="${item.id}|${i}">${a}</x-distractor>`
341
+ ).join("");
340
342
  }).join("");
341
343
  return distractors;
342
344
  }
@@ -1338,6 +1340,11 @@ var ImageNodeHandler2 = class extends NodeHandler2 {
1338
1340
  // src/importFromHtml/JournalEntryQuestionNodeHandler.ts
1339
1341
  var import_nanoid5 = require("nanoid");
1340
1342
  var import_node_html_parser10 = require("node-html-parser");
1343
+ var extractDistractorId = (id) => {
1344
+ if (!id) return null;
1345
+ const parts = id.split("|");
1346
+ return parts.length === 2 ? parts[0] : null;
1347
+ };
1341
1348
  var JournalEntryQuestionNodeHandler2 = class extends NodeHandler2 {
1342
1349
  processNode(node) {
1343
1350
  if (!(node instanceof import_node_html_parser10.HTMLElement) || node.tagName !== "x-journal-entry".toUpperCase())
@@ -1361,29 +1368,40 @@ var JournalEntryQuestionNodeHandler2 = class extends NodeHandler2 {
1361
1368
  const debitElement = lineItem.querySelector("x-debit");
1362
1369
  const creditElement = lineItem.querySelector("x-credit");
1363
1370
  if (!accountElement) return;
1364
- const item = {
1371
+ const item2 = {
1365
1372
  id: lineItem.getAttribute("id") ?? (0, import_nanoid5.nanoid)(),
1366
1373
  correct: true,
1367
1374
  account: createNestedEditorFromHtml(accountElement)
1368
1375
  };
1369
1376
  if (debitElement) {
1370
- item.debit = createNestedEditorFromHtml(debitElement);
1377
+ item2.debit = createNestedEditorFromHtml(debitElement);
1371
1378
  }
1372
1379
  if (creditElement) {
1373
- item.credit = createNestedEditorFromHtml(creditElement);
1380
+ item2.credit = createNestedEditorFromHtml(creditElement);
1374
1381
  }
1375
- jsonNode.lineItems.push(item);
1382
+ jsonNode.lineItems.push(item2);
1376
1383
  });
1384
+ const distractorEditor = createNestedEditorFromHtml(null);
1377
1385
  const distractors = node.querySelectorAll("x-distractor");
1386
+ const emptyDistractorEditorChildren = distractorEditor.editorState.root.children;
1387
+ distractorEditor.editorState.root.children = [];
1388
+ let distractorId = null;
1378
1389
  distractors.forEach((distractor) => {
1379
1390
  if (!(distractor instanceof import_node_html_parser10.HTMLElement)) return;
1380
- const item = {
1381
- id: distractor.getAttribute("id") ?? (0, import_nanoid5.nanoid)(),
1382
- correct: false,
1383
- account: createNestedEditorFromHtml(distractor)
1384
- };
1385
- jsonNode.lineItems.push(item);
1391
+ distractorId = distractorId ?? extractDistractorId(distractor.getAttribute("id"));
1392
+ distractorEditor.editorState.root.children.push(
1393
+ ...createNestedNodesFromHtml(distractor)
1394
+ );
1386
1395
  });
1396
+ if (!distractorEditor.editorState.root.children.length) {
1397
+ distractorEditor.editorState.root.children = emptyDistractorEditorChildren;
1398
+ }
1399
+ const item = {
1400
+ id: distractorId ?? (0, import_nanoid5.nanoid)(),
1401
+ correct: false,
1402
+ account: distractorEditor
1403
+ };
1404
+ jsonNode.lineItems.push(item);
1387
1405
  return jsonNode;
1388
1406
  }
1389
1407
  };
package/dist/index.mjs CHANGED
@@ -305,11 +305,13 @@ var JournalEntryQuestionNodeHandler = class extends NodeHandler {
305
305
  }
306
306
  processDistractors(node) {
307
307
  const distractors = node.lineItems.filter((item) => !item.correct).map((item) => {
308
- const accountContent = createHtmlFromNestedEditor(
308
+ const distractorAccounts = createHtmlFromNestedEditor(
309
309
  item.account,
310
310
  { parentNode: node }
311
311
  );
312
- return `<x-distractor id="${item.id}">${accountContent}</x-distractor>`;
312
+ return distractorAccounts.split("<br>").filter((a) => a.trim()).map(
313
+ (a, i) => `<x-distractor id="${item.id}|${i}">${a}</x-distractor>`
314
+ ).join("");
313
315
  }).join("");
314
316
  return distractors;
315
317
  }
@@ -1311,6 +1313,11 @@ var ImageNodeHandler2 = class extends NodeHandler2 {
1311
1313
  // src/importFromHtml/JournalEntryQuestionNodeHandler.ts
1312
1314
  import { nanoid as nanoid5 } from "nanoid";
1313
1315
  import { HTMLElement as HTMLElement10 } from "node-html-parser";
1316
+ var extractDistractorId = (id) => {
1317
+ if (!id) return null;
1318
+ const parts = id.split("|");
1319
+ return parts.length === 2 ? parts[0] : null;
1320
+ };
1314
1321
  var JournalEntryQuestionNodeHandler2 = class extends NodeHandler2 {
1315
1322
  processNode(node) {
1316
1323
  if (!(node instanceof HTMLElement10) || node.tagName !== "x-journal-entry".toUpperCase())
@@ -1334,29 +1341,40 @@ var JournalEntryQuestionNodeHandler2 = class extends NodeHandler2 {
1334
1341
  const debitElement = lineItem.querySelector("x-debit");
1335
1342
  const creditElement = lineItem.querySelector("x-credit");
1336
1343
  if (!accountElement) return;
1337
- const item = {
1344
+ const item2 = {
1338
1345
  id: lineItem.getAttribute("id") ?? nanoid5(),
1339
1346
  correct: true,
1340
1347
  account: createNestedEditorFromHtml(accountElement)
1341
1348
  };
1342
1349
  if (debitElement) {
1343
- item.debit = createNestedEditorFromHtml(debitElement);
1350
+ item2.debit = createNestedEditorFromHtml(debitElement);
1344
1351
  }
1345
1352
  if (creditElement) {
1346
- item.credit = createNestedEditorFromHtml(creditElement);
1353
+ item2.credit = createNestedEditorFromHtml(creditElement);
1347
1354
  }
1348
- jsonNode.lineItems.push(item);
1355
+ jsonNode.lineItems.push(item2);
1349
1356
  });
1357
+ const distractorEditor = createNestedEditorFromHtml(null);
1350
1358
  const distractors = node.querySelectorAll("x-distractor");
1359
+ const emptyDistractorEditorChildren = distractorEditor.editorState.root.children;
1360
+ distractorEditor.editorState.root.children = [];
1361
+ let distractorId = null;
1351
1362
  distractors.forEach((distractor) => {
1352
1363
  if (!(distractor instanceof HTMLElement10)) return;
1353
- const item = {
1354
- id: distractor.getAttribute("id") ?? nanoid5(),
1355
- correct: false,
1356
- account: createNestedEditorFromHtml(distractor)
1357
- };
1358
- jsonNode.lineItems.push(item);
1364
+ distractorId = distractorId ?? extractDistractorId(distractor.getAttribute("id"));
1365
+ distractorEditor.editorState.root.children.push(
1366
+ ...createNestedNodesFromHtml(distractor)
1367
+ );
1359
1368
  });
1369
+ if (!distractorEditor.editorState.root.children.length) {
1370
+ distractorEditor.editorState.root.children = emptyDistractorEditorChildren;
1371
+ }
1372
+ const item = {
1373
+ id: distractorId ?? nanoid5(),
1374
+ correct: false,
1375
+ account: distractorEditor
1376
+ };
1377
+ jsonNode.lineItems.push(item);
1360
1378
  return jsonNode;
1361
1379
  }
1362
1380
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@examind/block-sdk",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "@comment version": [
5
5
  "Don't specify package version here. It will be injected by publish workflow."
6
6
  ],