91 lines
1.9 KiB
Markdown
91 lines
1.9 KiB
Markdown
|
|
---
|
||
|
|
title: useEditorCommands
|
||
|
|
description: Construye menús, acciones e interfaces impulsadas por comandos sobre el editor.
|
||
|
|
---
|
||
|
|
|
||
|
|
# useEditorCommands
|
||
|
|
|
||
|
|
`useEditorCommands()` expone una capa orientada a comandos sobre las acciones del editor.
|
||
|
|
|
||
|
|
Es útil cuando construyes:
|
||
|
|
|
||
|
|
- menús de la app
|
||
|
|
- menús contextuales
|
||
|
|
- barras de herramientas
|
||
|
|
- adaptadores de comandos de teclado
|
||
|
|
- submenús de mover página
|
||
|
|
|
||
|
|
## Uso
|
||
|
|
|
||
|
|
```ts
|
||
|
|
import { useEditorCommands } from '@open-pencil/vue'
|
||
|
|
|
||
|
|
const { commands, menuItem, runCommand, moveSelectionToPage, otherPages } = useEditorCommands()
|
||
|
|
```
|
||
|
|
|
||
|
|
## Ejemplo básico
|
||
|
|
|
||
|
|
```ts
|
||
|
|
const { menuItem } = useEditorCommands()
|
||
|
|
|
||
|
|
const editMenu = [
|
||
|
|
menuItem('edit.undo', '⌘Z'),
|
||
|
|
menuItem('edit.redo', '⇧⌘Z'),
|
||
|
|
{ separator: true },
|
||
|
|
menuItem('selection.delete'),
|
||
|
|
]
|
||
|
|
```
|
||
|
|
|
||
|
|
## Ejemplos prácticos
|
||
|
|
|
||
|
|
### Ejecutar un comando directamente
|
||
|
|
|
||
|
|
```ts
|
||
|
|
const { runCommand } = useEditorCommands()
|
||
|
|
runCommand('selection.duplicate')
|
||
|
|
```
|
||
|
|
|
||
|
|
### Construir un submenú de "mover a página"
|
||
|
|
|
||
|
|
```ts
|
||
|
|
const { otherPages, moveSelectionToPage } = useEditorCommands()
|
||
|
|
|
||
|
|
const items = otherPages.value.map(page => ({
|
||
|
|
label: page.name,
|
||
|
|
action: () => moveSelectionToPage(page.id),
|
||
|
|
}))
|
||
|
|
```
|
||
|
|
|
||
|
|
## APIs relacionadas
|
||
|
|
|
||
|
|
- [useMenuModel](./use-menu-model)
|
||
|
|
- [useSelectionState](./use-selection-state)
|
||
|
|
- [useEditor](./use-editor)
|
||
|
|
|
||
|
|
## Tipos principales
|
||
|
|
|
||
|
|
```ts
|
||
|
|
type EditorCommandId =
|
||
|
|
| 'edit.undo'
|
||
|
|
| 'edit.redo'
|
||
|
|
| 'selection.selectAll'
|
||
|
|
| 'selection.duplicate'
|
||
|
|
| 'selection.delete'
|
||
|
|
| 'selection.group'
|
||
|
|
| 'selection.ungroup'
|
||
|
|
| 'selection.createComponent'
|
||
|
|
| 'selection.createComponentSet'
|
||
|
|
| 'selection.createInstance'
|
||
|
|
| 'selection.detachInstance'
|
||
|
|
| 'selection.goToMainComponent'
|
||
|
|
| 'selection.wrapInAutoLayout'
|
||
|
|
| 'selection.bringToFront'
|
||
|
|
| 'selection.sendToBack'
|
||
|
|
| 'selection.toggleVisibility'
|
||
|
|
| 'selection.toggleLock'
|
||
|
|
| 'selection.moveToPage'
|
||
|
|
| 'view.zoom100'
|
||
|
|
| 'view.zoomFit'
|
||
|
|
| 'view.zoomSelection'
|
||
|
|
```
|