@mathscan/math-exercise-engine 1.1.14 → 1.1.15
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.d.ts +80 -0
- package/dist/index.js +57 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -29
- package/dist/index.mjs.map +1 -1
- package/dist/style.css +202 -57
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -748,6 +748,11 @@ class MathExerciseParser extends CstParser {
|
|
|
748
748
|
this.OR([{ ALT: () => this.CONSUME(Space) }, { ALT: () => this.CONSUME(Newline) }]);
|
|
749
749
|
});
|
|
750
750
|
this.CONSUME(ROW);
|
|
751
|
+
this.OPTION(() => {
|
|
752
|
+
this.CONSUME(LBracket);
|
|
753
|
+
this.SUBRULE(this.parameterList);
|
|
754
|
+
this.CONSUME(RBracket);
|
|
755
|
+
});
|
|
751
756
|
this.MANY2(() => {
|
|
752
757
|
this.OR2([{ ALT: () => this.CONSUME2(Space) }, { ALT: () => this.CONSUME2(Newline) }]);
|
|
753
758
|
});
|
|
@@ -2060,23 +2065,27 @@ const TableCellSchema = z.object({
|
|
|
2060
2065
|
type: z.literal(AST_TYPES.TABLE_CELL),
|
|
2061
2066
|
colspan: z.number().int().positive().optional(),
|
|
2062
2067
|
rowspan: z.number().int().positive().optional(),
|
|
2068
|
+
backgroundColor: z.string().optional(),
|
|
2063
2069
|
inlines: z.array(InlineNodeSchema)
|
|
2064
2070
|
});
|
|
2065
|
-
function createTableCell(inlines, colspan, rowspan) {
|
|
2071
|
+
function createTableCell(inlines, colspan, rowspan, backgroundColor) {
|
|
2066
2072
|
return TableCellSchema.parse({
|
|
2067
2073
|
type: AST_TYPES.TABLE_CELL,
|
|
2068
2074
|
colspan,
|
|
2069
2075
|
rowspan,
|
|
2076
|
+
backgroundColor,
|
|
2070
2077
|
inlines
|
|
2071
2078
|
});
|
|
2072
2079
|
}
|
|
2073
2080
|
const TableRowSchema = z.object({
|
|
2074
2081
|
type: z.literal(AST_TYPES.TABLE_ROW),
|
|
2082
|
+
backgroundColor: z.string().optional(),
|
|
2075
2083
|
cells: z.array(TableCellSchema).min(1)
|
|
2076
2084
|
});
|
|
2077
|
-
function createTableRow(cells) {
|
|
2085
|
+
function createTableRow(cells, backgroundColor) {
|
|
2078
2086
|
return TableRowSchema.parse({
|
|
2079
2087
|
type: AST_TYPES.TABLE_ROW,
|
|
2088
|
+
backgroundColor,
|
|
2080
2089
|
cells
|
|
2081
2090
|
});
|
|
2082
2091
|
}
|
|
@@ -2676,15 +2685,18 @@ class NaturalDSLVisitor extends BaseCstVisitor {
|
|
|
2676
2685
|
return createTableBlock(cols, rows);
|
|
2677
2686
|
}
|
|
2678
2687
|
row(ctx) {
|
|
2688
|
+
const params = ctx.parameterList ? this.visit(ctx.parameterList) : {};
|
|
2689
|
+
const backgroundColor = params.bgcolor;
|
|
2679
2690
|
const cells = ctx.cell.map((c) => this.visit(c));
|
|
2680
|
-
return createTableRow(cells);
|
|
2691
|
+
return createTableRow(cells, backgroundColor);
|
|
2681
2692
|
}
|
|
2682
2693
|
cell(ctx) {
|
|
2683
2694
|
const params = ctx.parameterList ? this.visit(ctx.parameterList) : {};
|
|
2684
2695
|
const colspan = params.colspan;
|
|
2685
2696
|
const rowspan = params.rowspan;
|
|
2697
|
+
const backgroundColor = params.bgcolor;
|
|
2686
2698
|
const inlines = ctx.inlineElement ? ctx.inlineElement.map((elem) => this.visit(elem)) : [];
|
|
2687
|
-
return createTableCell(inlines, colspan, rowspan);
|
|
2699
|
+
return createTableCell(inlines, colspan, rowspan, backgroundColor);
|
|
2688
2700
|
}
|
|
2689
2701
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
2690
2702
|
// Number Line Block
|
|
@@ -3386,11 +3398,13 @@ const TableCellItemSchema = z.object({
|
|
|
3386
3398
|
type: z.literal(JSON_TYPES.TABLE_CELL),
|
|
3387
3399
|
colspan: z.number().int().positive().optional(),
|
|
3388
3400
|
rowspan: z.number().int().positive().optional(),
|
|
3401
|
+
backgroundColor: z.string().optional(),
|
|
3389
3402
|
items: z.array(LayoutItemSchema)
|
|
3390
3403
|
});
|
|
3391
3404
|
const TableRowItemSchema = z.object({
|
|
3392
3405
|
id: z.string(),
|
|
3393
3406
|
type: z.literal(JSON_TYPES.TABLE_ROW),
|
|
3407
|
+
backgroundColor: z.string().optional(),
|
|
3394
3408
|
cells: z.array(TableCellItemSchema)
|
|
3395
3409
|
});
|
|
3396
3410
|
const TableItemSchema = z.object({
|
|
@@ -9675,13 +9689,20 @@ function transformTable(table, idGenerator, inlineDragIds) {
|
|
|
9675
9689
|
if (cell.rowspan !== void 0) {
|
|
9676
9690
|
cellItem.rowspan = cell.rowspan;
|
|
9677
9691
|
}
|
|
9692
|
+
if (cell.backgroundColor !== void 0) {
|
|
9693
|
+
cellItem.backgroundColor = cell.backgroundColor;
|
|
9694
|
+
}
|
|
9678
9695
|
return cellItem;
|
|
9679
9696
|
});
|
|
9680
|
-
|
|
9697
|
+
const rowItem = {
|
|
9681
9698
|
id: idGenerator.generate(JSON_TYPES.TABLE_ROW),
|
|
9682
9699
|
type: JSON_TYPES.TABLE_ROW,
|
|
9683
9700
|
cells
|
|
9684
9701
|
};
|
|
9702
|
+
if (row.backgroundColor !== void 0) {
|
|
9703
|
+
rowItem.backgroundColor = row.backgroundColor;
|
|
9704
|
+
}
|
|
9705
|
+
return rowItem;
|
|
9685
9706
|
});
|
|
9686
9707
|
return {
|
|
9687
9708
|
id: idGenerator.generate(JSON_TYPES.TABLE),
|
|
@@ -18280,30 +18301,37 @@ const LayoutRenderer = ({
|
|
|
18280
18301
|
},
|
|
18281
18302
|
subItem.id
|
|
18282
18303
|
)) });
|
|
18283
|
-
case JSON_TYPES.TABLE:
|
|
18284
|
-
|
|
18285
|
-
|
|
18286
|
-
|
|
18287
|
-
|
|
18288
|
-
|
|
18289
|
-
|
|
18290
|
-
|
|
18291
|
-
|
|
18292
|
-
|
|
18293
|
-
|
|
18294
|
-
|
|
18295
|
-
|
|
18296
|
-
|
|
18297
|
-
|
|
18298
|
-
|
|
18299
|
-
|
|
18300
|
-
|
|
18301
|
-
|
|
18302
|
-
|
|
18303
|
-
|
|
18304
|
-
|
|
18305
|
-
|
|
18306
|
-
|
|
18304
|
+
case JSON_TYPES.TABLE: {
|
|
18305
|
+
const totalRows = item.rows.length;
|
|
18306
|
+
return /* @__PURE__ */ jsx("div", { className: "exercise-table-container", children: /* @__PURE__ */ jsx("table", { className: "exercise-table", children: /* @__PURE__ */ jsx("tbody", { children: item.rows.map((row, rowIndex) => /* @__PURE__ */ jsx("tr", { className: "exercise-table-row", style: { backgroundColor: row.backgroundColor }, children: row.cells.map((cell) => {
|
|
18307
|
+
const rowspan = cell.rowspan || 1;
|
|
18308
|
+
const isLastRow = rowIndex + rowspan - 1 >= totalRows - 1;
|
|
18309
|
+
return /* @__PURE__ */ jsx(
|
|
18310
|
+
"td",
|
|
18311
|
+
{
|
|
18312
|
+
className: `exercise-table-cell${isLastRow ? " exercise-table-cell--last-row" : ""}`,
|
|
18313
|
+
colSpan: cell.colspan || 1,
|
|
18314
|
+
rowSpan: rowspan,
|
|
18315
|
+
style: { backgroundColor: cell.backgroundColor },
|
|
18316
|
+
children: cell.items.map((subItem) => /* @__PURE__ */ jsx(
|
|
18317
|
+
LayoutRenderer,
|
|
18318
|
+
{
|
|
18319
|
+
item: subItem,
|
|
18320
|
+
widgets,
|
|
18321
|
+
values,
|
|
18322
|
+
droppedInputs,
|
|
18323
|
+
validationDetails,
|
|
18324
|
+
onChange,
|
|
18325
|
+
onInputFocus,
|
|
18326
|
+
resetKey
|
|
18327
|
+
},
|
|
18328
|
+
subItem.id
|
|
18329
|
+
))
|
|
18330
|
+
},
|
|
18331
|
+
cell.id
|
|
18332
|
+
);
|
|
18333
|
+
}) }, row.id)) }) }) });
|
|
18334
|
+
}
|
|
18307
18335
|
case JSON_TYPES.NUMBER_LINE:
|
|
18308
18336
|
return /* @__PURE__ */ jsx(
|
|
18309
18337
|
NumberLineRenderer,
|