@gotipe/vue
v0.1.2
Published
Vue 3 adapter for the GoTipe editor: useEditor, useEditorState and the EditorContent renderer.
Maintainers
Readme
@gotipe/vue
The Vue 3 adapter for GoTipe: composables that create and observe an editor, and an
EditorContent component that renders its document. It ships no CSS and no ready editor UI.
Docs · Website · Repository
Install
npm install @gotipe/core @gotipe/vue vueVue 3.4 or newer.
Usage
<script setup lang="ts">
import { DefaultPreset } from "@gotipe/core/presets";
import { EditorContent, useEditor, useEditorState } from "@gotipe/vue";
const editor = useEditor({
extensions: [DefaultPreset],
content: "<h1>Notes</h1><p>Select a word and press Bold.</p>",
});
const bold = useEditorState(editor, (state) => state.toolbar.activeMarks.includes("bold"));
function toggleBold() {
editor.value?.chain().focus().toggleBold().run();
}
</script>
<template>
<button type="button" :aria-pressed="bold ?? false" :disabled="!editor" @mousedown.prevent @click="toggleBold">
Bold
</button>
<EditorContent :editor="editor" aria-label="Notes" />
</template>@mousedown.prevent keeps the selection in the document while you click.
useEditor(options): aShallowRefwith the editor, created inonMountedand destroyed inonBeforeUnmount.useEditorStatus(options): the same editor and why it could not be created.useEditorState(editor, selector): aShallowRefupdated on every view change.EditorContent: the document surface; propseditor,blockViewsandariaLabel.editorKey,useEditorContext(): provide an editor to child components and read it.
License
MIT. See LICENSE.
