openpencil/packages/docs/pl/programmable/sdk/api/composables/use-editor.md
Danila Poyarkov 14325280d9 docs(i18n): translate all missing pages to 6 languages
- 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.
2026-04-22 18:35:22 +03:00

1.5 KiB

title description
useEditor Uzyskaj dostęp do bieżącej wstrzykniętej instancji edytora OpenPencil.

useEditor

useEditor() zwraca bieżący wstrzyknięty edytor OpenPencil.

Jest to główny punkt wejścia dla kompozytów SDK i bezstanowych prymitywów, które potrzebują dostępu do edytora.

Użycie

useEditor() musi być wywołane wewnątrz poddrzewa, gdzie wcześniej wywołano provideEditor(editor).

import { useEditor } from '@open-pencil/vue'

const editor = useEditor()

Podstawowy przykład

<script setup lang="ts">
import { computed } from 'vue'

import { useEditor } from '@open-pencil/vue'

const editor = useEditor()
const pageId = computed(() => editor.state.currentPageId)
</script>

<template>
  <div>Bieżąca strona: {{ pageId }}</div>
</template>

Przykłady praktyczne

Odczytaj zaznaczone węzły

const editor = useEditor()
const selected = editor.getSelectedNodes()

Wyzwól polecenia

const editor = useEditor()
editor.zoomToFit()
editor.undoAction()

Zachowanie przy błędzie

Jeśli wywołane poza drzewem dostawcy edytora, useEditor() rzuca z pomocnym komunikatem.

Jest to celowe — to API powinno głośno zawodzić, gdy brakuje kontekstu edytora.

Powiązane API

Typ

function useEditor(): Editor