npm.io
3.3.0 • Published 3 weeks ago

autumnnote-vue

Licence
MIT
Version
3.3.0
Deps
0
Size
10 kB
Vulns
0
Weekly
0
Stars
11

autumnnote-vue

npm version npm downloads License: MIT

Official Vue 3 wrapper for Autumn Note — the zero-dependency WYSIWYG rich-text editor built with vanilla JavaScript.

Installation

npm install autumnnote autumnnote-vue

Import the stylesheet once in your app:

import 'autumnnote/dist/autumnnote.css';

Quick Start

<script setup>
import { ref } from 'vue';
import AutumnNoteEditor from 'autumnnote-vue';
import 'autumnnote/dist/autumnnote.css';

const editorRef = ref(null);

function handleSave() {
  const html = editorRef.value.editor?.getHTML();
  console.log(html);
}
</script>

<template>
  <AutumnNoteEditor
    ref="editorRef"
    :options="{
      placeholder: 'Start typing…',
      height: 300,
      bubbleToolbar: true,
    }"
  />
  <button @click="handleSave">Save</button>
</template>

Props

Prop Type Description
options AsnOptions Editor configuration. See all options.

Accessing the editor instance

The component exposes the current Context as editor. Vue automatically unwraps the internal shallow ref on the public component instance:

editorRef.value.editor?.getHTML();
editorRef.value.editor?.setHTML('<p>Hello <strong>world</strong></p>');
editorRef.value.editor?.getMarkdown();
editorRef.value.editor?.invoke('toolbar.rebuild');
editorRef.value.editor?.on('change', (html) => console.log(html));

The exposed editor property is null before mount — use it inside onMounted or after the component is mounted.

Reinitialising with new options

The editor initialises once in onMounted. To reinitialise with a new configuration, toggle v-if — Vue will unmount and remount the component:

<script setup>
import { ref } from 'vue';

const ready = ref(true);
const options = ref({ theme: 'light' });

async function switchToDark() {
  options.value = { theme: 'dark' };
  ready.value = false;
  await nextTick();
  ready.value = true;
}
</script>

<template>
  <AutumnNoteEditor v-if="ready" :options="options" />
</template>

Dark mode

<AutumnNoteEditor :options="{ theme: 'dark', placeholder: 'Start typing…' }" />

Using plugins

import AutumnNote from 'autumnnote';

// Register globally before any component mounts
AutumnNote.use(MyPlugin, { limit: 500 });
<AutumnNoteEditor :options="{ toolbar: [[boldBtn, 'myButton']] }" />

TypeScript

The package ships hand-crafted TypeScript declarations (index.d.ts). No @types package needed:

<script setup lang="ts">
import { ref } from 'vue';
import type { Context, AsnOptions } from 'autumnnote';
import AutumnNoteEditor from 'autumnnote-vue';

const editorRef = ref<{ editor: { value: Context | null } } | null>(null);
const options: AsnOptions = { height: 300, bubbleToolbar: true };
</script>

<template>
  <AutumnNoteEditor ref="editorRef" :options="options" />
</template>

License

MIT Minh Pham

Keywords