@toantranmei/editor 0.0.0-stage → 0.1.1
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 +363 -2
- package/dist/css-CaicG2fA.js +580 -0
- package/dist/css-CaicG2fA.js.map +1 -0
- package/dist/index.js +6481 -0
- package/dist/index.js.map +1 -0
- package/dist/nuxt.js +78 -0
- package/dist/nuxt.js.map +1 -0
- package/dist/style.css +2 -0
- package/dist/types/block-items.d.ts +38 -0
- package/dist/types/block-names.d.ts +5 -0
- package/dist/types/block-ops.d.ts +66 -0
- package/dist/types/blocks/advanced.d.ts +7 -0
- package/dist/types/blocks/basic.d.ts +10 -0
- package/dist/types/blocks/extras.d.ts +23 -0
- package/dist/types/blocks/index.d.ts +13 -0
- package/dist/types/blocks/media.d.ts +3 -0
- package/dist/types/colors.d.ts +3 -0
- package/dist/types/components/BlockMenu.vue.d.ts +16 -0
- package/dist/types/components/ColorList.vue.d.ts +37 -0
- package/dist/types/components/DatePicker.vue.d.ts +22 -0
- package/dist/types/components/EmojiMenu.vue.d.ts +13 -0
- package/dist/types/components/FormatMenu.vue.d.ts +7 -0
- package/dist/types/components/ImageCropper.vue.d.ts +25 -0
- package/dist/types/components/ImageLightbox.vue.d.ts +16 -0
- package/dist/types/components/MeiEditor.vue.d.ts +72 -0
- package/dist/types/components/MeiOutline.vue.d.ts +14 -0
- package/dist/types/components/MentionMenu.vue.d.ts +13 -0
- package/dist/types/components/MermaidDiagram.vue.d.ts +9 -0
- package/dist/types/components/SlashMenu.vue.d.ts +14 -0
- package/dist/types/components/TableControls.vue.d.ts +13 -0
- package/dist/types/composables/useClickOutside.d.ts +5 -0
- package/dist/types/composables/useEditable.d.ts +7 -0
- package/dist/types/composables/useScope.d.ts +9 -0
- package/dist/types/config.d.ts +30 -0
- package/dist/types/content.d.ts +27 -0
- package/dist/types/date-utils.d.ts +38 -0
- package/dist/types/define-block.d.ts +43 -0
- package/dist/types/emoji-data.d.ts +9 -0
- package/dist/types/extensions/block-drop.d.ts +28 -0
- package/dist/types/extensions/block-id.d.ts +21 -0
- package/dist/types/extensions/block-selection.d.ts +24 -0
- package/dist/types/extensions/callout.d.ts +12 -0
- package/dist/types/extensions/code-block.d.ts +20 -0
- package/dist/types/extensions/color-marks.d.ts +24 -0
- package/dist/types/extensions/columns.d.ts +10 -0
- package/dist/types/extensions/embed.d.ts +13 -0
- package/dist/types/extensions/emoji.d.ts +5 -0
- package/dist/types/extensions/file-block.d.ts +17 -0
- package/dist/types/extensions/html-block.d.ts +39 -0
- package/dist/types/extensions/image-block.d.ts +1 -0
- package/dist/types/extensions/index.d.ts +13 -0
- package/dist/types/extensions/math.d.ts +13 -0
- package/dist/types/extensions/mention.d.ts +43 -0
- package/dist/types/extensions/mermaid.d.ts +4 -0
- package/dist/types/extensions/slash-command.d.ts +4 -0
- package/dist/types/extensions/suggestion-renderer.d.ts +11 -0
- package/dist/types/extensions/table.d.ts +1 -0
- package/dist/types/extensions/toc.d.ts +10 -0
- package/dist/types/extensions/toggle.d.ts +6 -0
- package/dist/types/extensions/unknown.d.ts +3 -0
- package/dist/types/index.d.ts +34 -0
- package/dist/types/keys.d.ts +3 -0
- package/dist/types/lazy.d.ts +12 -0
- package/dist/types/locale.d.ts +226 -0
- package/dist/types/nodeviews/CalloutView.vue.d.ts +93 -0
- package/dist/types/nodeviews/CodeBlockView.vue.d.ts +93 -0
- package/dist/types/nodeviews/EmbedView.vue.d.ts +93 -0
- package/dist/types/nodeviews/FileView.vue.d.ts +93 -0
- package/dist/types/nodeviews/HtmlView.vue.d.ts +93 -0
- package/dist/types/nodeviews/ImageView.vue.d.ts +93 -0
- package/dist/types/nodeviews/MathView.vue.d.ts +93 -0
- package/dist/types/nodeviews/MentionView.vue.d.ts +93 -0
- package/dist/types/nodeviews/TocView.vue.d.ts +93 -0
- package/dist/types/nodeviews/renderer.d.ts +12 -0
- package/dist/types/nuxt.d.ts +36 -0
- package/dist/types/plugin-key.d.ts +7 -0
- package/dist/types/plugin.d.ts +20 -0
- package/dist/types/recent.d.ts +24 -0
- package/dist/types/slash-items.d.ts +24 -0
- package/dist/types/table-ops.d.ts +32 -0
- package/dist/types/theme/css.d.ts +20 -0
- package/dist/types/theme/define.d.ts +18 -0
- package/dist/types/theme/index.d.ts +7 -0
- package/dist/types/theme/read.d.ts +5 -0
- package/dist/types/theme/tokens.d.ts +515 -0
- package/package.json +119 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 toantranmei
|
|
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
|
@@ -1,3 +1,364 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @toantranmei/editor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Notion-style block editor for **Vue 3** and **Nuxt**, built on [Tiptap](https://tiptap.dev).
|
|
4
|
+
|
|
5
|
+
- Slash menu (`/`) with recent blocks and color commands, drag handle, block menu with search
|
|
6
|
+
- Notion-style block selection and shortcuts, drag & drop with columns and nesting
|
|
7
|
+
- Bubble menu: bold, italic, underline, strike, code, link, text/background color
|
|
8
|
+
- Markdown shortcuts: `#`, `-`, `1.`, `[]`, `>`, ` ``` `, `---`
|
|
9
|
+
- Blocks: text, headings (H1–H4), lists, to-do, quote, divider, code, image, video/embed,
|
|
10
|
+
callout, toggle, toggle headings, table, columns — plus opt-in table of contents, math (KaTeX),
|
|
11
|
+
Mermaid diagrams, emoji picker, file/audio/video uploads and @mentions
|
|
12
|
+
- Pick the blocks each app loads; heavy libraries load only when a document needs them
|
|
13
|
+
- Vietnamese and English UI, themable with CSS variables, ships its own CSS (no Tailwind needed)
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm i @toantranmei/editor
|
|
19
|
+
# or: pnpm add @toantranmei/editor / yarn add @toantranmei/editor
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Requires Vue `^3.5`. Works with any Vite-based app.
|
|
23
|
+
|
|
24
|
+
## Nuxt
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
// nuxt.config.ts
|
|
28
|
+
export default defineNuxtConfig({
|
|
29
|
+
modules: ['@toantranmei/editor/nuxt'],
|
|
30
|
+
})
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The module registers `<MeiEditor>` as a client-only component and adds the CSS.
|
|
34
|
+
|
|
35
|
+
```vue
|
|
36
|
+
<script setup lang="ts">
|
|
37
|
+
import type { JSONContent } from '@toantranmei/editor'
|
|
38
|
+
|
|
39
|
+
const doc = ref<JSONContent | null>(null)
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<template>
|
|
43
|
+
<MeiEditor v-model="doc" />
|
|
44
|
+
</template>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Module options (`meiEditor` key in `nuxt.config`):
|
|
48
|
+
|
|
49
|
+
| Option | Default | Description |
|
|
50
|
+
| --------------- | ---------------- | --------------------------------------------- |
|
|
51
|
+
| `componentName` | `'MeiEditor'` | Name of the auto-registered component |
|
|
52
|
+
| `css` | `true` | Add `@toantranmei/editor/style.css` automatically |
|
|
53
|
+
| `prebundle` | `true` | Pre-bundle Tiptap deps in Vite dev |
|
|
54
|
+
| `blocks` | – | Block names loaded app-wide (`'default'` = `defaultBlocks`) |
|
|
55
|
+
| `tokens` | – | Design token overrides for every editor |
|
|
56
|
+
|
|
57
|
+
## Vue 3 + Vite
|
|
58
|
+
|
|
59
|
+
```vue
|
|
60
|
+
<script setup lang="ts">
|
|
61
|
+
import { ref } from 'vue'
|
|
62
|
+
import { MeiEditor, type JSONContent } from '@toantranmei/editor'
|
|
63
|
+
import '@toantranmei/editor/style.css'
|
|
64
|
+
|
|
65
|
+
const doc = ref<JSONContent | null>(null)
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<template>
|
|
69
|
+
<MeiEditor v-model="doc" />
|
|
70
|
+
</template>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Or register it globally:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { createApp } from 'vue'
|
|
77
|
+
import { MeiEditorPlugin } from '@toantranmei/editor'
|
|
78
|
+
import '@toantranmei/editor/style.css'
|
|
79
|
+
|
|
80
|
+
createApp(App).use(MeiEditorPlugin).mount('#app')
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Choosing blocks
|
|
84
|
+
|
|
85
|
+
Each block is a self-contained module (extensions + menu entries + UI). The editor loads
|
|
86
|
+
`defaultBlocks` unless you pass `blocks`:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { defaultBlocks, emoji, file, html, math, mention, mermaid, toc } from '@toantranmei/editor'
|
|
90
|
+
|
|
91
|
+
const blocks = [
|
|
92
|
+
...defaultBlocks,
|
|
93
|
+
toc,
|
|
94
|
+
emoji,
|
|
95
|
+
math, // needs `npm i katex` + import 'katex/dist/katex.min.css'
|
|
96
|
+
mermaid, // needs `npm i mermaid`
|
|
97
|
+
html, // sandboxed HTML/CSS/JS; html.configure({ network: ['https://cdn.jsdelivr.net'] })
|
|
98
|
+
file.configure({ upload: async (f, kind) => uploadToS3(f), maxSize: 20 }),
|
|
99
|
+
mention.configure({
|
|
100
|
+
search: q => api.searchPeopleAndPages(q), // → [{ id, label, kind: 'user' | 'page', avatar?, href? }]
|
|
101
|
+
onClick: item => router.push(`/u/${item.id}`),
|
|
102
|
+
}),
|
|
103
|
+
]
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
```vue
|
|
107
|
+
<MeiEditor v-model="doc" :blocks="blocks" />
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
App-wide: `app.use(MeiEditorPlugin, { blocks })`, or in Nuxt `meiEditor: { blocks: ['default', 'toc', 'math'] }`
|
|
111
|
+
(only the listed blocks are imported; the module also adds KaTeX's CSS for `math`).
|
|
112
|
+
|
|
113
|
+
| Block | In `defaultBlocks` | Notes |
|
|
114
|
+
| --- | --- | --- |
|
|
115
|
+
| `heading` (H1–H4), `bulletList`, `orderedList`, `taskList`, `quote`, `divider` | ✓ | `heading.configure({ levels: [1, 2, 3] })` |
|
|
116
|
+
| `codeBlock` | ✓ | Grammars load per language on first use |
|
|
117
|
+
| `image`, `embed` | ✓ | Upload via the `uploadImage` prop. Images have a Notion-style hover toolbar: align, caption, non-destructive crop, full-screen zoom (wheel/+/−/drag), download, replace / copy link / view original / delete |
|
|
118
|
+
| `callout`, `toggle`, `toggleHeading`, `table`, `columns` | ✓ | |
|
|
119
|
+
| `toc` | – | Table of contents from headings |
|
|
120
|
+
| `math` | – | Optional peer `katex` |
|
|
121
|
+
| `mermaid` | – | Optional peer `mermaid`; code blocks in `mermaid` show a live diagram |
|
|
122
|
+
| `html` | – | Notion-style HTML block: HTML/CSS/JS in a sandboxed iframe (no access to the page, cookies or storage). Edit in place (Code / Preview) or upload an `.html` file; fixed height (drag to resize), "Interact" to use it, full-screen view. `network`: `false` (default, blocks all requests like Notion), `true`, or a list of allowed origins; `maxSize` (KB), `defaultHeight` (px) |
|
|
123
|
+
| `emoji` | – | Type `:` + 2 letters; data loads on first use (vi/en search) |
|
|
124
|
+
| `file` | – | File, audio, video; `upload`, `maxSize` (MB, base64 when no `upload`) |
|
|
125
|
+
| `mention` | – | `@` people/pages via `search`; dates (today, 25/12…) built in. Click a date for a Notion-style picker (typed date/time, end date, date & time formats, reminders, clear); click a person/page to search and switch (read-only: `onClick` / page link). Reminders: `onRemind`, `getMentionReminders(doc)`, `reminderHelpUrl` |
|
|
126
|
+
|
|
127
|
+
### Custom blocks
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import { defineBlock } from '@toantranmei/editor'
|
|
131
|
+
import { Receipt } from '@lucide/vue'
|
|
132
|
+
|
|
133
|
+
export const invoice = defineBlock({
|
|
134
|
+
name: 'invoice',
|
|
135
|
+
nodes: ['invoice'],
|
|
136
|
+
extensions: () => [InvoiceNode], // your Tiptap node
|
|
137
|
+
items: () => [{ id: 'invoice', icon: Receipt, group: 'advanced', keywords: ['bill'], insert: c => c.insertInvoice() }],
|
|
138
|
+
messages: { vi: { blocks: { invoice: { title: 'Hoá đơn', description: 'Chèn hoá đơn' } } } },
|
|
139
|
+
})
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Documents with blocks that aren't loaded
|
|
143
|
+
|
|
144
|
+
Content using a block type this editor doesn't load (e.g. a doc written where `math` was enabled)
|
|
145
|
+
is kept intact: it shows as an "unsupported block" placeholder that can be moved or deleted, and
|
|
146
|
+
the original JSON comes back unchanged in `v-model`. (Unknown *marks* are dropped.)
|
|
147
|
+
|
|
148
|
+
## Props
|
|
149
|
+
|
|
150
|
+
| Prop | Type | Default | Description |
|
|
151
|
+
| -------------- | --------------------------------- | ------- | -------------------------------------------------------- |
|
|
152
|
+
| `modelValue` | `JSONContent \| null` | `null` | Document as Tiptap JSON (`v-model`) |
|
|
153
|
+
| `editable` | `boolean` | `true` | Read-only when `false` |
|
|
154
|
+
| `autofocus` | `boolean \| 'start' \| 'end'` | `false` | Focus on mount |
|
|
155
|
+
| `locale` | `'vi' \| 'en'` | `'vi'` | UI language |
|
|
156
|
+
| `messages` | `PartialMessages` | – | Override any UI string |
|
|
157
|
+
| `blocks` | `BlockDefinition[]` | `defaultBlocks` | Blocks to load (read at mount), see "Choosing blocks" |
|
|
158
|
+
| `uploadImage` | `(file: File) => Promise<string>` | – | Upload an image and return its URL (default: base64) |
|
|
159
|
+
| `maxImageSize` | `number` | `5` | Max image size in MB |
|
|
160
|
+
| `extensions` | `AnyExtension[]` | – | Extra Tiptap extensions |
|
|
161
|
+
| `theme` | `'auto' \| 'light' \| 'dark'` | `'auto'`| Color mode; `auto` follows `<html class="dark">` |
|
|
162
|
+
| `tokens` | `ThemeTokens` | – | Design token overrides for this editor (see Theming) |
|
|
163
|
+
| `blockLink` | `(id: string) => string` | – | URL for "Copy link to block" (default: page URL + `#id`) |
|
|
164
|
+
| `outline` | `boolean \| { minHeadings }` | `true` | Floating outline on the right (shown from 2 headings) |
|
|
165
|
+
|
|
166
|
+
Events: `update:modelValue`, `ready(editor)`, `content-error({ fatal, issues, error })`. The Tiptap editor is also exposed via a template ref (`ref.editor`).
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
## Keyboard & mouse
|
|
170
|
+
|
|
171
|
+
| Action | Shortcut |
|
|
172
|
+
| --- | --- |
|
|
173
|
+
| Select the current block / clear the selection | `Esc` |
|
|
174
|
+
| Select several blocks | `Shift`+click, or drag a text selection across blocks |
|
|
175
|
+
| Move / extend the block selection | `↑` `↓` / `Shift`+`↑` `↓` |
|
|
176
|
+
| Delete selected blocks | `Backspace` / `Delete` |
|
|
177
|
+
| Edit the selected block | `Enter` |
|
|
178
|
+
| Move block(s) up / down | `⌘⇧↑` / `⌘⇧↓` |
|
|
179
|
+
| Duplicate | `⌘D` |
|
|
180
|
+
| Turn into: text, H1–H3, to-do, bullet, numbered, toggle, code | `⌘⌥0` … `⌘⌥8` |
|
|
181
|
+
| Open the block menu | `⌘/` or click `⋮⋮` |
|
|
182
|
+
|
|
183
|
+
`Ctrl` replaces `⌘` on Windows/Linux. The block menu has a search box (actions, block types and
|
|
184
|
+
colors) and full keyboard navigation (`↑` `↓` `Enter`, `→` opens a submenu, `←`/`Esc` goes back).
|
|
185
|
+
|
|
186
|
+
Drag `⋮⋮` to move blocks. Drop **on the right edge** of a block to place them side by side in
|
|
187
|
+
columns (or on the left edge after a clear sideways move); dropping the last block out of a column
|
|
188
|
+
removes it. Drop **with an indent** below a list, toggle or callout to nest inside it. The page
|
|
189
|
+
auto-scrolls near the edges.
|
|
190
|
+
|
|
191
|
+
**Floating outline:** short bars fixed to the viewport's right edge mirror the page's headings (the
|
|
192
|
+
one in view is darker). It stays above full-width content and hides while the editor is off
|
|
193
|
+
screen. Hover for the full outline, click to jump. Tune with the `outline.*` tokens (`right`,
|
|
194
|
+
`top`…) and `heading.scrollMargin` (room for a sticky app header); hidden below 768px wide.
|
|
195
|
+
|
|
196
|
+
**Tables:** cells hold text only (like Notion's simple tables; no `/` menu inside cells). Hover a
|
|
197
|
+
table for row/column grips (insert, duplicate, move, clear, background color,
|
|
198
|
+
delete; header row/column on the first row/column) and "+" bars to add rows and columns.
|
|
199
|
+
Select several cells to merge, split, color or clear them. Columns resize by dragging borders.
|
|
200
|
+
|
|
201
|
+
Blocks get a stable `id` attribute, used by "Copy link to block"; opening a link with `#<id>`
|
|
202
|
+
scrolls to and selects that block.
|
|
203
|
+
|
|
204
|
+
### Image upload
|
|
205
|
+
|
|
206
|
+
```vue
|
|
207
|
+
<MeiEditor v-model="doc" :upload-image="upload" />
|
|
208
|
+
|
|
209
|
+
<script setup lang="ts">
|
|
210
|
+
async function upload(file: File) {
|
|
211
|
+
const body = new FormData()
|
|
212
|
+
body.append('file', file)
|
|
213
|
+
const res = await fetch('/api/upload', { method: 'POST', body })
|
|
214
|
+
return (await res.json()).url
|
|
215
|
+
}
|
|
216
|
+
</script>
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Safe loading
|
|
220
|
+
|
|
221
|
+
Invalid content never blanks the editor (Tiptap's default, which the next save would persist):
|
|
222
|
+
|
|
223
|
+
- Blocks with fixable problems (e.g. empty text nodes) are repaired.
|
|
224
|
+
- Broken blocks are kept verbatim as an "invalid block" placeholder; their JSON comes back
|
|
225
|
+
unchanged in `v-model`. Typing while one is selected adds text below instead of replacing it.
|
|
226
|
+
- Input that isn't a document at all makes the editor read-only, shows a notice and stops
|
|
227
|
+
emitting `update:modelValue`, so saved data isn't overwritten.
|
|
228
|
+
|
|
229
|
+
Every case emits `content-error` so the app can log or report it.
|
|
230
|
+
|
|
231
|
+
## Performance
|
|
232
|
+
|
|
233
|
+
Measured on a production build (Chrome, Apple Silicon), mixed content with lists, code,
|
|
234
|
+
callouts and tables. Key latency includes two animation frames (~33ms floor).
|
|
235
|
+
|
|
236
|
+
| Blocks | Open | Typing (p50) |
|
|
237
|
+
| --- | --- | --- |
|
|
238
|
+
| 1,000 | ~0.1 s | 33 ms |
|
|
239
|
+
| 5,000 | ~0.3 s | 33 ms |
|
|
240
|
+
| 10,000 | ~0.5 s | ~44 ms |
|
|
241
|
+
| 20,000 | ~1 s | ~98 ms |
|
|
242
|
+
|
|
243
|
+
Up to ~10k blocks per page the editor stays smooth. For larger content, split it into
|
|
244
|
+
sub-pages (Notion's approach): keep each document small and link pages together, e.g. with
|
|
245
|
+
`mention` page links or your own "page" block. Run `pnpm bench` in the repo to measure.
|
|
246
|
+
|
|
247
|
+
## Theming
|
|
248
|
+
|
|
249
|
+
All visual values live in **one design-token file** (`src/theme/tokens.ts`) and are exposed as
|
|
250
|
+
CSS variables (`--me-*`). Stylesheets only reference tokens, so changing a token restyles
|
|
251
|
+
every place that uses it.
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
primitive → raw values --me-gray-800, --me-azure-500, --me-space-4, --me-rounded-md
|
|
255
|
+
semantic → meaning (light/dark) --me-color-text, --me-color-accent, --me-radius-md, --me-palette-red-text
|
|
256
|
+
component → per-part knobs --me-menu-item-radius, --me-box-padding, --me-block-box-spacing
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
Usually you only override **semantic** tokens; reach for **component** tokens to fine-tune one part.
|
|
260
|
+
|
|
261
|
+
### Light / dark mode
|
|
262
|
+
|
|
263
|
+
`theme="auto"` (default) follows `<html class="dark">`, the convention used by Tailwind and
|
|
264
|
+
`@nuxtjs/color-mode`. Force a mode per editor with `theme="light"` or `theme="dark"`.
|
|
265
|
+
|
|
266
|
+
### Override tokens (typed, with autocomplete)
|
|
267
|
+
|
|
268
|
+
```ts
|
|
269
|
+
import { defineTokens } from '@toantranmei/editor'
|
|
270
|
+
|
|
271
|
+
const tokens = defineTokens({
|
|
272
|
+
color: { accent: '#7c3aed' }, // both modes
|
|
273
|
+
radius: { md: '10px' },
|
|
274
|
+
font: { sans: 'Inter, sans-serif' },
|
|
275
|
+
components: { menu: { itemRadius: '8px' }, box: { padding: '16px 20px' } },
|
|
276
|
+
dark: { color: { accent: '#a78bfa' } }, // dark mode only
|
|
277
|
+
})
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Apply them at the level you need:
|
|
281
|
+
|
|
282
|
+
```vue
|
|
283
|
+
<!-- one editor -->
|
|
284
|
+
<MeiEditor v-model="doc" :tokens="tokens" />
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
```ts
|
|
288
|
+
// every editor in a Nuxt app (compiled to a static stylesheet)
|
|
289
|
+
export default defineNuxtConfig({
|
|
290
|
+
modules: ['@toantranmei/editor/nuxt'],
|
|
291
|
+
meiEditor: { tokens: { color: { accent: '#7c3aed' } } },
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
// every editor in a Vue app
|
|
295
|
+
app.use(MeiEditorPlugin, { tokens: { color: { accent: '#7c3aed' } } })
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Or with plain CSS, e.g. to map the editor onto your design system's variables:
|
|
299
|
+
|
|
300
|
+
```css
|
|
301
|
+
.me-scope {
|
|
302
|
+
--me-color-accent: var(--ui-primary);
|
|
303
|
+
--me-font-sans: var(--font-sans);
|
|
304
|
+
--me-radius-md: var(--radius);
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Overriding styles directly
|
|
309
|
+
|
|
310
|
+
Library CSS sits in the `mei-editor` cascade layer, declared as
|
|
311
|
+
`@layer theme, base, mei-editor, components, utilities;`. Resets in `base` (such as Tailwind's
|
|
312
|
+
preflight) don't affect the editor, while your own CSS — unlayered, or in `components` /
|
|
313
|
+
`utilities` — overrides it without `!important`. Every part has a stable `me-*` class
|
|
314
|
+
(`.me-menu-item`, `.me-callout`, `.me-code-block`, …).
|
|
315
|
+
|
|
316
|
+
### Match a shadcn/ui + Tailwind app
|
|
317
|
+
|
|
318
|
+
Point the editor's semantic tokens at shadcn's CSS variables, and it follows the app's theme,
|
|
319
|
+
including dark mode (both use `.dark` on `<html>`). In shadcn, `accent` is the subtle hover
|
|
320
|
+
background and `primary` is the brand color, so map them that way round:
|
|
321
|
+
|
|
322
|
+
```ts
|
|
323
|
+
import { defineTokens } from '@toantranmei/editor'
|
|
324
|
+
|
|
325
|
+
// Tailwind v4 / shadcn v4 variables are full colors. On Tailwind v3 (HSL triplets) use 'hsl(var(--primary))'.
|
|
326
|
+
export const tokens = defineTokens({
|
|
327
|
+
color: {
|
|
328
|
+
text: 'var(--foreground)',
|
|
329
|
+
textMuted: 'var(--muted-foreground)',
|
|
330
|
+
bg: 'var(--background)',
|
|
331
|
+
elevated: 'var(--popover)',
|
|
332
|
+
surface: 'var(--muted)',
|
|
333
|
+
hover: 'var(--accent)',
|
|
334
|
+
border: 'var(--border)',
|
|
335
|
+
accent: 'var(--primary)',
|
|
336
|
+
onAccent: 'var(--primary-foreground)',
|
|
337
|
+
danger: 'var(--destructive)',
|
|
338
|
+
},
|
|
339
|
+
radius: { sm: 'calc(var(--radius) - 4px)', md: 'calc(var(--radius) - 2px)', lg: 'var(--radius)' },
|
|
340
|
+
font: { sans: 'var(--font-sans)', mono: 'var(--font-mono)' },
|
|
341
|
+
components: { input: { focusRing: 'var(--ring)' } },
|
|
342
|
+
})
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
Tailwind v4 works out of the box (its preflight lives in the `base` layer). Tailwind v3 emits its
|
|
346
|
+
preflight outside any cascade layer, which beats layered CSS, so it can reset editor buttons,
|
|
347
|
+
lists and headings.
|
|
348
|
+
|
|
349
|
+
### Colors in documents
|
|
350
|
+
|
|
351
|
+
Text, highlight and callout colors are stored **by name** (`data-text-color="red"`), not as hex,
|
|
352
|
+
so documents follow your theme and dark mode. Change the palette with
|
|
353
|
+
`palette: { red: { text: '…', bg: '…' } }`.
|
|
354
|
+
|
|
355
|
+
## Advanced
|
|
356
|
+
|
|
357
|
+
Everything is exported for building your own UI on the same blocks:
|
|
358
|
+
`createExtensions`, `BLOCKS`, `filterBlocks`, `turnBlockInto`, the custom extensions
|
|
359
|
+
(`Callout`, `Columns`, `ImageBlock`, `Embed`, `CodeBlock`, `SlashCommand`, `BlockDrop`, `TextColor`, `BgColor`),
|
|
360
|
+
the token objects (`primitiveTokens`, `semanticLightTokens`, `semanticDarkTokens`, `componentTokens`) and locales (`vi`, `en`).
|
|
361
|
+
|
|
362
|
+
## License
|
|
363
|
+
|
|
364
|
+
MIT
|