@lupinum/board-history 0.1.0 → 1.0.0-beta.2
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/dist/vue.d.ts +14 -0
- package/dist/vue.js +59 -0
- package/package.json +22 -3
package/dist/vue.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type PropType } from 'vue';
|
|
2
|
+
import type { HistoryApi } from './index.js';
|
|
3
|
+
/** Renderless undo/redo shortcuts scoped to the enclosing BoardRoot. */
|
|
4
|
+
export declare const BoardHistoryShortcuts: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
5
|
+
history: {
|
|
6
|
+
type: PropType<HistoryApi>;
|
|
7
|
+
required: true;
|
|
8
|
+
};
|
|
9
|
+
}>, () => null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
10
|
+
history: {
|
|
11
|
+
type: PropType<HistoryApi>;
|
|
12
|
+
required: true;
|
|
13
|
+
};
|
|
14
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
package/dist/vue.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// src/vue.ts
|
|
2
|
+
import { defineComponent, toRaw, watch } from "vue";
|
|
3
|
+
import { useBoardEngine } from "@lupinum/vue-board";
|
|
4
|
+
import {
|
|
5
|
+
isBoardInteractiveEventTarget,
|
|
6
|
+
isEventOwnedByBoardRoot
|
|
7
|
+
} from "@lupinum/board-core/internal";
|
|
8
|
+
var BoardHistoryShortcuts = defineComponent({
|
|
9
|
+
name: "BoardHistoryShortcuts",
|
|
10
|
+
props: {
|
|
11
|
+
history: {
|
|
12
|
+
type: Object,
|
|
13
|
+
required: true
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
setup(props) {
|
|
17
|
+
const context = useBoardEngine();
|
|
18
|
+
function getOwnedHistory() {
|
|
19
|
+
const plugins = context.engine.plugins;
|
|
20
|
+
if (!("history" in plugins) || toRaw(plugins.history) !== toRaw(props.history)) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
"BoardHistoryShortcuts history must belong to its enclosing BoardRoot engine."
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return props.history;
|
|
26
|
+
}
|
|
27
|
+
getOwnedHistory();
|
|
28
|
+
watch(() => props.history, getOwnedHistory);
|
|
29
|
+
watch(
|
|
30
|
+
() => context.rootElement.value,
|
|
31
|
+
(root, _previous, onCleanup) => {
|
|
32
|
+
if (!root) return;
|
|
33
|
+
const onKeyDown = (event) => {
|
|
34
|
+
if (event.defaultPrevented || isBoardInteractiveEventTarget(event.target))
|
|
35
|
+
return;
|
|
36
|
+
if (!isEventOwnedByBoardRoot(event.target, root)) return;
|
|
37
|
+
if (!event.metaKey && !event.ctrlKey) return;
|
|
38
|
+
const key = event.key.toLowerCase();
|
|
39
|
+
const history = getOwnedHistory();
|
|
40
|
+
if (key === "z") {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
if (event.shiftKey) history.redo();
|
|
43
|
+
else history.undo();
|
|
44
|
+
} else if (key === "y") {
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
history.redo();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
root.addEventListener("keydown", onKeyDown);
|
|
50
|
+
onCleanup(() => root.removeEventListener("keydown", onKeyDown));
|
|
51
|
+
},
|
|
52
|
+
{ immediate: true }
|
|
53
|
+
);
|
|
54
|
+
return () => null;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
export {
|
|
58
|
+
BoardHistoryShortcuts
|
|
59
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lupinum/board-history",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
4
4
|
"description": "Undo and redo plugin for @lupinum/board-core.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Lupinum OG <info@lupinum.com> (https://lupinum.com)",
|
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
".": {
|
|
19
19
|
"types": "./dist/index.d.ts",
|
|
20
20
|
"import": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./vue": {
|
|
23
|
+
"types": "./dist/vue.d.ts",
|
|
24
|
+
"import": "./dist/vue.js"
|
|
21
25
|
}
|
|
22
26
|
},
|
|
23
27
|
"repository": {
|
|
@@ -39,9 +43,24 @@
|
|
|
39
43
|
"access": "public"
|
|
40
44
|
},
|
|
41
45
|
"peerDependencies": {
|
|
42
|
-
"
|
|
46
|
+
"vue": "^3.5.0",
|
|
47
|
+
"@lupinum/board-core": "1.0.0-beta.2",
|
|
48
|
+
"@lupinum/vue-board": "1.0.0-beta.2"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"@lupinum/vue-board": {
|
|
52
|
+
"optional": true
|
|
53
|
+
},
|
|
54
|
+
"vue": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"vue": "^3.5.0",
|
|
60
|
+
"@lupinum/board-core": "1.0.0-beta.2",
|
|
61
|
+
"@lupinum/vue-board": "1.0.0-beta.2"
|
|
43
62
|
},
|
|
44
63
|
"scripts": {
|
|
45
|
-
"build": "tsup src/index.ts --format esm --clean && tsc -p tsconfig.build.json"
|
|
64
|
+
"build": "tsup src/index.ts src/vue.ts --format esm --clean && tsc -p tsconfig.build.json"
|
|
46
65
|
}
|
|
47
66
|
}
|