From 04b6353e4192aa0d828cf700c58e66853f561d03 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Mon, 6 Sep 2021 13:43:56 +0100 Subject: [PATCH] Adds setter for history --- packages/core/package.json | 2 +- packages/tldraw/package.json | 2 +- packages/tldraw/src/state/tlstate.spec.ts | 9 +++++++++ packages/tldraw/src/state/tlstate.ts | 8 ++++++++ yarn.lock | 10 +++++++++- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 6eebbdcc9..f7f1314d7 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -23,7 +23,7 @@ "start": "node scripts/dev & yarn types:dev", "build": "node scripts/build && yarn types:build", "types:pre": "tsc", - "types:dev": "tsc --watch ", + "types:dev": "tsc --watch", "types:build": "tsc --project tsconfig.build.json", "lint": "eslint src/ --ext .ts,.tsx", "clean": "rm -rf dist", diff --git a/packages/tldraw/package.json b/packages/tldraw/package.json index 190f830c4..39b7a3034 100644 --- a/packages/tldraw/package.json +++ b/packages/tldraw/package.json @@ -67,6 +67,6 @@ "@tldraw/core": "^0.0.79", "perfect-freehand": "^0.5.3", "react-hotkeys-hook": "^3.4.0", - "rko": "^0.5.22" + "rko": "^0.5.23" } } \ No newline at end of file diff --git a/packages/tldraw/src/state/tlstate.spec.ts b/packages/tldraw/src/state/tlstate.spec.ts index ad02a93a3..b373dc6ee 100644 --- a/packages/tldraw/src/state/tlstate.spec.ts +++ b/packages/tldraw/src/state/tlstate.spec.ts @@ -370,5 +370,14 @@ describe('TLDrawState', () => { expect(tlstate.history).toBeDefined() expect(tlstate.history).toMatchSnapshot('history') + + tlstate.history = [] + expect(tlstate.history).toEqual([]) + + const before = tlstate.state + tlstate.undo() + const after = tlstate.state + + expect(before).toBe(after) }) }) diff --git a/packages/tldraw/src/state/tlstate.ts b/packages/tldraw/src/state/tlstate.ts index 10b836217..2903d7c86 100644 --- a/packages/tldraw/src/state/tlstate.ts +++ b/packages/tldraw/src/state/tlstate.ts @@ -37,6 +37,7 @@ import { TLDrawPage, TLDrawBinding, GroupShape, + TLDrawCommand, } from '~types' import { TLDR } from './tldr' import { defaultStyle } from '~shape' @@ -653,6 +654,13 @@ export class TLDrawState extends StateManager { return this.stack } + /** + * Replace the current history stack. + */ + set history(commands: TLDrawCommand[]) { + this.replaceHistory(commands) + } + /** * The current document. */ diff --git a/yarn.lock b/yarn.lock index bb9359663..01f439817 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11557,7 +11557,7 @@ ripemd160@^2.0.0, ripemd160@^2.0.1: hash-base "^3.0.0" inherits "^2.0.1" -rko@^0.5.19, rko@^0.5.20, rko@^0.5.22: +rko@^0.5.19, rko@^0.5.20: version "0.5.22" resolved "https://registry.yarnpkg.com/rko/-/rko-0.5.22.tgz#d5a563beefd97a9cfdda3c29c1fbe119d782b576" integrity sha512-aNXCHTLshLgq6XuWZzb3XKgy5RyS5YY6/YzCnrBa+tn7NTPC2HysbNhJwyt6bow3u8whiD36GajhUYR6oIbJWw== @@ -11565,6 +11565,14 @@ rko@^0.5.19, rko@^0.5.20, rko@^0.5.22: idb-keyval "^5.1.3" zustand "^3.5.9" +rko@^0.5.23: + version "0.5.23" + resolved "https://registry.yarnpkg.com/rko/-/rko-0.5.23.tgz#2613c05d518df71b08215bb031aa4680ede51302" + integrity sha512-u4c2n/99zE+j23WE7FoO5GA4ussYhvhZ5/fh/xJ9ctXyV6Vy+445r2jM2M2xegrCRkIw67RtPI5BmpCXZHnRxA== + dependencies: + idb-keyval "^5.1.3" + zustand "^3.5.9" + rollup-plugin-terser@^7.0.0: version "7.0.2" resolved "https://registry.yarnpkg.com/rollup-plugin-terser/-/rollup-plugin-terser-7.0.2.tgz#e8fbba4869981b2dc35ae7e8a502d5c6c04d324d"