@lupinum/board-history 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present Lupinum OG and contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,58 @@
1
+ <p align="center"><img src="https://raw.githubusercontent.com/lupinum-dev/nuxt-board/main/docs/public/app-icon.svg" width="128" alt="Nuxt Board icon"></p>
2
+
3
+ <h1 align="center">@lupinum/board-history</h1>
4
+
5
+ <p align="center">Add deterministic undo and redo to the Nuxt Board engine.</p>
6
+
7
+ <p align="center">
8
+ <a href="https://www.npmjs.com/package/@lupinum/board-history"><img src="https://img.shields.io/npm/v/@lupinum/board-history?label=npm" alt="npm version"></a>
9
+ <a href="https://github.com/lupinum-dev/nuxt-board/actions/workflows/ci.yml"><img src="https://github.com/lupinum-dev/nuxt-board/actions/workflows/ci.yml/badge.svg" alt="CI status"></a>
10
+ <a href="https://github.com/lupinum-dev/nuxt-board/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT license"></a>
11
+ </p>
12
+
13
+ > [!WARNING]
14
+ > This package has not reached a stable release. Review the changelog before each upgrade.
15
+
16
+ ## Purpose
17
+
18
+ Use this plugin when users must reverse committed board changes. One completed drag, resize, text edit, or outer batch creates one history frame.
19
+
20
+ ## Requirements
21
+
22
+ Install the same version of this package and `@lupinum/board-core`. The fixed-version release keeps the plugin ABI aligned with the engine.
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ pnpm add @lupinum/board-history @lupinum/board-core
28
+ ```
29
+
30
+ ## Quick start
31
+
32
+ ```ts
33
+ import { createBoardEngine } from '@lupinum/board-core'
34
+ import { historyPlugin } from '@lupinum/board-history'
35
+
36
+ const engine = createBoardEngine({
37
+ plugins: [historyPlugin({ maxSteps: 200 })],
38
+ })
39
+
40
+ engine.plugins.history.undo()
41
+ engine.plugins.history.redo()
42
+ ```
43
+
44
+ ## Exports
45
+
46
+ The package exports the history plugin and its typed history controls.
47
+
48
+ ## Documentation
49
+
50
+ Read the [history reference](https://nuxt-board.lupinum.com/docs/reference/history).
51
+
52
+ ## Support and security
53
+
54
+ Open a [GitHub issue](https://github.com/lupinum-dev/nuxt-board/issues) for support. Report vulnerabilities through the [private security process](https://github.com/lupinum-dev/nuxt-board/security/policy).
55
+
56
+ ## License
57
+
58
+ This package uses the [MIT License](https://github.com/lupinum-dev/nuxt-board/blob/main/LICENSE).
@@ -0,0 +1,36 @@
1
+ import type { BoardEventMap, BoardPlugin, BoardPluginApis } from '@lupinum/board-core';
2
+ /** Public history state exposed by the history plugin API. */
3
+ export interface HistoryState {
4
+ undoDepth: number;
5
+ redoDepth: number;
6
+ current: string | null;
7
+ }
8
+ /** Public metadata for a single undoable history frame. */
9
+ export interface HistoryEntry {
10
+ label: string;
11
+ timestamp: number;
12
+ }
13
+ /** Options for bounding retained structural history roots. */
14
+ export interface HistoryPluginOptions {
15
+ maxSteps?: number;
16
+ }
17
+ export interface HistoryApi {
18
+ undo: () => void;
19
+ redo: () => void;
20
+ canUndo: () => boolean;
21
+ canRedo: () => boolean;
22
+ clear: () => void;
23
+ getState: () => HistoryState;
24
+ }
25
+ export interface HistoryEventMap extends BoardEventMap {
26
+ 'history:push': (entry: HistoryEntry) => void;
27
+ 'history:undo': (entry: HistoryEntry | null) => void;
28
+ 'history:redo': (entry: HistoryEntry | null) => void;
29
+ 'history:clear': () => void;
30
+ }
31
+ interface HistoryPluginApis extends BoardPluginApis {
32
+ history: HistoryApi;
33
+ }
34
+ /** Install deterministic undo/redo backed by committed structural roots. */
35
+ export declare function historyPlugin(options?: HistoryPluginOptions): BoardPlugin<HistoryPluginApis, HistoryEventMap>;
36
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,83 @@
1
+ // src/index.ts
2
+ import {
3
+ defineInternalBoardPlugin
4
+ } from "@lupinum/board-core/internal";
5
+ function toHistoryEntry(frame) {
6
+ return { label: frame.label, timestamp: frame.timestamp };
7
+ }
8
+ function historyPlugin(options = {}) {
9
+ const maxSteps = Math.max(1, options.maxSteps ?? 200);
10
+ return defineInternalBoardPlugin({
11
+ name: "history",
12
+ install(engine) {
13
+ const undoStack = [];
14
+ const redoStack = [];
15
+ const offCommit = engine.projectCommit((commit) => {
16
+ if (commit.metadata.history === "ignore") return () => void 0;
17
+ const frame = Object.freeze({
18
+ label: commit.label,
19
+ timestamp: commit.timestamp,
20
+ before: commit.before,
21
+ after: commit.after
22
+ });
23
+ return () => {
24
+ undoStack.push(frame);
25
+ if (undoStack.length > maxSteps) undoStack.shift();
26
+ redoStack.length = 0;
27
+ engine.emit("history:push", toHistoryEntry(frame));
28
+ };
29
+ });
30
+ const api = {
31
+ undo() {
32
+ engine.assertActive();
33
+ const frame = undoStack.pop() ?? null;
34
+ if (!frame) {
35
+ engine.emit("history:undo", null);
36
+ return;
37
+ }
38
+ engine.restoreHistoryRoot(frame.before);
39
+ redoStack.push(frame);
40
+ engine.emit("history:undo", toHistoryEntry(frame));
41
+ },
42
+ redo() {
43
+ engine.assertActive();
44
+ const frame = redoStack.pop() ?? null;
45
+ if (!frame) {
46
+ engine.emit("history:redo", null);
47
+ return;
48
+ }
49
+ engine.restoreHistoryRoot(frame.after);
50
+ undoStack.push(frame);
51
+ engine.emit("history:redo", toHistoryEntry(frame));
52
+ },
53
+ canUndo: () => {
54
+ engine.assertActive();
55
+ return undoStack.length > 0;
56
+ },
57
+ canRedo: () => {
58
+ engine.assertActive();
59
+ return redoStack.length > 0;
60
+ },
61
+ clear() {
62
+ engine.assertActive();
63
+ undoStack.length = 0;
64
+ redoStack.length = 0;
65
+ engine.emit("history:clear");
66
+ },
67
+ getState: () => {
68
+ engine.assertActive();
69
+ return {
70
+ undoDepth: undoStack.length,
71
+ redoDepth: redoStack.length,
72
+ current: undoStack[undoStack.length - 1]?.label ?? null
73
+ };
74
+ }
75
+ };
76
+ engine.extend("history", api);
77
+ return offCommit;
78
+ }
79
+ });
80
+ }
81
+ export {
82
+ historyPlugin
83
+ };
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@lupinum/board-history",
3
+ "version": "0.1.0",
4
+ "description": "Undo and redo plugin for @lupinum/board-core.",
5
+ "license": "MIT",
6
+ "author": "Lupinum OG <info@lupinum.com> (https://lupinum.com)",
7
+ "type": "module",
8
+ "engines": {
9
+ "node": ">=20.19.0"
10
+ },
11
+ "main": "dist/index.js",
12
+ "module": "dist/index.js",
13
+ "types": "dist/index.d.ts",
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ }
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/lupinum-dev/nuxt-board.git",
26
+ "directory": "packages/board-history"
27
+ },
28
+ "homepage": "https://nuxt-board.lupinum.com",
29
+ "bugs": {
30
+ "url": "https://github.com/lupinum-dev/nuxt-board/issues"
31
+ },
32
+ "keywords": [
33
+ "board",
34
+ "history",
35
+ "undo",
36
+ "redo"
37
+ ],
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "peerDependencies": {
42
+ "@lupinum/board-core": "0.1.0"
43
+ },
44
+ "scripts": {
45
+ "build": "tsup src/index.ts --format esm --clean && tsc -p tsconfig.build.json"
46
+ }
47
+ }