@commonpub/editor 0.7.0 → 0.7.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commonpub/editor",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "TipTap block editor with 18+ maker-focused extensions for CommonPub",
|
|
6
6
|
"license": "AGPL-3.0-or-later",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"unified": "^11.0.5",
|
|
52
52
|
"zod": "^4.3.6",
|
|
53
53
|
"@commonpub/config": "0.9.0",
|
|
54
|
-
"@commonpub/schema": "0.9.
|
|
54
|
+
"@commonpub/schema": "0.9.4"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"vue": "^3.4.0",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* - Drag-and-drop reordering via BlockWrapper
|
|
10
10
|
* - Floating text toolbar on selection (delegated to FloatingToolbar)
|
|
11
11
|
*/
|
|
12
|
-
import { ref, inject, type Component } from 'vue';
|
|
12
|
+
import { ref, inject, onMounted, onUnmounted, type Component } from 'vue';
|
|
13
13
|
import type { EditorBlock, BlockTypeGroup } from '../types.js';
|
|
14
14
|
import type { BlockEditor } from '../composables/useBlockEditor.js';
|
|
15
15
|
import { BLOCK_COMPONENTS_KEY, UPLOAD_HANDLER_KEY, SEARCH_PRODUCTS_KEY } from '../provide.js';
|
|
@@ -309,6 +309,30 @@ function needsUpload(type: string): boolean {
|
|
|
309
309
|
function needsSearch(type: string): boolean {
|
|
310
310
|
return type === 'partsList';
|
|
311
311
|
}
|
|
312
|
+
|
|
313
|
+
// --- Undo/Redo keyboard shortcuts ---
|
|
314
|
+
function onKeydown(event: KeyboardEvent): void {
|
|
315
|
+
const mod = event.metaKey || event.ctrlKey;
|
|
316
|
+
if (!mod || event.key.toLowerCase() !== 'z') return;
|
|
317
|
+
|
|
318
|
+
// Don't intercept when an element with its own undo is focused:
|
|
319
|
+
// - ProseMirror (TipTap text blocks have their own undo)
|
|
320
|
+
// - textarea/input (native browser undo for code blocks, math, titles, etc.)
|
|
321
|
+
const el = document.activeElement;
|
|
322
|
+
if (el?.closest('.ProseMirror')) return;
|
|
323
|
+
const tag = el?.tagName;
|
|
324
|
+
if (tag === 'TEXTAREA' || tag === 'INPUT' || tag === 'SELECT') return;
|
|
325
|
+
|
|
326
|
+
event.preventDefault();
|
|
327
|
+
if (event.shiftKey) {
|
|
328
|
+
props.blockEditor.redo();
|
|
329
|
+
} else {
|
|
330
|
+
props.blockEditor.undo();
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
onMounted(() => { document.addEventListener('keydown', onKeydown); });
|
|
335
|
+
onUnmounted(() => { document.removeEventListener('keydown', onKeydown); });
|
|
312
336
|
</script>
|
|
313
337
|
|
|
314
338
|
<template>
|
|
@@ -115,6 +115,10 @@ export function useBlockEditor(initialBlocks?: BlockTuple[], options?: BlockEdit
|
|
|
115
115
|
type,
|
|
116
116
|
content: { ...content },
|
|
117
117
|
}));
|
|
118
|
+
// Reset history — loading new content is not an undoable operation
|
|
119
|
+
history.splice(0, history.length);
|
|
120
|
+
historyIndex.value = -1;
|
|
121
|
+
pushHistory();
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
if (initialBlocks && initialBlocks.length > 0) {
|