- 78 SDK pages per language (components, composables, advanced API, guides, architecture, getting-started) - vector-edit.md user guide page (5 languages) - Update stale ru/programmable/cli/inspecting.md - Fix YAML frontmatter quoting for colons in descriptions 474 files, 0 missing pages across de/es/fr/it/pl/ru. VitePress build verified — all 546 SDK pages render.
2.7 KiB
2.7 KiB
| title | description |
|---|---|
| SDK – Erste Schritte | @open-pencil/vue mit createEditor, provideEditor und einem Canvas einrichten. |
SDK – Erste Schritte
Installation
bun add @open-pencil/core @open-pencil/vue canvaskit-wasm
Das SDK befindet sich heute im Monorepo und wird auch als @open-pencil/vue veröffentlicht.
import { createEditor } from '@open-pencil/core/editor'
import { provideEditor, useCanvas } from '@open-pencil/vue'
Mentales Modell
Es gibt drei Schichten:
@open-pencil/core— framework-agnostische Editor-Engine@open-pencil/vue— Vue Composables und headless Primitive- Ihre App — Styling, Routing, Datei-Flows, produktspezifische UI
Minimales Setup
1. Einen Editor erstellen
import { createEditor } from '@open-pencil/core/editor'
const editor = createEditor({
width: 1200,
height: 800,
})
2. Vue bereitstellen
<script setup lang="ts">
import { provideEditor } from '@open-pencil/vue'
import type { Editor } from '@open-pencil/core/editor'
const props = defineProps<{
editor: Editor
}>()
provideEditor(props.editor)
</script>
<template>
<slot />
</template>
Diese Schicht fungiert als Provider für den Editor-Baum. Die Dokumentation bevorzugt provideEditor() direkt, da dies die aktuelle echte API-Oberfläche ist.
3. Einen Canvas anbinden
<script setup lang="ts">
import { ref } from 'vue'
import { useCanvas, useEditor } from '@open-pencil/vue'
const canvasRef = ref<HTMLCanvasElement | null>(null)
const editor = useEditor()
useCanvas(canvasRef, editor)
</script>
<template>
<canvas ref="canvasRef" class="size-full" />
</template>
Composables verwenden
Sobald der Editor bereitgestellt ist, können Kind-Komponenten die Auswahl lesen und Befehle ausgeben:
import { useEditorCommands, useSelectionState } from '@open-pencil/vue'
const selection = useSelectionState()
const commands = useEditorCommands()
Einfaches Beispiel
<script setup lang="ts">
import { ref } from 'vue'
import { useCanvas, useEditor, useSelectionState } from '@open-pencil/vue'
const canvasRef = ref<HTMLCanvasElement | null>(null)
const editor = useEditor()
const { selectedCount } = useSelectionState()
useCanvas(canvasRef, editor, {
onReady: () => {
console.log('Canvas ready')
},
})
</script>
<template>
<div class="grid h-full grid-rows-[1fr_auto]">
<canvas ref="canvasRef" class="size-full" />
<div class="border-t px-3 py-2 text-xs text-muted">
Ausgewählt: {{ selectedCount }}
</div>
</div>
</template>