@domternal/vanilla 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 +65 -29
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2 -1
- 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,78 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@domternal/vanilla)
|
|
4
4
|
[](https://github.com/domternal/domternal/blob/main/LICENSE)
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
Framework-free DOM components for the [Domternal](https://domternal.dev) editor.
|
|
7
|
+
Each component is a class you instantiate against a host element:
|
|
8
|
+
`DomternalEditor`, `DomternalToolbar`, `DomternalBubbleMenu`, `DomternalFloatingMenu`,
|
|
9
|
+
`DomternalEmojiPicker`, and `DomternalNotionColorPicker`. Every class extends
|
|
10
|
+
`EventTarget`, exposes plain getters and mutator methods, dispatches `CustomEvent`s for state
|
|
11
|
+
changes, and tears down with an idempotent `destroy()`. Use it in Astro, Svelte, Solid,
|
|
12
|
+
Lit, Web Components, or plain HTML - anywhere without a framework runtime.
|
|
8
13
|
|
|
9
14
|
## Links
|
|
10
15
|
|
|
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>
|
|
16
|
+
<u>[Website](https://domternal.dev)</u> • <u>[Documentation](https://domternal.dev/v1/guides/vanilla)</u> • <u>[Live examples](https://domternal.dev/examples)</u>
|
|
13
17
|
|
|
14
|
-
##
|
|
18
|
+
## Install
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
```bash
|
|
21
|
+
pnpm add @domternal/core @domternal/theme @domternal/vanilla
|
|
22
|
+
```
|
|
17
23
|
|
|
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
|
|
24
|
+
`@domternal/core` is a peer dependency. `@domternal/theme` supplies the editor styles
|
|
25
|
+
(import it once in your app).
|
|
34
26
|
|
|
35
|
-
##
|
|
27
|
+
## Usage
|
|
36
28
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
```ts
|
|
30
|
+
import { StarterKit } from '@domternal/core';
|
|
31
|
+
import {
|
|
32
|
+
DomternalEditor,
|
|
33
|
+
DomternalToolbar,
|
|
34
|
+
DomternalBubbleMenu,
|
|
35
|
+
} from '@domternal/vanilla';
|
|
36
|
+
import '@domternal/theme';
|
|
41
37
|
|
|
42
|
-
|
|
38
|
+
const toolbarEl = document.getElementById('toolbar')!;
|
|
39
|
+
const editorEl = document.getElementById('editor')!;
|
|
40
|
+
const bubbleEl = document.getElementById('bubble')!;
|
|
43
41
|
|
|
44
|
-
|
|
42
|
+
const dm = new DomternalEditor(editorEl, {
|
|
43
|
+
extensions: [StarterKit],
|
|
44
|
+
content: '<p>Hello world</p>',
|
|
45
|
+
onUpdate: ({ editor }) => console.log(editor.getHTML()),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
new DomternalToolbar(toolbarEl, { editor: dm.editor });
|
|
49
|
+
new DomternalBubbleMenu(bubbleEl, { editor: dm.editor });
|
|
50
|
+
|
|
51
|
+
// Reactive-friendly getters:
|
|
52
|
+
console.log(dm.htmlContent, dm.isEmpty);
|
|
53
|
+
|
|
54
|
+
// CustomEvent subscription:
|
|
55
|
+
dm.addEventListener('update', () => console.log('content changed'));
|
|
56
|
+
|
|
57
|
+
// Cleanup (idempotent):
|
|
58
|
+
dm.destroy();
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The matching mount points:
|
|
62
|
+
|
|
63
|
+
```html
|
|
64
|
+
<div id="toolbar"></div>
|
|
65
|
+
<div id="editor" class="dm-editor"></div>
|
|
66
|
+
<div id="bubble" class="dm-bubble-menu"></div>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
> Construction is browser-only: every constructor calls `assertBrowser()` and throws in
|
|
70
|
+
> SSR. Module-scope imports stay SSR-safe, so gate instantiation behind a client-side
|
|
71
|
+
> entry point (e.g. an Astro `<script>` block or `client:only`).
|
|
72
|
+
|
|
73
|
+
## Exports
|
|
74
|
+
|
|
75
|
+
- `DomternalEditor` / `DomternalEditorOptions` - wraps core's `Editor`, plus
|
|
76
|
+
`DEFAULT_EXTENSIONS` (Document, Paragraph, Text, BaseKeymap, History).
|
|
77
|
+
- `DomternalToolbar`, `DomternalBubbleMenu`, `DomternalFloatingMenu`,
|
|
78
|
+
`DomternalEmojiPicker`, `DomternalNotionColorPicker` - the floating UI components.
|
|
79
|
+
- Shared helpers: `isBrowser`, `assertBrowser`, `createPluginKey`, `renderIconInto`,
|
|
80
|
+
`resolveIcon`, `subscribe`.
|
package/dist/index.d.ts
CHANGED
|
@@ -190,6 +190,12 @@ declare const DEFAULT_EXTENSIONS: AnyExtension[];
|
|
|
190
190
|
interface DomternalEditorOptions {
|
|
191
191
|
/** Custom extensions to add. Merged on top of `DEFAULT_EXTENSIONS`. */
|
|
192
192
|
extensions?: AnyExtension[];
|
|
193
|
+
/**
|
|
194
|
+
* Whether the built-in History extension is included. Disable it when an
|
|
195
|
+
* extension brings its own undo/redo, such as collaborative editing.
|
|
196
|
+
* @default true
|
|
197
|
+
*/
|
|
198
|
+
history?: boolean;
|
|
193
199
|
/** Initial editor content (HTML string or JSON). */
|
|
194
200
|
content?: Content;
|
|
195
201
|
/** Whether the editor is editable. @default true */
|
package/dist/index.js
CHANGED
|
@@ -76,9 +76,10 @@ var DomternalEditor = class extends EventTarget {
|
|
|
76
76
|
this.#onFocus = options.onFocus;
|
|
77
77
|
this.#onBlur = options.onBlur;
|
|
78
78
|
this.#onDestroy = options.onDestroy;
|
|
79
|
+
const defaults = options.history ?? true ? DEFAULT_EXTENSIONS : DEFAULT_EXTENSIONS.filter((extension) => extension.name !== "history");
|
|
79
80
|
this.editor = new Editor({
|
|
80
81
|
element: host,
|
|
81
|
-
extensions: [...
|
|
82
|
+
extensions: [...defaults, ...options.extensions ?? []],
|
|
82
83
|
content: options.content ?? "",
|
|
83
84
|
editable: options.editable ?? true,
|
|
84
85
|
autofocus: options.autofocus ?? false
|