@domternal/vue 0.11.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +66 -29
- package/dist/index.d.ts +6 -0
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Domternal contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -3,42 +3,79 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@domternal/vue)
|
|
4
4
|
[](https://github.com/domternal/domternal/blob/main/LICENSE)
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
Vue 3 bindings for the [Domternal](https://domternal.dev) editor. Provides the composable
|
|
7
|
+
`Domternal` component with namespaced subcomponents, the `useEditor` and `useEditorState`
|
|
8
|
+
composables for full control, provide/inject helpers for sharing one editor across descendants,
|
|
9
|
+
and `VueNodeViewRenderer` for writing custom node views as Vue SFCs. SSR-safe by default: the
|
|
10
|
+
editor is created in `onMounted`. Requires Vue 3.3+ and the Composition API.
|
|
8
11
|
|
|
9
12
|
## Links
|
|
10
13
|
|
|
11
|
-
<u>[Website](https://domternal.dev)</u> • <u>[Documentation](https://domternal.dev/v1/
|
|
12
|
-
<u>[StackBlitz (Angular)](https://stackblitz.com/edit/domternal-angular-full-example)</u> • <u>[StackBlitz (React)](https://stackblitz.com/edit/domternal-react-full-example)</u> • <u>[StackBlitz (Vue)](https://stackblitz.com/edit/domternal-vue-full-example)</u> • <u>[StackBlitz (Vanilla TS)](https://stackblitz.com/edit/domternal-vanilla-full-example)</u>
|
|
14
|
+
<u>[Website](https://domternal.dev)</u> • <u>[Documentation](https://domternal.dev/v1/guides/vue)</u> • <u>[Live examples](https://domternal.dev/examples)</u>
|
|
13
15
|
|
|
14
|
-
##
|
|
16
|
+
## Install
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
```bash
|
|
19
|
+
pnpm add @domternal/vue @domternal/core @domternal/theme vue
|
|
20
|
+
```
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
- **React components** - composable `Domternal` component, toolbar, bubble menu, floating menu, emoji picker, notion color picker, custom node views (React 18+)
|
|
21
|
-
- **Vue components** - composable `Domternal` component, `useEditor`/`useEditorState` composables, toolbar, bubble menu, floating menu, emoji picker, notion color picker, custom node views (Vue 3.3+)
|
|
22
|
-
- **Vanilla wrapper** - framework-free class-based API for Astro, Svelte, Solid, plain HTML, and Web Components - editor, toolbar, bubble menu, floating menu, emoji picker, notion color picker
|
|
23
|
-
- **Notion-style block UX** - drag-to-reorder, block context menu, slash command, smart paste, keyboard reorder, floating Table of Contents
|
|
24
|
-
- **70+ extensions across 16 packages** - nodes, marks, and behavior extensions
|
|
25
|
-
- **125+ chainable commands** - `editor.chain().focus().toggleBold().run()`
|
|
26
|
-
- **Full table support** - cell merging, column resize, row/column controls, cell toolbar, all free and MIT licensed
|
|
27
|
-
- **Tree-shakeable** - import only what you use, your bundler strips the rest
|
|
28
|
-
- **~44 KB gzipped** (own code), <u>[see Packages](https://domternal.dev/v1/packages)</u> for full bundle breakdown with ProseMirror
|
|
29
|
-
- **TypeScript first** - 100% typed, zero `any`
|
|
30
|
-
- **15,000+ tests** - 4,000+ unit and 11,000+ E2E across 230+ Playwright specs and 4 demo apps
|
|
31
|
-
- **Light and dark theme** - 120+ CSS custom properties for full visual control
|
|
32
|
-
- **Inline styles export** - `getHTML({ styled: true })` produces inline CSS ready for email clients, CMS, and Google Docs
|
|
33
|
-
- **SSR helpers** - `generateHTML`, `generateJSON`, `generateText` for server-side rendering
|
|
22
|
+
`vue` (>=3.3) and `@domternal/core` are peer dependencies. `@domternal/theme` supplies the
|
|
23
|
+
editor styles.
|
|
34
24
|
|
|
35
|
-
##
|
|
25
|
+
## Usage
|
|
36
26
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
- <u>[Packages & Bundle Size](https://domternal.dev/v1/packages)</u> - what each package includes and bundle size breakdown
|
|
40
|
-
- <u>[Blog](https://domternal.dev/blog)</u>
|
|
27
|
+
Composable component pattern (recommended): `Domternal` creates the editor and provides it to all
|
|
28
|
+
subcomponents via inject, so children need no `editor` prop.
|
|
41
29
|
|
|
42
|
-
|
|
30
|
+
```vue
|
|
31
|
+
<script setup lang="ts">
|
|
32
|
+
import { Domternal } from '@domternal/vue';
|
|
33
|
+
import { StarterKit, BubbleMenu } from '@domternal/core';
|
|
34
|
+
import '@domternal/theme';
|
|
43
35
|
|
|
44
|
-
|
|
36
|
+
const extensions = [StarterKit, BubbleMenu];
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<template>
|
|
40
|
+
<Domternal :extensions="extensions" content="<p>Hello from Vue!</p>">
|
|
41
|
+
<Domternal.Toolbar />
|
|
42
|
+
<Domternal.Content />
|
|
43
|
+
<Domternal.BubbleMenu :contexts="{ text: ['bold', 'italic', 'underline'] }" />
|
|
44
|
+
</Domternal>
|
|
45
|
+
</template>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Composable hook
|
|
49
|
+
|
|
50
|
+
Use `useEditor` directly when you need the editor instance, then read reactive state with
|
|
51
|
+
`useEditorState`:
|
|
52
|
+
|
|
53
|
+
```vue
|
|
54
|
+
<script setup lang="ts">
|
|
55
|
+
import { useEditor, useEditorState, provideEditor, DomternalToolbar } from '@domternal/vue';
|
|
56
|
+
import { StarterKit } from '@domternal/core';
|
|
57
|
+
|
|
58
|
+
const { editor, editorRef } = useEditor({
|
|
59
|
+
extensions: [StarterKit],
|
|
60
|
+
content: '<p>Start typing...</p>',
|
|
61
|
+
onUpdate: ({ editor }) => console.log(editor.getHTML()),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
provideEditor(editor);
|
|
65
|
+
|
|
66
|
+
const { htmlContent, isEmpty } = useEditorState(editor);
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<template>
|
|
70
|
+
<DomternalToolbar />
|
|
71
|
+
<div ref="editorRef" class="dm-editor" />
|
|
72
|
+
</template>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`useEditor` returns `editor` (a `ShallowRef<Editor | null>`, null until mounted) and `editorRef`
|
|
76
|
+
(bind to the mount element). `useEditorState` returns `htmlContent`, `jsonContent`, `isEmpty`,
|
|
77
|
+
`isFocused`, and `isEditable`, or pass a selector for a granular `ComputedRef`:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const isBold = useEditorState(editor, (ed) => ed.isActive('bold'));
|
|
81
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,12 @@ declare const DEFAULT_EXTENSIONS: AnyExtension[];
|
|
|
9
9
|
interface UseEditorOptions {
|
|
10
10
|
/** Custom extensions to add to the editor. */
|
|
11
11
|
extensions?: AnyExtension[];
|
|
12
|
+
/**
|
|
13
|
+
* Whether the built-in History extension is included. Disable it when an
|
|
14
|
+
* extension brings its own undo/redo, such as collaborative editing.
|
|
15
|
+
* @default true
|
|
16
|
+
*/
|
|
17
|
+
history?: boolean;
|
|
12
18
|
/** Initial editor content (HTML string or JSON). */
|
|
13
19
|
content?: Content;
|
|
14
20
|
/** Whether the editor is editable. @default true */
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineComponent, h, computed, Fragment, ref, watch, shallowRef, onMounted, nextTick, onScopeDispose, watchEffect, Teleport, inject, provide, getCurrentInstance, customRef, markRaw, shallowReactive, render } from 'vue';
|
|
2
|
-
import { positionFloatingOnce, PluginKey, positionFloating, ToolbarController, refocusEditorAfterCommand, createFloatingMenuPlugin, FloatingMenuController, defaultIcons, defaultBubbleContexts, createBubbleMenuPlugin,
|
|
2
|
+
import { positionFloatingOnce, PluginKey, positionFloating, ToolbarController, refocusEditorAfterCommand, createFloatingMenuPlugin, FloatingMenuController, defaultIcons, defaultBubbleContexts, createBubbleMenuPlugin, Document, Paragraph, Text, BaseKeymap, History, Editor } from '@domternal/core';
|
|
3
3
|
export { Editor, generateHTML, generateJSON, generateText } from '@domternal/core';
|
|
4
4
|
|
|
5
5
|
// src/useEditor.ts
|
|
@@ -27,9 +27,10 @@ function useEditor(options = {}) {
|
|
|
27
27
|
function createEditorInstance(element, initialContent, focus) {
|
|
28
28
|
const extensions = options.extensions ?? [];
|
|
29
29
|
const editable = options.editable ?? true;
|
|
30
|
+
const defaults = options.history ?? true ? DEFAULT_EXTENSIONS : DEFAULT_EXTENSIONS.filter((extension) => extension.name !== "history");
|
|
30
31
|
const ed = new Editor({
|
|
31
32
|
element,
|
|
32
|
-
extensions: [...
|
|
33
|
+
extensions: [...defaults, ...extensions],
|
|
33
34
|
content: initialContent,
|
|
34
35
|
editable,
|
|
35
36
|
autofocus: focus
|