alien-editor 0.1.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/README.md +249 -0
- package/dist/alien-editor.js +2103 -0
- package/dist/alien-editor.umd.cjs +2 -0
- package/dist/index.d.ts +8 -0
- package/dist/nuxt.cjs +1 -0
- package/dist/nuxt.js +17 -0
- package/dist/src/components/AlienEditor.vue.d.ts +20 -0
- package/dist/src/components/blocks/BlockList.vue.d.ts +2 -0
- package/dist/src/components/blocks/BlockWrapper.vue.d.ts +21 -0
- package/dist/src/components/blocks/ButtonBlock.vue.d.ts +6 -0
- package/dist/src/components/blocks/CodeBlock.vue.d.ts +6 -0
- package/dist/src/components/blocks/DividerBlock.vue.d.ts +6 -0
- package/dist/src/components/blocks/HeadingBlock.vue.d.ts +8 -0
- package/dist/src/components/blocks/ImageBlock.vue.d.ts +8 -0
- package/dist/src/components/blocks/ListBlock.vue.d.ts +6 -0
- package/dist/src/components/blocks/ModuleBlock.vue.d.ts +8 -0
- package/dist/src/components/blocks/TextBlock.vue.d.ts +8 -0
- package/dist/src/components/blocks/VideoBlock.vue.d.ts +6 -0
- package/dist/src/components/modals/ImageUrlModal.vue.d.ts +2 -0
- package/dist/src/components/modals/LinkModal.vue.d.ts +2 -0
- package/dist/src/components/toolbar/AlienToolbar.vue.d.ts +2 -0
- package/dist/src/components/toolbar/ColorPicker.vue.d.ts +2 -0
- package/dist/src/components/toolbar/ModeToggle.vue.d.ts +2 -0
- package/dist/src/components/toolbar/ModuleDropdown.vue.d.ts +2 -0
- package/dist/src/components/toolbar/ToolbarButton.vue.d.ts +26 -0
- package/dist/src/composables/useBlocks.d.ts +13 -0
- package/dist/src/composables/useDragDrop.d.ts +16 -0
- package/dist/src/composables/useEditorState.d.ts +191 -0
- package/dist/src/composables/useFormatting.d.ts +14 -0
- package/dist/src/composables/useHistory.d.ts +9 -0
- package/dist/src/composables/useParser.d.ts +4 -0
- package/dist/src/composables/useSelection.d.ts +8 -0
- package/dist/src/composables/useSerializer.d.ts +7 -0
- package/dist/src/types/index.d.ts +116 -0
- package/dist/src/utils/tailwindMap.d.ts +12 -0
- package/dist/style.css +1 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# alien-editor
|
|
2
|
+
|
|
3
|
+
A Vue 3 block-based rich text editor with native Tailwind CSS integration. No heavy dependencies — built entirely on `contenteditable` and the browser's Selection/Range APIs.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Block-based editing** — paragraphs, headings (H1–H6), images, videos, code blocks, dividers, buttons, blockquotes, ordered/unordered lists
|
|
8
|
+
- **Rich text formatting** — bold, italic, underline, strikethrough, font size, font weight, text alignment, links
|
|
9
|
+
- **Tailwind CSS** — all styles are applied as Tailwind utility classes in the HTML output
|
|
10
|
+
- **Custom colors** — searchable color picker driven by a prop
|
|
11
|
+
- **Module injection** — insert custom HTML blocks from a searchable dropdown
|
|
12
|
+
- **Media upload** — file input + URL paste for images; emits `@upload` for parent handling
|
|
13
|
+
- **Drag & drop** — reorder blocks with native HTML5 drag-and-drop
|
|
14
|
+
- **Undo / Redo** — full history with Ctrl+Z / Ctrl+Y
|
|
15
|
+
- **Three view modes** — Edit, Code (raw HTML), Preview (rendered output)
|
|
16
|
+
- **v-model support** — emits raw HTML string on every change
|
|
17
|
+
- **Nuxt 3 compatible** — SSR-safe, ships a Nuxt module
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install alien-editor
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Usage — Vue 3
|
|
30
|
+
|
|
31
|
+
### Global registration (recommended)
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
// main.js / main.ts
|
|
35
|
+
import { createApp } from 'vue'
|
|
36
|
+
import AlienEditorPlugin from 'alien-editor'
|
|
37
|
+
import 'alien-editor/dist/style.css'
|
|
38
|
+
import App from './App.vue'
|
|
39
|
+
|
|
40
|
+
const app = createApp(App)
|
|
41
|
+
app.use(AlienEditorPlugin)
|
|
42
|
+
app.mount('#app')
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Per-component import
|
|
46
|
+
|
|
47
|
+
```vue
|
|
48
|
+
<script setup lang="ts">
|
|
49
|
+
import { ref } from 'vue'
|
|
50
|
+
import { AlienEditor } from 'alien-editor'
|
|
51
|
+
import 'alien-editor/dist/style.css'
|
|
52
|
+
|
|
53
|
+
const html = ref('<p>Hello world!</p>')
|
|
54
|
+
|
|
55
|
+
const colors = [
|
|
56
|
+
{ title: 'Rose', key: 'rose', class: 'text-rose-500' },
|
|
57
|
+
{ title: 'Blue', key: 'blue', class: 'text-blue-600' },
|
|
58
|
+
{ title: 'Green', key: 'green', class: 'text-green-600' },
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
const modules = [
|
|
62
|
+
{
|
|
63
|
+
title: 'Call to Action',
|
|
64
|
+
key: 'cta',
|
|
65
|
+
module: '<div class="bg-blue-600 text-white p-6 rounded-xl text-center"><h2 class="text-2xl font-bold">Get Started</h2><p>Sign up today.</p></div>',
|
|
66
|
+
},
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
function handleUpload(file: File) {
|
|
70
|
+
// Upload the file to your server, then update v-model with the returned URL
|
|
71
|
+
console.log('File selected:', file.name)
|
|
72
|
+
}
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<template>
|
|
76
|
+
<AlienEditor
|
|
77
|
+
v-model="html"
|
|
78
|
+
placeholder="Start writing..."
|
|
79
|
+
:colors="colors"
|
|
80
|
+
:modules="modules"
|
|
81
|
+
@upload="handleUpload"
|
|
82
|
+
/>
|
|
83
|
+
</template>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Usage — Nuxt 3
|
|
89
|
+
|
|
90
|
+
Add the module to `nuxt.config.ts`:
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
// nuxt.config.ts
|
|
94
|
+
export default defineNuxtConfig({
|
|
95
|
+
modules: ['alien-editor/nuxt'],
|
|
96
|
+
css: ['alien-editor/dist/style.css'],
|
|
97
|
+
})
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Then use the component anywhere — it's auto-imported:
|
|
101
|
+
|
|
102
|
+
```vue
|
|
103
|
+
<script setup lang="ts">
|
|
104
|
+
const html = ref('')
|
|
105
|
+
|
|
106
|
+
function handleUpload(file: File) {
|
|
107
|
+
// Upload to your storage, get URL, then set it via v-model
|
|
108
|
+
}
|
|
109
|
+
</script>
|
|
110
|
+
|
|
111
|
+
<template>
|
|
112
|
+
<AlienEditor
|
|
113
|
+
v-model="html"
|
|
114
|
+
placeholder="Write something..."
|
|
115
|
+
@upload="handleUpload"
|
|
116
|
+
/>
|
|
117
|
+
</template>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Props
|
|
123
|
+
|
|
124
|
+
| Prop | Type | Default | Description |
|
|
125
|
+
|------|------|---------|-------------|
|
|
126
|
+
| `modelValue` | `string` | `''` | The HTML content of the editor. Supports `v-model`. |
|
|
127
|
+
| `placeholder` | `string` | `'Start writing...'` | Placeholder text shown in empty blocks. |
|
|
128
|
+
| `colors` | `ColorOption[]` | `[]` | Custom color options for the text color picker. When empty, the picker is hidden. |
|
|
129
|
+
| `modules` | `ModuleOption[]` | `[]` | Custom HTML blocks for the module inserter dropdown. When empty, the dropdown is hidden. |
|
|
130
|
+
|
|
131
|
+
### `ColorOption`
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
interface ColorOption {
|
|
135
|
+
title: string // Display name, e.g. "Rose Red"
|
|
136
|
+
key: string // Short identifier, e.g. "rose"
|
|
137
|
+
class: string // Tailwind class, e.g. "text-rose-500"
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### `ModuleOption`
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
interface ModuleOption {
|
|
145
|
+
title: string // Display name, e.g. "Call to Action"
|
|
146
|
+
key: string // Short identifier, e.g. "cta"
|
|
147
|
+
module: string // Raw HTML string to inject as a block
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Events
|
|
154
|
+
|
|
155
|
+
| Event | Payload | Description |
|
|
156
|
+
|-------|---------|-------------|
|
|
157
|
+
| `update:modelValue` | `string` | Emitted on every content change with the full HTML output. Used by `v-model`. |
|
|
158
|
+
| `upload` | `File` | Emitted when the user selects an image file. The parent is responsible for uploading and providing a URL back via `v-model`. |
|
|
159
|
+
|
|
160
|
+
### Handling `@upload`
|
|
161
|
+
|
|
162
|
+
```vue
|
|
163
|
+
<script setup lang="ts">
|
|
164
|
+
const html = ref('')
|
|
165
|
+
|
|
166
|
+
async function handleUpload(file: File) {
|
|
167
|
+
const formData = new FormData()
|
|
168
|
+
formData.append('file', file)
|
|
169
|
+
|
|
170
|
+
const res = await fetch('/api/upload', { method: 'POST', body: formData })
|
|
171
|
+
const { url } = await res.json()
|
|
172
|
+
|
|
173
|
+
// Replace the temporary local blob URL with the real URL
|
|
174
|
+
html.value = html.value.replace(/blob:[^"]+/, url)
|
|
175
|
+
}
|
|
176
|
+
</script>
|
|
177
|
+
|
|
178
|
+
<template>
|
|
179
|
+
<AlienEditor v-model="html" @upload="handleUpload" />
|
|
180
|
+
</template>
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Tailwind CSS Setup
|
|
186
|
+
|
|
187
|
+
`alien-editor` writes Tailwind utility classes directly into the HTML output. Because Tailwind purges unused classes by default, you must include the package in your `tailwind.config.js` `content` array so that class names like `font-bold`, `text-center`, `text-rose-500` etc. are preserved:
|
|
188
|
+
|
|
189
|
+
```js
|
|
190
|
+
// tailwind.config.js
|
|
191
|
+
module.exports = {
|
|
192
|
+
content: [
|
|
193
|
+
'./src/**/*.{vue,js,ts}',
|
|
194
|
+
'./node_modules/alien-editor/dist/**/*.js', // ← add this
|
|
195
|
+
],
|
|
196
|
+
// ...
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Or use `safelist` if you need specific dynamic classes:
|
|
201
|
+
|
|
202
|
+
```js
|
|
203
|
+
module.exports = {
|
|
204
|
+
content: ['./src/**/*.{vue,js,ts}'],
|
|
205
|
+
safelist: [
|
|
206
|
+
// Alignment classes (dynamically assembled)
|
|
207
|
+
'text-left', 'text-center', 'text-right', 'text-justify',
|
|
208
|
+
// Font size classes
|
|
209
|
+
{ pattern: /^text-(xs|sm|base|lg|xl|2xl|3xl|4xl|5xl)$/ },
|
|
210
|
+
// Font weight classes
|
|
211
|
+
{ pattern: /^font-(thin|light|normal|medium|semibold|bold|extrabold|black)$/ },
|
|
212
|
+
// Your custom color classes
|
|
213
|
+
'text-rose-500', 'text-blue-600', 'text-green-600',
|
|
214
|
+
],
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## Keyboard Shortcuts
|
|
221
|
+
|
|
222
|
+
| Shortcut | Action |
|
|
223
|
+
|----------|--------|
|
|
224
|
+
| `Ctrl+Z` / `Cmd+Z` | Undo |
|
|
225
|
+
| `Ctrl+Y` / `Cmd+Y` or `Ctrl+Shift+Z` | Redo |
|
|
226
|
+
| `Enter` in a text block | Create new paragraph below |
|
|
227
|
+
| `Backspace` on empty block | Delete block, focus previous |
|
|
228
|
+
| `Enter` in a list item | Add new list item |
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## Building from Source
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
cd alien-editor
|
|
236
|
+
npm install
|
|
237
|
+
npm run build
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Output is placed in `dist/`:
|
|
241
|
+
- `dist/alien-editor.js` — ESM bundle
|
|
242
|
+
- `dist/alien-editor.umd.cjs` — UMD bundle
|
|
243
|
+
- `dist/style.css` — component styles
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## License
|
|
248
|
+
|
|
249
|
+
MIT
|