aden-editor-vue 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +187 -2
- package/dist/index.cjs +94 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +7 -0
- package/dist/types/index.d.ts +77 -0
- package/package.json +38 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AdenEditor 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
|
@@ -1,3 +1,188 @@
|
|
|
1
|
-
#
|
|
1
|
+
# aden-editor-vue
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Vue 3 富文本编辑器组件,安装后即可使用。** 提供常用格式工具栏、图片/视频/附件、表格、公式、待办、撤销重做、字数统计和粘贴清洗。支持 `v-model`,并能通过配置连接你自己的上传与提及查询接口。
|
|
4
|
+
|
|
5
|
+
- Vue 3 项目专用的独立集成包
|
|
6
|
+
- 开箱即用的编辑器和内置工具栏
|
|
7
|
+
- 支持 TypeScript,暴露读取和设置内容的方法
|
|
8
|
+
- 上传地址、鉴权和服务端返回格式由业务项目自行控制
|
|
9
|
+
|
|
10
|
+
## 安装
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install aden-editor-vue
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
要求 Vue `3.3` 或更高版本。如果当前项目还没有安装 Vue:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install vue aden-editor-vue
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
安装本包会自动安装编辑器内核 `aden-editor`。React 项目请使用独立的 React 集成包(发布后提供),不要在 React 项目中安装本包。
|
|
23
|
+
|
|
24
|
+
## 最快开始
|
|
25
|
+
|
|
26
|
+
在 Vue 页面中直接使用组件:
|
|
27
|
+
|
|
28
|
+
```vue
|
|
29
|
+
<script setup lang="ts">
|
|
30
|
+
import { ref } from 'vue';
|
|
31
|
+
import { AdenEditor } from 'aden-editor-vue';
|
|
32
|
+
|
|
33
|
+
const content = ref('<p>欢迎使用 AdenEditor</p>');
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<template>
|
|
37
|
+
<AdenEditor v-model="content" />
|
|
38
|
+
<pre>{{ content }}</pre>
|
|
39
|
+
</template>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
默认工具栏和样式会自动加载。未传 `options` 时,文字编辑、列表、引用、表格等内置功能仍可直接使用;无需单独导入 CSS,也无需自己处理创建、挂载和卸载。
|
|
43
|
+
|
|
44
|
+
## 保存内容
|
|
45
|
+
|
|
46
|
+
`v-model` 的值是 HTML,适合接入常见的 HTML 内容字段。若需保存完整编辑器文档结构,可通过组件 `ref` 获取 JSON:
|
|
47
|
+
|
|
48
|
+
```vue
|
|
49
|
+
<script setup lang="ts">
|
|
50
|
+
import { ref } from 'vue';
|
|
51
|
+
import { AdenEditor } from 'aden-editor-vue';
|
|
52
|
+
import type { AdenEditorExpose } from 'aden-editor-vue';
|
|
53
|
+
|
|
54
|
+
const content = ref('<p>编辑内容</p>');
|
|
55
|
+
const editor = ref<AdenEditorExpose | null>(null);
|
|
56
|
+
|
|
57
|
+
async function save() {
|
|
58
|
+
const html = editor.value?.getHtml();
|
|
59
|
+
const doc = editor.value?.getJSON();
|
|
60
|
+
await fetch('/api/articles/123', {
|
|
61
|
+
method: 'PUT',
|
|
62
|
+
headers: { 'Content-Type': 'application/json' },
|
|
63
|
+
body: JSON.stringify({ html, doc }),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<template>
|
|
69
|
+
<AdenEditor ref="editor" v-model="content" />
|
|
70
|
+
<button type="button" @click="save">保存</button>
|
|
71
|
+
</template>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
组件 ref 提供:`getHtml()`、`setHtml(html)`、`getJSON()`、`setJSON(doc)`、`getMarkdown()`、`getText()`、`focus()` 和 `clear()`。
|
|
75
|
+
|
|
76
|
+
## 工具栏配置
|
|
77
|
+
|
|
78
|
+
可通过 `options.toolbarItems` 自选工具和排列顺序。每个内层数组代表一行:
|
|
79
|
+
|
|
80
|
+
```vue
|
|
81
|
+
<script setup lang="ts">
|
|
82
|
+
import { ref } from 'vue';
|
|
83
|
+
import { AdenEditor } from 'aden-editor-vue';
|
|
84
|
+
import type { AdenEditorOptions } from 'aden-editor-vue';
|
|
85
|
+
|
|
86
|
+
const content = ref('');
|
|
87
|
+
const options: AdenEditorOptions = {
|
|
88
|
+
placeholder: '写点什么…',
|
|
89
|
+
toolbarItems: [
|
|
90
|
+
['undo', 'redo', '|', 'heading', 'bold', 'italic', 'underline', 'link'],
|
|
91
|
+
['ul', 'ol', 'quote', 'codeblock', 'image', 'table', 'stat'],
|
|
92
|
+
],
|
|
93
|
+
};
|
|
94
|
+
</script>
|
|
95
|
+
|
|
96
|
+
<template>
|
|
97
|
+
<AdenEditor v-model="content" :options="options" />
|
|
98
|
+
</template>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
不设置 `toolbarItems` 使用完整默认工具栏;设 `options.toolbar = false` 可隐藏内置工具栏。工具栏项 ID 包括 `bold`、`heading`、`fontSize`、`color`、`ul`、`quote`、`image`、`video`、`attachment`、`table`、`formula`、`fullscreen` 等。可从 `BuiltinToolbarItemId` 获得完整 TypeScript 类型。
|
|
102
|
+
|
|
103
|
+
## 接入自己的上传接口
|
|
104
|
+
|
|
105
|
+
上传回调接收浏览器 `File`,需返回文件可访问的 URL。接口路径、登录态、鉴权头和返回 JSON 结构都在业务代码中处理:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
const options: AdenEditorOptions = {
|
|
109
|
+
uploadImage: async (file) => {
|
|
110
|
+
const form = new FormData();
|
|
111
|
+
form.append('file', file);
|
|
112
|
+
|
|
113
|
+
const response = await fetch('/api/upload/image', {
|
|
114
|
+
method: 'POST',
|
|
115
|
+
headers: { Authorization: `Bearer ${getToken()}` },
|
|
116
|
+
body: form,
|
|
117
|
+
});
|
|
118
|
+
if (!response.ok) throw new Error(`图片上传失败:${response.status}`);
|
|
119
|
+
|
|
120
|
+
const result = await response.json() as { url: string };
|
|
121
|
+
return result.url;
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
视频和附件可分别配置 `uploadVideo`、`uploadAttachment`。不配置上传回调时,编辑器不会猜测或请求你的业务接口。
|
|
127
|
+
|
|
128
|
+
## 内容变化与自动保存
|
|
129
|
+
|
|
130
|
+
组件的 `change` 事件会给出最新 JSON 和 HTML。适合在这里做防抖后自动保存:
|
|
131
|
+
|
|
132
|
+
```vue
|
|
133
|
+
<AdenEditor
|
|
134
|
+
v-model="content"
|
|
135
|
+
:options="options"
|
|
136
|
+
@change="({ doc, html }) => scheduleSave({ doc, html })"
|
|
137
|
+
/>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## 提及、只读与字数限制
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
const options: AdenEditorOptions = {
|
|
144
|
+
maxLength: 5000,
|
|
145
|
+
onMaxLength: (length, max) => console.info(`当前 ${length}/${max}`),
|
|
146
|
+
mentionSearch: async (query) => {
|
|
147
|
+
const response = await fetch(`/api/users?q=${encodeURIComponent(query)}`);
|
|
148
|
+
if (!response.ok) throw new Error('用户查询失败');
|
|
149
|
+
return response.json(); // { id, label, description?, avatar? }[]
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
只读状态可以通过 `readonly` 响应式属性动态切换:
|
|
155
|
+
|
|
156
|
+
```vue
|
|
157
|
+
<AdenEditor v-model="content" :readonly="isReadonly" />
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## 生命周期与 SSR
|
|
161
|
+
|
|
162
|
+
组件在 Vue 客户端挂载时初始化编辑器,在卸载时自动清理事件和弹层。使用 Nuxt 或其他 SSR 框架时,可将编辑器放在客户端组件边界内,例如 Nuxt 的 `<ClientOnly>`:
|
|
163
|
+
|
|
164
|
+
```vue
|
|
165
|
+
<ClientOnly>
|
|
166
|
+
<AdenEditor v-model="content" />
|
|
167
|
+
</ClientOnly>
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## 样式定制
|
|
171
|
+
|
|
172
|
+
默认样式随组件自动注入。可在项目 CSS 中覆盖编辑器变量:
|
|
173
|
+
|
|
174
|
+
```css
|
|
175
|
+
.aden-editor {
|
|
176
|
+
--aden-accent: #e8452c;
|
|
177
|
+
--aden-radius: 4px;
|
|
178
|
+
--aden-font: 14px;
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## 当前支持范围
|
|
183
|
+
|
|
184
|
+
此包面向 Vue 3 浏览器项目,复用 `aden-editor` 的 Web 编辑能力。小程序端和协作编辑目前不包含在本 Vue 组件包内。
|
|
185
|
+
|
|
186
|
+
## 许可
|
|
187
|
+
|
|
188
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AdenEditor: () => AdenEditor,
|
|
24
|
+
AdenEditorPlugin: () => AdenEditorPlugin,
|
|
25
|
+
default: () => index_default
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var import_vue = require("vue");
|
|
29
|
+
var import_aden_editor = require("aden-editor");
|
|
30
|
+
var AdenEditor = (0, import_vue.defineComponent)({
|
|
31
|
+
name: "AdenEditor",
|
|
32
|
+
inheritAttrs: false,
|
|
33
|
+
props: {
|
|
34
|
+
modelValue: { type: String, default: void 0 },
|
|
35
|
+
defaultValue: { type: String, default: "" },
|
|
36
|
+
options: { type: Object, default: void 0 },
|
|
37
|
+
readonly: { type: Boolean, default: void 0 }
|
|
38
|
+
},
|
|
39
|
+
emits: {
|
|
40
|
+
"update:modelValue": (_html) => true,
|
|
41
|
+
change: (_change) => true
|
|
42
|
+
},
|
|
43
|
+
setup(props, { attrs, emit, expose }) {
|
|
44
|
+
const mount = (0, import_vue.ref)(null);
|
|
45
|
+
let adapter = null;
|
|
46
|
+
const getAdapter = () => {
|
|
47
|
+
if (!adapter) throw new Error("AdenEditor is not mounted.");
|
|
48
|
+
return adapter;
|
|
49
|
+
};
|
|
50
|
+
expose({
|
|
51
|
+
getHtml: () => getAdapter().getHtml(),
|
|
52
|
+
setHtml: (html) => getAdapter().setHtml(html),
|
|
53
|
+
getJSON: () => getAdapter().getJSON(),
|
|
54
|
+
setJSON: (doc) => getAdapter().setJSON(doc),
|
|
55
|
+
getMarkdown: () => getAdapter().getMarkdown(),
|
|
56
|
+
getText: () => getAdapter().getText(),
|
|
57
|
+
focus: () => getAdapter().focus(),
|
|
58
|
+
clear: () => getAdapter().clear()
|
|
59
|
+
});
|
|
60
|
+
(0, import_vue.onMounted)(() => {
|
|
61
|
+
var _a, _b, _c;
|
|
62
|
+
if (!mount.value) return;
|
|
63
|
+
const editor = (0, import_aden_editor.createEditor)({ html: (_a = props.modelValue) != null ? _a : props.defaultValue });
|
|
64
|
+
adapter = new import_aden_editor.WebAdapter({
|
|
65
|
+
...props.options,
|
|
66
|
+
readonly: (_c = props.readonly) != null ? _c : (_b = props.options) == null ? void 0 : _b.readonly,
|
|
67
|
+
mount: mount.value,
|
|
68
|
+
editor,
|
|
69
|
+
onDocChange: (doc, html) => {
|
|
70
|
+
emit("update:modelValue", html);
|
|
71
|
+
emit("change", { doc, html });
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
(0, import_vue.watch)(() => props.modelValue, (html) => {
|
|
76
|
+
if (html !== void 0 && adapter && adapter.getHtml() !== html) adapter.setHtml(html);
|
|
77
|
+
});
|
|
78
|
+
(0, import_vue.watch)(() => props.readonly, (readonly) => {
|
|
79
|
+
if (readonly !== void 0) adapter == null ? void 0 : adapter.setReadonly(readonly);
|
|
80
|
+
});
|
|
81
|
+
(0, import_vue.onBeforeUnmount)(() => {
|
|
82
|
+
adapter == null ? void 0 : adapter.destroy();
|
|
83
|
+
adapter = null;
|
|
84
|
+
});
|
|
85
|
+
return () => (0, import_vue.h)("div", { ...attrs, ref: mount });
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
var index_default = AdenEditor;
|
|
89
|
+
var AdenEditorPlugin = {
|
|
90
|
+
install(app) {
|
|
91
|
+
app.component("AdenEditor", AdenEditor);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import { defineComponent, h, onBeforeUnmount, onMounted, ref, watch } from 'vue';\nimport type { App, Plugin, PropType } from 'vue';\nimport { createEditor, WebAdapter } from 'aden-editor';\nimport type { Doc, WebAdapterOptions } from 'aden-editor';\n\n/** WebAdapter options. The Vue component owns mount, editor, and change handling. */\nexport type AdenEditorOptions = Omit<WebAdapterOptions, 'mount' | 'editor' | 'onDocChange'>;\n\nexport interface AdenEditorChange {\n doc: Doc;\n html: string;\n}\n\n/** Public methods available through a Vue template ref. */\nexport interface AdenEditorExpose {\n getHtml(): string;\n setHtml(html: string): void;\n getJSON(): Doc;\n setJSON(doc: Doc): void;\n getMarkdown(): string;\n getText(): string;\n focus(): void;\n clear(): void;\n}\n\n/**\n * Vue 3 component for aden-editor.\n *\n * - `v-model` reads and writes HTML.\n * - `options` accepts the standard WebAdapter options.\n * - `change` emits `{ doc, html }` for persistence or app state updates.\n */\nexport const AdenEditor = defineComponent({\n name: 'AdenEditor',\n inheritAttrs: false,\n props: {\n modelValue: { type: String, default: undefined },\n defaultValue: { type: String, default: '' },\n options: { type: Object as PropType<AdenEditorOptions>, default: undefined },\n readonly: { type: Boolean, default: undefined },\n },\n emits: {\n 'update:modelValue': (_html: string) => true,\n change: (_change: AdenEditorChange) => true,\n },\n setup(props, { attrs, emit, expose }) {\n const mount = ref<HTMLDivElement | null>(null);\n let adapter: WebAdapter | null = null;\n\n const getAdapter = (): WebAdapter => {\n if (!adapter) throw new Error('AdenEditor is not mounted.');\n return adapter;\n };\n\n expose({\n getHtml: () => getAdapter().getHtml(),\n setHtml: (html: string) => getAdapter().setHtml(html),\n getJSON: () => getAdapter().getJSON(),\n setJSON: (doc: Doc) => getAdapter().setJSON(doc),\n getMarkdown: () => getAdapter().getMarkdown(),\n getText: () => getAdapter().getText(),\n focus: () => getAdapter().focus(),\n clear: () => getAdapter().clear(),\n } satisfies AdenEditorExpose);\n\n onMounted(() => {\n if (!mount.value) return;\n const editor = createEditor({ html: props.modelValue ?? props.defaultValue });\n adapter = new WebAdapter({\n ...props.options,\n readonly: props.readonly ?? props.options?.readonly,\n mount: mount.value,\n editor,\n onDocChange: (doc, html) => {\n emit('update:modelValue', html);\n emit('change', { doc, html });\n },\n });\n });\n\n watch(() => props.modelValue, (html) => {\n if (html !== undefined && adapter && adapter.getHtml() !== html) adapter.setHtml(html);\n });\n\n watch(() => props.readonly, (readonly) => {\n if (readonly !== undefined) adapter?.setReadonly(readonly);\n });\n\n onBeforeUnmount(() => {\n adapter?.destroy();\n adapter = null;\n });\n\n return () => h('div', { ...attrs, ref: mount });\n },\n});\n\nexport default AdenEditor;\n\n/** Optional global registration: app.use(AdenEditorPlugin). */\nexport const AdenEditorPlugin: Plugin = {\n install(app: App) {\n app.component('AdenEditor', AdenEditor);\n },\n};\n"],
|
|
5
|
+
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;AAC5E,gBAAU,IAAI,8BAAW;AAAA,QACvB,GAAG,MAAM;AAAA,QACT,WAAU,WAAM,aAAN,aAAkB,WAAM,YAAN,mBAAe;AAAA,QAC3C,OAAO,MAAM;AAAA,QACb;AAAA,QACA,aAAa,CAAC,KAAK,SAAS;AAC1B,eAAK,qBAAqB,IAAI;AAC9B,eAAK,UAAU,EAAE,KAAK,KAAK,CAAC;AAAA,QAC9B;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAED,0BAAM,MAAM,MAAM,YAAY,CAAC,SAAS;AACtC,UAAI,SAAS,UAAa,WAAW,QAAQ,QAAQ,MAAM,KAAM,SAAQ,QAAQ,IAAI;AAAA,IACvF,CAAC;AAED,0BAAM,MAAM,MAAM,UAAU,CAAC,aAAa;AACxC,UAAI,aAAa,OAAW,oCAAS,YAAY;AAAA,IACnD,CAAC;AAED,oCAAgB,MAAM;AACpB,yCAAS;AACT,gBAAU;AAAA,IACZ,CAAC;AAED,WAAO,UAAM,cAAE,OAAO,EAAE,GAAG,OAAO,KAAK,MAAM,CAAC;AAAA,EAChD;AACF,CAAC;AAED,IAAO,gBAAQ;AAGR,IAAM,mBAA2B;AAAA,EACtC,QAAQ,KAAU;AAChB,QAAI,UAAU,cAAc,UAAU;AAAA,EACxC;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { defineComponent, h, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
3
|
+
import { createEditor, WebAdapter } from "aden-editor";
|
|
4
|
+
var AdenEditor = defineComponent({
|
|
5
|
+
name: "AdenEditor",
|
|
6
|
+
inheritAttrs: false,
|
|
7
|
+
props: {
|
|
8
|
+
modelValue: { type: String, default: void 0 },
|
|
9
|
+
defaultValue: { type: String, default: "" },
|
|
10
|
+
options: { type: Object, default: void 0 },
|
|
11
|
+
readonly: { type: Boolean, default: void 0 }
|
|
12
|
+
},
|
|
13
|
+
emits: {
|
|
14
|
+
"update:modelValue": (_html) => true,
|
|
15
|
+
change: (_change) => true
|
|
16
|
+
},
|
|
17
|
+
setup(props, { attrs, emit, expose }) {
|
|
18
|
+
const mount = ref(null);
|
|
19
|
+
let adapter = null;
|
|
20
|
+
const getAdapter = () => {
|
|
21
|
+
if (!adapter) throw new Error("AdenEditor is not mounted.");
|
|
22
|
+
return adapter;
|
|
23
|
+
};
|
|
24
|
+
expose({
|
|
25
|
+
getHtml: () => getAdapter().getHtml(),
|
|
26
|
+
setHtml: (html) => getAdapter().setHtml(html),
|
|
27
|
+
getJSON: () => getAdapter().getJSON(),
|
|
28
|
+
setJSON: (doc) => getAdapter().setJSON(doc),
|
|
29
|
+
getMarkdown: () => getAdapter().getMarkdown(),
|
|
30
|
+
getText: () => getAdapter().getText(),
|
|
31
|
+
focus: () => getAdapter().focus(),
|
|
32
|
+
clear: () => getAdapter().clear()
|
|
33
|
+
});
|
|
34
|
+
onMounted(() => {
|
|
35
|
+
var _a, _b, _c;
|
|
36
|
+
if (!mount.value) return;
|
|
37
|
+
const editor = createEditor({ html: (_a = props.modelValue) != null ? _a : props.defaultValue });
|
|
38
|
+
adapter = new WebAdapter({
|
|
39
|
+
...props.options,
|
|
40
|
+
readonly: (_c = props.readonly) != null ? _c : (_b = props.options) == null ? void 0 : _b.readonly,
|
|
41
|
+
mount: mount.value,
|
|
42
|
+
editor,
|
|
43
|
+
onDocChange: (doc, html) => {
|
|
44
|
+
emit("update:modelValue", html);
|
|
45
|
+
emit("change", { doc, html });
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
watch(() => props.modelValue, (html) => {
|
|
50
|
+
if (html !== void 0 && adapter && adapter.getHtml() !== html) adapter.setHtml(html);
|
|
51
|
+
});
|
|
52
|
+
watch(() => props.readonly, (readonly) => {
|
|
53
|
+
if (readonly !== void 0) adapter == null ? void 0 : adapter.setReadonly(readonly);
|
|
54
|
+
});
|
|
55
|
+
onBeforeUnmount(() => {
|
|
56
|
+
adapter == null ? void 0 : adapter.destroy();
|
|
57
|
+
adapter = null;
|
|
58
|
+
});
|
|
59
|
+
return () => h("div", { ...attrs, ref: mount });
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
var index_default = AdenEditor;
|
|
63
|
+
var AdenEditorPlugin = {
|
|
64
|
+
install(app) {
|
|
65
|
+
app.component("AdenEditor", AdenEditor);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
export {
|
|
69
|
+
AdenEditor,
|
|
70
|
+
AdenEditorPlugin,
|
|
71
|
+
index_default as default
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import { defineComponent, h, onBeforeUnmount, onMounted, ref, watch } from 'vue';\nimport type { App, Plugin, PropType } from 'vue';\nimport { createEditor, WebAdapter } from 'aden-editor';\nimport type { Doc, WebAdapterOptions } from 'aden-editor';\n\n/** WebAdapter options. The Vue component owns mount, editor, and change handling. */\nexport type AdenEditorOptions = Omit<WebAdapterOptions, 'mount' | 'editor' | 'onDocChange'>;\n\nexport interface AdenEditorChange {\n doc: Doc;\n html: string;\n}\n\n/** Public methods available through a Vue template ref. */\nexport interface AdenEditorExpose {\n getHtml(): string;\n setHtml(html: string): void;\n getJSON(): Doc;\n setJSON(doc: Doc): void;\n getMarkdown(): string;\n getText(): string;\n focus(): void;\n clear(): void;\n}\n\n/**\n * Vue 3 component for aden-editor.\n *\n * - `v-model` reads and writes HTML.\n * - `options` accepts the standard WebAdapter options.\n * - `change` emits `{ doc, html }` for persistence or app state updates.\n */\nexport const AdenEditor = defineComponent({\n name: 'AdenEditor',\n inheritAttrs: false,\n props: {\n modelValue: { type: String, default: undefined },\n defaultValue: { type: String, default: '' },\n options: { type: Object as PropType<AdenEditorOptions>, default: undefined },\n readonly: { type: Boolean, default: undefined },\n },\n emits: {\n 'update:modelValue': (_html: string) => true,\n change: (_change: AdenEditorChange) => true,\n },\n setup(props, { attrs, emit, expose }) {\n const mount = ref<HTMLDivElement | null>(null);\n let adapter: WebAdapter | null = null;\n\n const getAdapter = (): WebAdapter => {\n if (!adapter) throw new Error('AdenEditor is not mounted.');\n return adapter;\n };\n\n expose({\n getHtml: () => getAdapter().getHtml(),\n setHtml: (html: string) => getAdapter().setHtml(html),\n getJSON: () => getAdapter().getJSON(),\n setJSON: (doc: Doc) => getAdapter().setJSON(doc),\n getMarkdown: () => getAdapter().getMarkdown(),\n getText: () => getAdapter().getText(),\n focus: () => getAdapter().focus(),\n clear: () => getAdapter().clear(),\n } satisfies AdenEditorExpose);\n\n onMounted(() => {\n if (!mount.value) return;\n const editor = createEditor({ html: props.modelValue ?? props.defaultValue });\n adapter = new WebAdapter({\n ...props.options,\n readonly: props.readonly ?? props.options?.readonly,\n mount: mount.value,\n editor,\n onDocChange: (doc, html) => {\n emit('update:modelValue', html);\n emit('change', { doc, html });\n },\n });\n });\n\n watch(() => props.modelValue, (html) => {\n if (html !== undefined && adapter && adapter.getHtml() !== html) adapter.setHtml(html);\n });\n\n watch(() => props.readonly, (readonly) => {\n if (readonly !== undefined) adapter?.setReadonly(readonly);\n });\n\n onBeforeUnmount(() => {\n adapter?.destroy();\n adapter = null;\n });\n\n return () => h('div', { ...attrs, ref: mount });\n },\n});\n\nexport default AdenEditor;\n\n/** Optional global registration: app.use(AdenEditorPlugin). */\nexport const AdenEditorPlugin: Plugin = {\n install(app: App) {\n app.component('AdenEditor', AdenEditor);\n },\n};\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,iBAAiB,GAAG,iBAAiB,WAAW,KAAK,aAAa;AAE3E,SAAS,cAAc,kBAAkB;AA8BlC,IAAM,aAAa,gBAAgB;AAAA,EACxC,MAAM;AAAA,EACN,cAAc;AAAA,EACd,OAAO;AAAA,IACL,YAAY,EAAE,MAAM,QAA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AU,EAAE,KAAK,KAAK,CAAC;AAAA,QAC9B;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAED,UAAM,MAAM,MAAM,YAAY,CAAC,SAAS;AACtC,UAAI,SAAS,UAAa,WAAW,QAAQ,QAAQ,MAAM,KAAM,SAAQ,QAAQ,IAAI;AAAA,IACvF,CAAC;AAED,UAAM,MAAM,MAAM,UAAU,CAAC,aAAa;AACxC,UAAI,aAAa,OAAW,oCAAS,YAAY;AAAA,IACnD,CAAC;AAED,oBAAgB,MAAM;AACpB,yCAAS;AACT,gBAAU;AAAA,IACZ,CAAC;AAED,WAAO,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,KAAK,MAAM,CAAC;AAAA,EAChD;AACF,CAAC;AAED,IAAO,gBAAQ;AAGR,IAAM,mBAA2B;AAAA,EACtC,QAAQ,KAAU;AAChB,QAAI,UAAU,cAAc,UAAU;AAAA,EACxC;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Plugin, PropType } from 'vue';
|
|
2
|
+
import type { Doc, WebAdapterOptions } from 'aden-editor';
|
|
3
|
+
/** WebAdapter options. The Vue component owns mount, editor, and change handling. */
|
|
4
|
+
export type AdenEditorOptions = Omit<WebAdapterOptions, 'mount' | 'editor' | 'onDocChange'>;
|
|
5
|
+
export interface AdenEditorChange {
|
|
6
|
+
doc: Doc;
|
|
7
|
+
html: string;
|
|
8
|
+
}
|
|
9
|
+
/** Public methods available through a Vue template ref. */
|
|
10
|
+
export interface AdenEditorExpose {
|
|
11
|
+
getHtml(): string;
|
|
12
|
+
setHtml(html: string): void;
|
|
13
|
+
getJSON(): Doc;
|
|
14
|
+
setJSON(doc: Doc): void;
|
|
15
|
+
getMarkdown(): string;
|
|
16
|
+
getText(): string;
|
|
17
|
+
focus(): void;
|
|
18
|
+
clear(): void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Vue 3 component for aden-editor.
|
|
22
|
+
*
|
|
23
|
+
* - `v-model` reads and writes HTML.
|
|
24
|
+
* - `options` accepts the standard WebAdapter options.
|
|
25
|
+
* - `change` emits `{ doc, html }` for persistence or app state updates.
|
|
26
|
+
*/
|
|
27
|
+
export declare const AdenEditor: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
28
|
+
modelValue: {
|
|
29
|
+
type: StringConstructor;
|
|
30
|
+
default: undefined;
|
|
31
|
+
};
|
|
32
|
+
defaultValue: {
|
|
33
|
+
type: StringConstructor;
|
|
34
|
+
default: string;
|
|
35
|
+
};
|
|
36
|
+
options: {
|
|
37
|
+
type: PropType<AdenEditorOptions>;
|
|
38
|
+
default: undefined;
|
|
39
|
+
};
|
|
40
|
+
readonly: {
|
|
41
|
+
type: BooleanConstructor;
|
|
42
|
+
default: undefined;
|
|
43
|
+
};
|
|
44
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
45
|
+
[key: string]: any;
|
|
46
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
47
|
+
'update:modelValue': (_html: string) => true;
|
|
48
|
+
change: (_change: AdenEditorChange) => true;
|
|
49
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
50
|
+
modelValue: {
|
|
51
|
+
type: StringConstructor;
|
|
52
|
+
default: undefined;
|
|
53
|
+
};
|
|
54
|
+
defaultValue: {
|
|
55
|
+
type: StringConstructor;
|
|
56
|
+
default: string;
|
|
57
|
+
};
|
|
58
|
+
options: {
|
|
59
|
+
type: PropType<AdenEditorOptions>;
|
|
60
|
+
default: undefined;
|
|
61
|
+
};
|
|
62
|
+
readonly: {
|
|
63
|
+
type: BooleanConstructor;
|
|
64
|
+
default: undefined;
|
|
65
|
+
};
|
|
66
|
+
}>> & Readonly<{
|
|
67
|
+
"onUpdate:modelValue"?: ((_html: string) => any) | undefined;
|
|
68
|
+
onChange?: ((_change: AdenEditorChange) => any) | undefined;
|
|
69
|
+
}>, {
|
|
70
|
+
readonly: boolean;
|
|
71
|
+
modelValue: string;
|
|
72
|
+
defaultValue: string;
|
|
73
|
+
options: AdenEditorOptions;
|
|
74
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
75
|
+
export default AdenEditor;
|
|
76
|
+
/** Optional global registration: app.use(AdenEditorPlugin). */
|
|
77
|
+
export declare const AdenEditorPlugin: Plugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aden-editor-vue",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vue 3 富文本编辑器组件,支持 v-model、自定义工具栏和业务上传接口",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/types/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"keywords": [
|
|
21
|
+
"vue",
|
|
22
|
+
"vue3",
|
|
23
|
+
"editor",
|
|
24
|
+
"rich-text",
|
|
25
|
+
"wysiwyg",
|
|
26
|
+
"contenteditable",
|
|
27
|
+
"editor-component",
|
|
28
|
+
"toolbar"
|
|
29
|
+
],
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"vue": ">=3.3.0"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"aden-editor": "^0.1.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "node ../../scripts/build-vue.mjs",
|
|
38
|
+
"prepack": "npm run build"
|
|
39
|
+
}
|
|
40
|
+
}
|