@mathscan/math-exercise-engine 1.1.13 → 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 +129 -0
- package/dist/index.js +64 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -28
- 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
|
});
|
|
@@ -2059,22 +2064,28 @@ function createNumberLineBlock(min, max, positions, step, minorTicks, style, lab
|
|
|
2059
2064
|
const TableCellSchema = z.object({
|
|
2060
2065
|
type: z.literal(AST_TYPES.TABLE_CELL),
|
|
2061
2066
|
colspan: z.number().int().positive().optional(),
|
|
2067
|
+
rowspan: z.number().int().positive().optional(),
|
|
2068
|
+
backgroundColor: z.string().optional(),
|
|
2062
2069
|
inlines: z.array(InlineNodeSchema)
|
|
2063
2070
|
});
|
|
2064
|
-
function createTableCell(inlines, colspan) {
|
|
2071
|
+
function createTableCell(inlines, colspan, rowspan, backgroundColor) {
|
|
2065
2072
|
return TableCellSchema.parse({
|
|
2066
2073
|
type: AST_TYPES.TABLE_CELL,
|
|
2067
2074
|
colspan,
|
|
2075
|
+
rowspan,
|
|
2076
|
+
backgroundColor,
|
|
2068
2077
|
inlines
|
|
2069
2078
|
});
|
|
2070
2079
|
}
|
|
2071
2080
|
const TableRowSchema = z.object({
|
|
2072
2081
|
type: z.literal(AST_TYPES.TABLE_ROW),
|
|
2082
|
+
backgroundColor: z.string().optional(),
|
|
2073
2083
|
cells: z.array(TableCellSchema).min(1)
|
|
2074
2084
|
});
|
|
2075
|
-
function createTableRow(cells) {
|
|
2085
|
+
function createTableRow(cells, backgroundColor) {
|
|
2076
2086
|
return TableRowSchema.parse({
|
|
2077
2087
|
type: AST_TYPES.TABLE_ROW,
|
|
2088
|
+
backgroundColor,
|
|
2078
2089
|
cells
|
|
2079
2090
|
});
|
|
2080
2091
|
}
|
|
@@ -2674,14 +2685,18 @@ class NaturalDSLVisitor extends BaseCstVisitor {
|
|
|
2674
2685
|
return createTableBlock(cols, rows);
|
|
2675
2686
|
}
|
|
2676
2687
|
row(ctx) {
|
|
2688
|
+
const params = ctx.parameterList ? this.visit(ctx.parameterList) : {};
|
|
2689
|
+
const backgroundColor = params.bgcolor;
|
|
2677
2690
|
const cells = ctx.cell.map((c) => this.visit(c));
|
|
2678
|
-
return createTableRow(cells);
|
|
2691
|
+
return createTableRow(cells, backgroundColor);
|
|
2679
2692
|
}
|
|
2680
2693
|
cell(ctx) {
|
|
2681
2694
|
const params = ctx.parameterList ? this.visit(ctx.parameterList) : {};
|
|
2682
2695
|
const colspan = params.colspan;
|
|
2696
|
+
const rowspan = params.rowspan;
|
|
2697
|
+
const backgroundColor = params.bgcolor;
|
|
2683
2698
|
const inlines = ctx.inlineElement ? ctx.inlineElement.map((elem) => this.visit(elem)) : [];
|
|
2684
|
-
return createTableCell(inlines, colspan);
|
|
2699
|
+
return createTableCell(inlines, colspan, rowspan, backgroundColor);
|
|
2685
2700
|
}
|
|
2686
2701
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
2687
2702
|
// Number Line Block
|
|
@@ -3382,11 +3397,14 @@ const TableCellItemSchema = z.object({
|
|
|
3382
3397
|
id: z.string(),
|
|
3383
3398
|
type: z.literal(JSON_TYPES.TABLE_CELL),
|
|
3384
3399
|
colspan: z.number().int().positive().optional(),
|
|
3400
|
+
rowspan: z.number().int().positive().optional(),
|
|
3401
|
+
backgroundColor: z.string().optional(),
|
|
3385
3402
|
items: z.array(LayoutItemSchema)
|
|
3386
3403
|
});
|
|
3387
3404
|
const TableRowItemSchema = z.object({
|
|
3388
3405
|
id: z.string(),
|
|
3389
3406
|
type: z.literal(JSON_TYPES.TABLE_ROW),
|
|
3407
|
+
backgroundColor: z.string().optional(),
|
|
3390
3408
|
cells: z.array(TableCellItemSchema)
|
|
3391
3409
|
});
|
|
3392
3410
|
const TableItemSchema = z.object({
|
|
@@ -9668,13 +9686,23 @@ function transformTable(table, idGenerator, inlineDragIds) {
|
|
|
9668
9686
|
if (cell.colspan !== void 0) {
|
|
9669
9687
|
cellItem.colspan = cell.colspan;
|
|
9670
9688
|
}
|
|
9689
|
+
if (cell.rowspan !== void 0) {
|
|
9690
|
+
cellItem.rowspan = cell.rowspan;
|
|
9691
|
+
}
|
|
9692
|
+
if (cell.backgroundColor !== void 0) {
|
|
9693
|
+
cellItem.backgroundColor = cell.backgroundColor;
|
|
9694
|
+
}
|
|
9671
9695
|
return cellItem;
|
|
9672
9696
|
});
|
|
9673
|
-
|
|
9697
|
+
const rowItem = {
|
|
9674
9698
|
id: idGenerator.generate(JSON_TYPES.TABLE_ROW),
|
|
9675
9699
|
type: JSON_TYPES.TABLE_ROW,
|
|
9676
9700
|
cells
|
|
9677
9701
|
};
|
|
9702
|
+
if (row.backgroundColor !== void 0) {
|
|
9703
|
+
rowItem.backgroundColor = row.backgroundColor;
|
|
9704
|
+
}
|
|
9705
|
+
return rowItem;
|
|
9678
9706
|
});
|
|
9679
9707
|
return {
|
|
9680
9708
|
id: idGenerator.generate(JSON_TYPES.TABLE),
|
|
@@ -18273,29 +18301,37 @@ const LayoutRenderer = ({
|
|
|
18273
18301
|
},
|
|
18274
18302
|
subItem.id
|
|
18275
18303
|
)) });
|
|
18276
|
-
case JSON_TYPES.TABLE:
|
|
18277
|
-
|
|
18278
|
-
|
|
18279
|
-
|
|
18280
|
-
|
|
18281
|
-
|
|
18282
|
-
|
|
18283
|
-
|
|
18284
|
-
{
|
|
18285
|
-
|
|
18286
|
-
|
|
18287
|
-
|
|
18288
|
-
|
|
18289
|
-
|
|
18290
|
-
|
|
18291
|
-
|
|
18292
|
-
|
|
18293
|
-
|
|
18294
|
-
|
|
18295
|
-
|
|
18296
|
-
|
|
18297
|
-
|
|
18298
|
-
|
|
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
|
+
}
|
|
18299
18335
|
case JSON_TYPES.NUMBER_LINE:
|
|
18300
18336
|
return /* @__PURE__ */ jsx(
|
|
18301
18337
|
NumberLineRenderer,
|