32 lines
938 B
TypeScript
32 lines
938 B
TypeScript
import { Extension } from "@tiptap/core"
|
|
import { Plugin, PluginKey } from "@tiptap/pm/state"
|
|
import { runGraphicKeyboardAction } from "@/lib/drive/docs-graphic-keyboard"
|
|
|
|
export const docsGraphicKeyboardKey = new PluginKey("docsGraphicKeyboard")
|
|
|
|
/**
|
|
* Keyboard control for selected graphics:
|
|
* - Arrows: move (Shift = 10px); in-flow (« Avec le texte »): ↑↓ reorder, ←→ cycle left/center/right
|
|
* - Alt+Arrows: resize (Shift = 20px)
|
|
* - [ / ]: rotate ±5° (Shift = ±15°)
|
|
* - Mod+[ / Mod+]: send backward / bring forward
|
|
*/
|
|
export const DocsGraphicKeyboard = Extension.create({
|
|
name: "docsGraphicKeyboard",
|
|
priority: 1000,
|
|
|
|
addProseMirrorPlugins() {
|
|
const editor = this.editor
|
|
return [
|
|
new Plugin({
|
|
key: docsGraphicKeyboardKey,
|
|
props: {
|
|
handleKeyDown(_view, event) {
|
|
return runGraphicKeyboardAction(editor, event)
|
|
},
|
|
},
|
|
}),
|
|
]
|
|
},
|
|
})
|