From 8556a260524ce992c222fb9b9b636fb6b2e943f2 Mon Sep 17 00:00:00 2001 From: Lewis Hemens Date: Wed, 21 Feb 2024 21:29:12 +0000 Subject: [PATCH] Fix sharing links --- client/store/canvas.ts | 58 +++++++++++++++++++++--------------------- client/text_utils.ts | 10 +++++--- tsconfig.json | 2 +- 3 files changed, 36 insertions(+), 34 deletions(-) diff --git a/client/store/canvas.ts b/client/store/canvas.ts index c531834..850dd86 100644 --- a/client/store/canvas.ts +++ b/client/store/canvas.ts @@ -15,17 +15,41 @@ import { RenderLayer } from "#asciiflow/client/render_layer"; * and provides methods to modify the current state. */ export class CanvasStore { - public readonly drawingId: DrawingId = DrawingId.local(""); - constructor(drawingId: DrawingId) { - this.drawingId = drawingId; + public readonly persistentCommitted: Persistent; + public readonly undoLayers: Persistent; + public readonly redoLayers: Persistent; + private _zoom: Persistent; + private _offset: Persistent; + + constructor(public readonly drawingId: DrawingId) { + this.persistentCommitted = Persistent.custom( + this.persistentKey("committed-layer"), + this.drawingId.shareSpec + ? new DrawingStringifier().deserialize(this.drawingId.shareSpec).layer + : new Layer(), + Layer + ); + this.undoLayers = Persistent.custom( + this.persistentKey("undo-layers"), + [], + new ArrayStringifier(Layer) + ); + this.redoLayers = Persistent.custom( + this.persistentKey("redo-layers"), + [], + new ArrayStringifier(Layer) + ); + this._zoom = Persistent.json(this.persistentKey("zoom"), 1); + this._offset = Persistent.json(this.persistentKey("offset"), { + x: (constants.MAX_GRID_WIDTH * constants.CHAR_PIXELS_H) / 2, + y: (constants.MAX_GRID_HEIGHT * constants.CHAR_PIXELS_V) / 2, + }) } public persistentKey(...values: string[]) { return Persistent.key("drawing", this.drawingId.persistentKey, ...values); } - private _zoom = Persistent.json(this.persistentKey("zoom"), 1); - public get zoom() { return this._zoom.get(); } @@ -34,11 +58,6 @@ export class CanvasStore { this._zoom.set(value); } - private _offset = Persistent.json(this.persistentKey("offset"), { - x: (constants.MAX_GRID_WIDTH * constants.CHAR_PIXELS_H) / 2, - y: (constants.MAX_GRID_HEIGHT * constants.CHAR_PIXELS_V) / 2, - }); - public get offset() { return new Vector(this._offset.get().x, this._offset.get().y); } @@ -50,13 +69,6 @@ export class CanvasStore { }); } - @observable accessor persistentCommitted = Persistent.custom( - this.persistentKey("committed-layer"), - this.drawingId.shareSpec - ? new DrawingStringifier().deserialize(this.drawingId.shareSpec).layer - : new Layer(), - Layer - ); @observable accessor scratch = new Layer(); @observable accessor selection: Box; @@ -80,18 +92,6 @@ export class CanvasStore { }); } - @observable accessor undoLayers = Persistent.custom( - this.persistentKey("undo-layers"), - [], - new ArrayStringifier(Layer) - ); - - @observable accessor redoLayers = Persistent.custom( - this.persistentKey("redo-layers"), - [], - new ArrayStringifier(Layer) - ); - @action.bound setSelection(box: Box) { this.selection = box; } diff --git a/client/text_utils.ts b/client/text_utils.ts index 470da97..4eb07e6 100644 --- a/client/text_utils.ts +++ b/client/text_utils.ts @@ -32,10 +32,12 @@ export function layerToText(layer: ILayerView, box?: Box) { .forEach(([key, value]) => { lineArrays[key.y - box.topLeft().y][key.x - box.topLeft().x] = value; }); - return lineArrays - .map((lineValues) => lineValues.reduce((acc, curr) => acc + curr, "")) - .map((line) => line.replace(/\s+$/, "")) - .join("\n"); + return ( + lineArrays + .map((lineValues) => lineValues.reduce((acc, curr) => acc + curr, "")) + .map((line) => line.replace(/\s+$/, "")) + .join("\n") + ); } /** diff --git a/tsconfig.json b/tsconfig.json index f1a8580..117cc28 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,7 +14,7 @@ "sourceMap": true, "skipLibCheck": true, "jsx": "react", - "lib": ["es2017", "dom"], + "lib": ["es2021", "dom"], "esModuleInterop": true, "declaration": true, "strictPropertyInitialization": false