+
+
+
{
-
-
-
+
{
/>
+
+ saveEditorPage()"/>
+
+
= {}
+ static deserialize(vals: [string, [StatementID, string, number, number][]]) {
+ const inst = new this(vals[0])
+
+ for ( const row of vals[1] ) {
+ inst.statements[row[0]] = MathStatement.deserialize(row)
+ }
+
+ return inst
+ }
+
constructor(
/** Unique page ID. */
public readonly id: string,
) {}
+ serialize(): [string, [StatementID, string, number, number][]] {
+ return [
+ this.id,
+ Object.values(this.statements).map(x => x.serialize()),
+ ]
+ }
+
/** Get all defined statements. */
getStatements(): MathStatement[] {
return Object.values(this.statements)
diff --git a/src/support/parse.ts b/src/support/parse.ts
index 90a9e0b..bedd078 100644
--- a/src/support/parse.ts
+++ b/src/support/parse.ts
@@ -264,6 +264,10 @@ export class MathStatement {
return new MathStatement(uuidv4() as StatementID, raw)
}
+ static deserialize(vals: [StatementID, string, number, number]) {
+ return new this(...vals)
+ }
+
constructor(
/** Unique ID of this statement. */
public readonly id: StatementID,
@@ -278,6 +282,15 @@ export class MathStatement {
public y: number = 0,
) {}
+ serialize(): [StatementID, string, number, number] {
+ return [
+ this.id,
+ this.raw,
+ this.x,
+ this.y,
+ ]
+ }
+
/** Parse the raw statement to an AST. */
parse(): math.MathNode {
return math.parse(this.raw)
diff --git a/src/support/types.ts b/src/support/types.ts
index 248ef7f..e59aab8 100644
--- a/src/support/types.ts
+++ b/src/support/types.ts
@@ -94,24 +94,52 @@ export interface EvaluationResult {
export class RichTextBox {
+ static deserialize(vals: [string, number, number]) {
+ return new this(...vals)
+ }
+
constructor(
public text: string = '',
public x: number = 0,
public y: number = 0,
) {}
+
+ serialize(): [string, number, number] {
+ return [
+ this.text,
+ this.x,
+ this.y,
+ ]
+ }
}
export class ImageContainer {
+ static deserialize(vals: [string, number, number]) {
+ return new this(...vals)
+ }
+
constructor(
public url: string = '',
public x: number = 0,
public y: number = 0,
) {}
+
+ serialize(): [string, number, number] {
+ return [
+ this.url,
+ this.x,
+ this.y,
+ ]
+ }
}
export class ChartBox {
+ static deserialize(vals: [string, number, number, number, number, number]) {
+ return new this(...vals)
+ }
+
// eslint-disable-next-line max-params
constructor(
public fnName: string,
@@ -121,6 +149,17 @@ export class ChartBox {
public x: number = 0,
public y: number = 0,
) {}
+
+ serialize(): [string, number, number, number, number, number] {
+ return [
+ this.fnName,
+ this.minX,
+ this.maxX,
+ this.stepX,
+ this.x,
+ this.y,
+ ]
+ }
}