55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import { Action, ActionKind } from "./action.ts";
|
|
import * as rasterizer from "./rasterizer.ts";
|
|
|
|
export class Board {
|
|
private actions: Action[] = [];
|
|
|
|
public constructor(
|
|
title: string,
|
|
) {
|
|
this.pushAction({ tag: "init", title });
|
|
}
|
|
|
|
public addColumn(idx: number, title: string) {
|
|
this.pushAction({ tag: "addColumn", title, idx });
|
|
}
|
|
|
|
public editColumn(idx: number, title: string) {
|
|
this.pushAction({ tag: "editColumn", title, idx });
|
|
}
|
|
|
|
public deleteColumn(idx: number) {
|
|
this.pushAction({ tag: "deleteColumn", idx });
|
|
}
|
|
|
|
public moveColumn(idx: number, delta: number) {
|
|
this.pushAction({ tag: "moveColumn", idx, delta });
|
|
}
|
|
|
|
public addTask(path: number[], idx: number, content: string) {
|
|
this.pushAction({ tag: "addTask", path, idx, content });
|
|
}
|
|
|
|
public editTask(path: number[], content: string) {
|
|
this.pushAction({ tag: "editTask", path, content });
|
|
}
|
|
|
|
public deleteTask(path: number[]) {
|
|
this.pushAction({ tag: "deleteTask", path });
|
|
}
|
|
|
|
public moveTask(srcPath: number[], destPath: number[], idx: number) {
|
|
this.pushAction({ tag: "moveTask", srcPath, destPath, idx });
|
|
}
|
|
|
|
private pushAction(kind: ActionKind) {
|
|
const chsm = this.actions.at(-1)?.chsm ??
|
|
0 + JSON.stringify(kind).length;
|
|
this.actions.push({ kind, chsm });
|
|
}
|
|
|
|
public rasterize(): rasterizer.Board {
|
|
return new rasterizer.Rasterizer(this.actions).rasterize();
|
|
}
|
|
}
|