@easyx/editor 1.1.2 → 2.0.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 +32 -118
- package/dist/core/create-editor.d.ts +2 -2
- package/dist/index.cjs +33 -26
- package/dist/index.d.ts +9 -9
- package/dist/index.js +33 -26
- package/dist/types.d.ts +10 -10
- package/dist/utils/event-emitter.d.ts +4 -4
- package/dist/utils/media-upload.d.ts +2 -2
- package/package.json +4 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 EasyX
|
|
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,16 +1,20 @@
|
|
|
1
1
|
# @easyx/editor
|
|
2
2
|
|
|
3
|
-
零框架依赖的 Tiptap
|
|
3
|
+
零框架依赖的 Tiptap 富文本编辑器:工具栏、气泡菜单、媒体上传与表格增强开箱即用,可接入任何前端技术栈。
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@easyx/editor)
|
|
6
|
+
[](https://github.com/easyx-dev/easyx/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
[文档](https://easyx-dev.github.io/easyx/editor/) · [演示](https://easyx-dev.github.io/easyx/editor/demo/) · [API 参考](https://easyx-dev.github.io/easyx/editor/api-reference/)
|
|
4
9
|
|
|
5
10
|
## 特性
|
|
6
11
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
- **表格增强**:集成 [`@easyx/tiptap-table-plus`](https://www.npmjs.com/package/@easyx/tiptap-table-plus)
|
|
12
|
+
- **零框架依赖**:工具栏、气泡菜单与选中浮层均为原生 DOM,不引入 React / Vue
|
|
13
|
+
- **开箱即用**:内置文本样式、对齐缩进、上下标、任务列表、链接、表格等常用能力
|
|
14
|
+
- **表格增强**:集成 [`@easyx/tiptap-table-plus`](https://www.npmjs.com/package/@easyx/tiptap-table-plus),支持单元格样式、选区手柄、右键菜单与块级背景色
|
|
10
15
|
- **媒体支持**:图片(对齐 / 拖拽缩放 / 替代文本)、视频(对齐 / 封面 / 控制器 / 自动播放)、音频、附件
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- **亮 / 暗主题**:通过 CSS 变量控制,可被外部覆盖
|
|
16
|
+
- **粘贴与拖入上传**:按文件类型自动路由到对应媒体的 `upload`
|
|
17
|
+
- **高度与主题**:自适应 / 定高 / 最大高度 / 拖拽调节;亮暗主题经 CSS 变量控制
|
|
14
18
|
|
|
15
19
|
## 安装
|
|
16
20
|
|
|
@@ -18,139 +22,49 @@
|
|
|
18
22
|
pnpm add @easyx/editor
|
|
19
23
|
```
|
|
20
24
|
|
|
21
|
-
样式已内联进 JS
|
|
25
|
+
样式已内联进 JS 产物,无需单独引入 CSS。
|
|
22
26
|
|
|
23
27
|
## 快速上手
|
|
24
28
|
|
|
25
29
|
```ts
|
|
26
|
-
import { createEditor } from '@easyx/editor'
|
|
30
|
+
import { createEditor } from '@easyx/editor';
|
|
27
31
|
|
|
28
|
-
const container = document.querySelector<HTMLElement>('#editor')
|
|
32
|
+
const container = document.querySelector<HTMLElement>('#editor')!;
|
|
29
33
|
|
|
30
34
|
const editor = createEditor(container, {
|
|
31
35
|
placeholder: '请输入…',
|
|
32
36
|
defaultTheme: 'light',
|
|
33
37
|
height: 320,
|
|
34
|
-
minHeight: 200,
|
|
35
|
-
maxHeight: 480,
|
|
36
38
|
resizable: true,
|
|
37
39
|
image: {
|
|
38
40
|
upload: async (file) => ({
|
|
39
|
-
id:
|
|
41
|
+
id: file.name,
|
|
40
42
|
url: URL.createObjectURL(file),
|
|
41
43
|
name: file.name,
|
|
44
|
+
size: file.size,
|
|
42
45
|
}),
|
|
43
46
|
},
|
|
44
|
-
onChange: (
|
|
45
|
-
})
|
|
46
|
-
```
|
|
47
|
+
onChange: (content) => console.log(content),
|
|
48
|
+
});
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
`createEditor(container, options)` 的第二个参数为 `EasyxEditorOptions`:
|
|
51
|
-
|
|
52
|
-
| 选项 | 类型 | 默认值 | 说明 |
|
|
53
|
-
|------|------|--------|------|
|
|
54
|
-
| `placeholder` | `string` | `'输入内容…'` | 空内容占位符 |
|
|
55
|
-
| `readOnly` | `boolean` | `false` | 只读模式 |
|
|
56
|
-
| `autoFocus` | `boolean` | `false` | 创建后自动聚焦 |
|
|
57
|
-
| `defaultContent` | `string` | — | 初始内容(HTML) |
|
|
58
|
-
| `defaultTheme` | `'light' \| 'dark'` | `'light'` | 初始主题 |
|
|
59
|
-
| `image` | `ImageMediaUploadConfig` | — | 图片上传 / 缩放配置 |
|
|
60
|
-
| `video` | `MediaUploadConfig` | — | 视频上传 / 媒体库配置 |
|
|
61
|
-
| `audio` | `MediaUploadConfig` | — | 音频上传 / 媒体库配置 |
|
|
62
|
-
| `attachment` | `MediaUploadConfig` | — | 附件上传 / 媒体库配置 |
|
|
63
|
-
| `minHeight` | `number \| string` | — | 最小高度(number 视为 px) |
|
|
64
|
-
| `height` | `number \| 'auto' \| string` | `'auto'` | 定高并内部滚动;`'auto'` 随内容伸缩 |
|
|
65
|
-
| `maxHeight` | `number \| string` | — | 最大高度,内容撑到上限后内部滚动 |
|
|
66
|
-
| `resizable` | `boolean` | `false` | 右下角拖拽手柄调高 |
|
|
67
|
-
| `onChange` | `(html: string) => void` | — | 内容变更回调 |
|
|
68
|
-
| `onReady` | `() => void` | — | 初始化完成回调 |
|
|
69
|
-
| `onFocus` | `() => void` | — | 聚焦回调 |
|
|
70
|
-
| `onBlur` | `() => void` | — | 失焦回调 |
|
|
71
|
-
| `onDestroy` | `() => void` | — | 销毁回调 |
|
|
72
|
-
|
|
73
|
-
## 实例方法
|
|
74
|
-
|
|
75
|
-
`createEditor` 返回一个编辑器实例:
|
|
76
|
-
|
|
77
|
-
| 方法 | 说明 |
|
|
78
|
-
|------|------|
|
|
79
|
-
| `isEmpty()` | 编辑器是否为空 |
|
|
80
|
-
| `getHTML()` / `setHTML(html)` | 读写 HTML 内容 |
|
|
81
|
-
| `getJSON()` / `setJSON(json)` | 读写 JSON 内容 |
|
|
82
|
-
| `getText()` | 获取纯文本 |
|
|
83
|
-
| `clear()` | 清空内容 |
|
|
84
|
-
| `setTheme('light' \| 'dark')` | 切换主题(同步表格组件主题) |
|
|
85
|
-
| `focus()` / `blur()` / `isFocused()` | 焦点管理 |
|
|
86
|
-
| `disable()` / `enable()` / `isDisabled()` | 禁用 / 启用编辑器 |
|
|
87
|
-
| `getContainer()` | 获取挂载 DOM 元素 |
|
|
88
|
-
| `destroy()` | 销毁编辑器,清理 DOM 与事件监听 |
|
|
89
|
-
| `on(event, handler)` / `off(event, handler)` | 事件监听 |
|
|
90
|
-
| `once(event, handler)` | 一次性事件监听 |
|
|
91
|
-
| `emit(event, ...args)` | 触发自定义事件 |
|
|
92
|
-
|
|
93
|
-
各内容读写方法均以 `ContentType = string` / JSON 作为输入输出。
|
|
94
|
-
|
|
95
|
-
## 事件
|
|
96
|
-
|
|
97
|
-
| 事件 | 触发时机 | 参数 |
|
|
98
|
-
|------|----------|------|
|
|
99
|
-
| `ready` | 编辑器初始化完成 | 无 |
|
|
100
|
-
| `change` | 内容变更 | `html: string` |
|
|
101
|
-
| `focus` | 获得焦点 | 无 |
|
|
102
|
-
| `blur` | 失去焦点 | 无 |
|
|
103
|
-
| `destroy` | 销毁 | 无 |
|
|
104
|
-
| `uploadError` | 粘贴 / 拖入上传失败 | `file: File, error: unknown` |
|
|
105
|
-
|
|
106
|
-
```ts
|
|
107
|
-
editor.on('change', (html) => console.log(html))
|
|
108
|
-
editor.on('uploadError', (file, error) => console.error(file.name, error))
|
|
50
|
+
editor.setHTML('<p>Hello World</p>');
|
|
109
51
|
```
|
|
110
52
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
`image` / `video` / `audio` / `attachment` 均接受 `MediaUploadConfig`:
|
|
114
|
-
|
|
115
|
-
```ts
|
|
116
|
-
interface MediaUploadConfig {
|
|
117
|
-
/** 上传单个文件,返回媒体项 */
|
|
118
|
-
upload: (
|
|
119
|
-
file: File,
|
|
120
|
-
onProgress?: (progress: number) => void,
|
|
121
|
-
) => Promise<MediaItem>
|
|
122
|
-
/** 媒体库分页列表(可选),提供后媒体下拉会出现「媒体库」Tab */
|
|
123
|
-
getList?: (params: MediaListParams) => Promise<MediaListResult>
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
interface MediaItem {
|
|
127
|
-
id: string
|
|
128
|
-
url: string
|
|
129
|
-
name: string
|
|
130
|
-
size?: number
|
|
131
|
-
thumbnailUrl?: string
|
|
132
|
-
duration?: number
|
|
133
|
-
fileType?: string
|
|
134
|
-
}
|
|
135
|
-
```
|
|
53
|
+
容器为空时 `createEditor` 抛错;实例方法、事件与媒体类型见 [API 参考](https://easyx-dev.github.io/easyx/editor/api-reference/)。
|
|
136
54
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
```ts
|
|
140
|
-
image: {
|
|
141
|
-
resizable: false, // 关闭图片拖拽缩放
|
|
142
|
-
upload: async (file) => ({ id: '1', url: '...', name: file.name }),
|
|
143
|
-
}
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
## 主题
|
|
55
|
+
## 许可
|
|
147
56
|
|
|
148
|
-
|
|
57
|
+
[MIT](https://github.com/easyx-dev/easyx/blob/main/LICENSE)
|
|
149
58
|
|
|
150
|
-
|
|
151
|
-
editor.setTheme('dark')
|
|
152
|
-
```
|
|
59
|
+
## 从 v1 迁移
|
|
153
60
|
|
|
154
|
-
|
|
61
|
+
v2 统一了公开类型命名,行为不变:
|
|
155
62
|
|
|
156
|
-
|
|
63
|
+
| v1 | v2 |
|
|
64
|
+
|----|----|
|
|
65
|
+
| `EasyxEditorOptions` | `EditorOptions` |
|
|
66
|
+
| `ThemeType` | `EditorTheme` |
|
|
67
|
+
| `ContentType` | `EditorContentType` |
|
|
68
|
+
| `EventHandler` | `EditorEventHandler` |
|
|
69
|
+
| `UploadProgressCallback` | `MediaUploadProgress` |
|
|
70
|
+
| `ImageMediaUploadConfig` | `EditorImageConfig`(现为公开导出) |
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Editor } from '@tiptap/core';
|
|
2
|
-
import type {
|
|
2
|
+
import type { EditorOptions } from '../types';
|
|
3
3
|
import { EventEmitter } from '../utils/event-emitter';
|
|
4
|
-
export declare function createEditorInstance(container: HTMLElement, options:
|
|
4
|
+
export declare function createEditorInstance(container: HTMLElement, options: EditorOptions): {
|
|
5
5
|
editor: Editor;
|
|
6
6
|
emitter: EventEmitter;
|
|
7
7
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_modules__ = {
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var ___CSS_LOADER_EXPORT___ =
|
|
3
|
+
702 (module, __webpack_exports__, __webpack_require__) {
|
|
4
|
+
var _node_modules_pnpm_rsbuild_core_2_1_13_node_modules_rsbuild_core_compiled_css_loader_noSourceMaps_js__rspack_import_0 = __webpack_require__(879);
|
|
5
|
+
var _node_modules_pnpm_rsbuild_core_2_1_13_node_modules_rsbuild_core_compiled_css_loader_noSourceMaps_js__rspack_import_0_default = /*#__PURE__*/ __webpack_require__.n(_node_modules_pnpm_rsbuild_core_2_1_13_node_modules_rsbuild_core_compiled_css_loader_noSourceMaps_js__rspack_import_0);
|
|
6
|
+
var _node_modules_pnpm_rsbuild_core_2_1_13_node_modules_rsbuild_core_compiled_css_loader_api_js__rspack_import_1 = __webpack_require__(968);
|
|
7
|
+
var _node_modules_pnpm_rsbuild_core_2_1_13_node_modules_rsbuild_core_compiled_css_loader_api_js__rspack_import_1_default = /*#__PURE__*/ __webpack_require__.n(_node_modules_pnpm_rsbuild_core_2_1_13_node_modules_rsbuild_core_compiled_css_loader_api_js__rspack_import_1);
|
|
8
|
+
var ___CSS_LOADER_EXPORT___ = _node_modules_pnpm_rsbuild_core_2_1_13_node_modules_rsbuild_core_compiled_css_loader_api_js__rspack_import_1_default()(_node_modules_pnpm_rsbuild_core_2_1_13_node_modules_rsbuild_core_compiled_css_loader_noSourceMaps_js__rspack_import_0_default());
|
|
9
9
|
___CSS_LOADER_EXPORT___.push([
|
|
10
10
|
module.id,
|
|
11
11
|
`.easyx-editor {
|
|
@@ -154,11 +154,18 @@ var __webpack_modules__ = {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
.easyx-editor.easyx-editor-scroll .easyx-editor-content {
|
|
157
|
+
flex-direction: column;
|
|
157
158
|
flex: auto;
|
|
158
159
|
min-height: 0;
|
|
160
|
+
display: flex;
|
|
159
161
|
overflow-y: auto;
|
|
160
162
|
}
|
|
161
163
|
|
|
164
|
+
.easyx-editor.easyx-editor-scroll .easyx-editor-content > .ProseMirror {
|
|
165
|
+
flex: 1 0 auto;
|
|
166
|
+
min-height: 0;
|
|
167
|
+
}
|
|
168
|
+
|
|
162
169
|
.easyx-editor-resize-handle {
|
|
163
170
|
cursor: ns-resize;
|
|
164
171
|
z-index: 5;
|
|
@@ -211,21 +218,21 @@ var __webpack_modules__ = {
|
|
|
211
218
|
}
|
|
212
219
|
|
|
213
220
|
.easyx-editor-content {
|
|
214
|
-
padding: var(--easyx-editor-padding);
|
|
215
|
-
min-height: var(--easyx-editor-min-height);
|
|
216
221
|
word-break: break-word;
|
|
217
222
|
outline: none;
|
|
218
223
|
}
|
|
219
224
|
|
|
220
|
-
.easyx-editor-content .ProseMirror {
|
|
225
|
+
.easyx-editor-content > .ProseMirror {
|
|
226
|
+
padding: var(--easyx-editor-padding);
|
|
227
|
+
min-height: var(--easyx-editor-min-height);
|
|
221
228
|
outline: none;
|
|
222
229
|
}
|
|
223
230
|
|
|
224
|
-
.easyx-editor-content > :first-child {
|
|
231
|
+
.easyx-editor-content > .ProseMirror > :first-child {
|
|
225
232
|
margin-top: 0;
|
|
226
233
|
}
|
|
227
234
|
|
|
228
|
-
.easyx-editor-content > :last-child {
|
|
235
|
+
.easyx-editor-content > .ProseMirror > :last-child {
|
|
229
236
|
margin-bottom: 0;
|
|
230
237
|
}
|
|
231
238
|
|
|
@@ -1691,7 +1698,7 @@ var __webpack_modules__ = {
|
|
|
1691
1698
|
A: __rspack_default_export
|
|
1692
1699
|
});
|
|
1693
1700
|
},
|
|
1694
|
-
|
|
1701
|
+
968 (module) {
|
|
1695
1702
|
module.exports = function(cssWithMappingToString) {
|
|
1696
1703
|
var list = [];
|
|
1697
1704
|
list.toString = function() {
|
|
@@ -1744,12 +1751,12 @@ var __webpack_modules__ = {
|
|
|
1744
1751
|
return list;
|
|
1745
1752
|
};
|
|
1746
1753
|
},
|
|
1747
|
-
|
|
1754
|
+
879 (module) {
|
|
1748
1755
|
module.exports = function(i) {
|
|
1749
1756
|
return i[1];
|
|
1750
1757
|
};
|
|
1751
1758
|
},
|
|
1752
|
-
|
|
1759
|
+
987 (module) {
|
|
1753
1760
|
var stylesInDOM = [];
|
|
1754
1761
|
function getIndexByIdentifier(identifier) {
|
|
1755
1762
|
var result = -1;
|
|
@@ -1827,7 +1834,7 @@ var __webpack_modules__ = {
|
|
|
1827
1834
|
};
|
|
1828
1835
|
};
|
|
1829
1836
|
},
|
|
1830
|
-
|
|
1837
|
+
324 (module) {
|
|
1831
1838
|
var memo = {};
|
|
1832
1839
|
function getTarget(target) {
|
|
1833
1840
|
if (void 0 === memo[target]) {
|
|
@@ -1848,7 +1855,7 @@ var __webpack_modules__ = {
|
|
|
1848
1855
|
}
|
|
1849
1856
|
module.exports = insertBySelector;
|
|
1850
1857
|
},
|
|
1851
|
-
|
|
1858
|
+
927 (module) {
|
|
1852
1859
|
function insertStyleElement(options) {
|
|
1853
1860
|
var element = document.createElement("style");
|
|
1854
1861
|
options.setAttributes(element, options.attributes);
|
|
@@ -1857,14 +1864,14 @@ var __webpack_modules__ = {
|
|
|
1857
1864
|
}
|
|
1858
1865
|
module.exports = insertStyleElement;
|
|
1859
1866
|
},
|
|
1860
|
-
|
|
1867
|
+
723 (module, __unused_rspack_exports, __webpack_require__) {
|
|
1861
1868
|
function setAttributesWithoutAttributes(styleElement) {
|
|
1862
1869
|
var nonce = __webpack_require__.nc;
|
|
1863
1870
|
if (nonce) styleElement.setAttribute("nonce", nonce);
|
|
1864
1871
|
}
|
|
1865
1872
|
module.exports = setAttributesWithoutAttributes;
|
|
1866
1873
|
},
|
|
1867
|
-
|
|
1874
|
+
24 (module) {
|
|
1868
1875
|
function apply(styleElement, options, obj) {
|
|
1869
1876
|
var css = "";
|
|
1870
1877
|
if (obj.supports) css += "@supports (".concat(obj.supports, ") {");
|
|
@@ -1900,7 +1907,7 @@ var __webpack_modules__ = {
|
|
|
1900
1907
|
}
|
|
1901
1908
|
module.exports = domAPI;
|
|
1902
1909
|
},
|
|
1903
|
-
|
|
1910
|
+
508 (module) {
|
|
1904
1911
|
function styleTagTransform(css, styleElement) {
|
|
1905
1912
|
if (styleElement.styleSheet) styleElement.styleSheet.cssText = css;
|
|
1906
1913
|
else {
|
|
@@ -1965,19 +1972,19 @@ var __webpack_exports__ = {};
|
|
|
1965
1972
|
__webpack_require__.d(__webpack_exports__, {
|
|
1966
1973
|
createEditor: ()=>createEditor
|
|
1967
1974
|
});
|
|
1968
|
-
var injectStylesIntoStyleTag = __webpack_require__(
|
|
1975
|
+
var injectStylesIntoStyleTag = __webpack_require__(987);
|
|
1969
1976
|
var injectStylesIntoStyleTag_default = /*#__PURE__*/ __webpack_require__.n(injectStylesIntoStyleTag);
|
|
1970
|
-
var styleDomAPI = __webpack_require__(
|
|
1977
|
+
var styleDomAPI = __webpack_require__(24);
|
|
1971
1978
|
var styleDomAPI_default = /*#__PURE__*/ __webpack_require__.n(styleDomAPI);
|
|
1972
|
-
var insertBySelector = __webpack_require__(
|
|
1979
|
+
var insertBySelector = __webpack_require__(324);
|
|
1973
1980
|
var insertBySelector_default = /*#__PURE__*/ __webpack_require__.n(insertBySelector);
|
|
1974
|
-
var setAttributesWithoutAttributes = __webpack_require__(
|
|
1981
|
+
var setAttributesWithoutAttributes = __webpack_require__(723);
|
|
1975
1982
|
var setAttributesWithoutAttributes_default = /*#__PURE__*/ __webpack_require__.n(setAttributesWithoutAttributes);
|
|
1976
|
-
var insertStyleElement = __webpack_require__(
|
|
1983
|
+
var insertStyleElement = __webpack_require__(927);
|
|
1977
1984
|
var insertStyleElement_default = /*#__PURE__*/ __webpack_require__.n(insertStyleElement);
|
|
1978
|
-
var styleTagTransform = __webpack_require__(
|
|
1985
|
+
var styleTagTransform = __webpack_require__(508);
|
|
1979
1986
|
var styleTagTransform_default = /*#__PURE__*/ __webpack_require__.n(styleTagTransform);
|
|
1980
|
-
var styles = __webpack_require__(
|
|
1987
|
+
var styles = __webpack_require__(702);
|
|
1981
1988
|
var styles_options = {};
|
|
1982
1989
|
styles_options.styleTagTransform = styleTagTransform_default();
|
|
1983
1990
|
styles_options.setAttributes = setAttributesWithoutAttributes_default();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import './styles/index.scss';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
export type {
|
|
5
|
-
export type {
|
|
6
|
-
export declare function createEditor(container: HTMLElement, options:
|
|
2
|
+
import type { EditorOptions, EditorTheme } from './types';
|
|
3
|
+
import type { EditorEventHandler } from './utils/event-emitter';
|
|
4
|
+
export type { EditorContentType, EditorImageConfig, EditorOptions, EditorTheme, MediaItem, MediaListParams, MediaListResult, MediaUploadConfig, MediaUploadProgress, } from './types';
|
|
5
|
+
export type { EditorEventHandler } from './utils/event-emitter';
|
|
6
|
+
export declare function createEditor(container: HTMLElement, options: EditorOptions): {
|
|
7
7
|
isEmpty(): boolean;
|
|
8
8
|
clear(): void;
|
|
9
9
|
setHTML(html: string): void;
|
|
@@ -11,7 +11,7 @@ export declare function createEditor(container: HTMLElement, options: EasyxEdito
|
|
|
11
11
|
getText(): string;
|
|
12
12
|
setJSON(json: Record<string, unknown>): void;
|
|
13
13
|
getJSON(): Record<string, unknown>;
|
|
14
|
-
setTheme(theme:
|
|
14
|
+
setTheme(theme: EditorTheme): void;
|
|
15
15
|
focus(): void;
|
|
16
16
|
blur(): void;
|
|
17
17
|
isFocused(): boolean;
|
|
@@ -20,8 +20,8 @@ export declare function createEditor(container: HTMLElement, options: EasyxEdito
|
|
|
20
20
|
isDisabled(): boolean;
|
|
21
21
|
getContainer(): HTMLElement;
|
|
22
22
|
destroy(): void;
|
|
23
|
-
on(event: string, handler:
|
|
24
|
-
off(event: string, handler:
|
|
25
|
-
once(event: string, handler:
|
|
23
|
+
on(event: string, handler: EditorEventHandler): void;
|
|
24
|
+
off(event: string, handler: EditorEventHandler): void;
|
|
25
|
+
once(event: string, handler: EditorEventHandler): void;
|
|
26
26
|
emit(event: string, ...args: unknown[]): void;
|
|
27
27
|
};
|
package/dist/index.js
CHANGED
|
@@ -59,12 +59,12 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
59
59
|
__webpack_require__.nc = void 0;
|
|
60
60
|
})();
|
|
61
61
|
__webpack_require__.add({
|
|
62
|
-
|
|
63
|
-
var
|
|
64
|
-
var
|
|
65
|
-
var
|
|
66
|
-
var
|
|
67
|
-
var ___CSS_LOADER_EXPORT___ =
|
|
62
|
+
2702 (module, __webpack_exports__, __webpack_require__) {
|
|
63
|
+
var _node_modules_pnpm_rsbuild_core_2_1_13_node_modules_rsbuild_core_compiled_css_loader_noSourceMaps_js__rspack_import_0 = __webpack_require__(5879);
|
|
64
|
+
var _node_modules_pnpm_rsbuild_core_2_1_13_node_modules_rsbuild_core_compiled_css_loader_noSourceMaps_js__rspack_import_0_default = /*#__PURE__*/ __webpack_require__.n(_node_modules_pnpm_rsbuild_core_2_1_13_node_modules_rsbuild_core_compiled_css_loader_noSourceMaps_js__rspack_import_0);
|
|
65
|
+
var _node_modules_pnpm_rsbuild_core_2_1_13_node_modules_rsbuild_core_compiled_css_loader_api_js__rspack_import_1 = __webpack_require__(2968);
|
|
66
|
+
var _node_modules_pnpm_rsbuild_core_2_1_13_node_modules_rsbuild_core_compiled_css_loader_api_js__rspack_import_1_default = /*#__PURE__*/ __webpack_require__.n(_node_modules_pnpm_rsbuild_core_2_1_13_node_modules_rsbuild_core_compiled_css_loader_api_js__rspack_import_1);
|
|
67
|
+
var ___CSS_LOADER_EXPORT___ = _node_modules_pnpm_rsbuild_core_2_1_13_node_modules_rsbuild_core_compiled_css_loader_api_js__rspack_import_1_default()(_node_modules_pnpm_rsbuild_core_2_1_13_node_modules_rsbuild_core_compiled_css_loader_noSourceMaps_js__rspack_import_0_default());
|
|
68
68
|
___CSS_LOADER_EXPORT___.push([
|
|
69
69
|
module.id,
|
|
70
70
|
`.easyx-editor {
|
|
@@ -213,11 +213,18 @@ __webpack_require__.add({
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
.easyx-editor.easyx-editor-scroll .easyx-editor-content {
|
|
216
|
+
flex-direction: column;
|
|
216
217
|
flex: auto;
|
|
217
218
|
min-height: 0;
|
|
219
|
+
display: flex;
|
|
218
220
|
overflow-y: auto;
|
|
219
221
|
}
|
|
220
222
|
|
|
223
|
+
.easyx-editor.easyx-editor-scroll .easyx-editor-content > .ProseMirror {
|
|
224
|
+
flex: 1 0 auto;
|
|
225
|
+
min-height: 0;
|
|
226
|
+
}
|
|
227
|
+
|
|
221
228
|
.easyx-editor-resize-handle {
|
|
222
229
|
cursor: ns-resize;
|
|
223
230
|
z-index: 5;
|
|
@@ -270,21 +277,21 @@ __webpack_require__.add({
|
|
|
270
277
|
}
|
|
271
278
|
|
|
272
279
|
.easyx-editor-content {
|
|
273
|
-
padding: var(--easyx-editor-padding);
|
|
274
|
-
min-height: var(--easyx-editor-min-height);
|
|
275
280
|
word-break: break-word;
|
|
276
281
|
outline: none;
|
|
277
282
|
}
|
|
278
283
|
|
|
279
|
-
.easyx-editor-content .ProseMirror {
|
|
284
|
+
.easyx-editor-content > .ProseMirror {
|
|
285
|
+
padding: var(--easyx-editor-padding);
|
|
286
|
+
min-height: var(--easyx-editor-min-height);
|
|
280
287
|
outline: none;
|
|
281
288
|
}
|
|
282
289
|
|
|
283
|
-
.easyx-editor-content > :first-child {
|
|
290
|
+
.easyx-editor-content > .ProseMirror > :first-child {
|
|
284
291
|
margin-top: 0;
|
|
285
292
|
}
|
|
286
293
|
|
|
287
|
-
.easyx-editor-content > :last-child {
|
|
294
|
+
.easyx-editor-content > .ProseMirror > :last-child {
|
|
288
295
|
margin-bottom: 0;
|
|
289
296
|
}
|
|
290
297
|
|
|
@@ -1750,7 +1757,7 @@ __webpack_require__.add({
|
|
|
1750
1757
|
A: __rspack_default_export
|
|
1751
1758
|
});
|
|
1752
1759
|
},
|
|
1753
|
-
|
|
1760
|
+
2968 (module) {
|
|
1754
1761
|
module.exports = function(cssWithMappingToString) {
|
|
1755
1762
|
var list = [];
|
|
1756
1763
|
list.toString = function() {
|
|
@@ -1803,12 +1810,12 @@ __webpack_require__.add({
|
|
|
1803
1810
|
return list;
|
|
1804
1811
|
};
|
|
1805
1812
|
},
|
|
1806
|
-
|
|
1813
|
+
5879 (module) {
|
|
1807
1814
|
module.exports = function(i) {
|
|
1808
1815
|
return i[1];
|
|
1809
1816
|
};
|
|
1810
1817
|
},
|
|
1811
|
-
|
|
1818
|
+
9987 (module) {
|
|
1812
1819
|
var stylesInDOM = [];
|
|
1813
1820
|
function getIndexByIdentifier(identifier) {
|
|
1814
1821
|
var result = -1;
|
|
@@ -1886,7 +1893,7 @@ __webpack_require__.add({
|
|
|
1886
1893
|
};
|
|
1887
1894
|
};
|
|
1888
1895
|
},
|
|
1889
|
-
|
|
1896
|
+
4324 (module) {
|
|
1890
1897
|
var memo = {};
|
|
1891
1898
|
function getTarget(target) {
|
|
1892
1899
|
if (void 0 === memo[target]) {
|
|
@@ -1907,7 +1914,7 @@ __webpack_require__.add({
|
|
|
1907
1914
|
}
|
|
1908
1915
|
module.exports = insertBySelector;
|
|
1909
1916
|
},
|
|
1910
|
-
|
|
1917
|
+
5927 (module) {
|
|
1911
1918
|
function insertStyleElement(options) {
|
|
1912
1919
|
var element = document.createElement("style");
|
|
1913
1920
|
options.setAttributes(element, options.attributes);
|
|
@@ -1916,14 +1923,14 @@ __webpack_require__.add({
|
|
|
1916
1923
|
}
|
|
1917
1924
|
module.exports = insertStyleElement;
|
|
1918
1925
|
},
|
|
1919
|
-
|
|
1926
|
+
2723 (module, __unused_rspack_exports, __webpack_require__) {
|
|
1920
1927
|
function setAttributesWithoutAttributes(styleElement) {
|
|
1921
1928
|
var nonce = __webpack_require__.nc;
|
|
1922
1929
|
if (nonce) styleElement.setAttribute("nonce", nonce);
|
|
1923
1930
|
}
|
|
1924
1931
|
module.exports = setAttributesWithoutAttributes;
|
|
1925
1932
|
},
|
|
1926
|
-
|
|
1933
|
+
24 (module) {
|
|
1927
1934
|
function apply(styleElement, options, obj) {
|
|
1928
1935
|
var css = "";
|
|
1929
1936
|
if (obj.supports) css += "@supports (".concat(obj.supports, ") {");
|
|
@@ -1959,7 +1966,7 @@ __webpack_require__.add({
|
|
|
1959
1966
|
}
|
|
1960
1967
|
module.exports = domAPI;
|
|
1961
1968
|
},
|
|
1962
|
-
|
|
1969
|
+
9508 (module) {
|
|
1963
1970
|
function styleTagTransform(css, styleElement) {
|
|
1964
1971
|
if (styleElement.styleSheet) styleElement.styleSheet.cssText = css;
|
|
1965
1972
|
else {
|
|
@@ -1970,19 +1977,19 @@ __webpack_require__.add({
|
|
|
1970
1977
|
module.exports = styleTagTransform;
|
|
1971
1978
|
}
|
|
1972
1979
|
});
|
|
1973
|
-
const injectStylesIntoStyleTag = __webpack_require__("
|
|
1980
|
+
const injectStylesIntoStyleTag = __webpack_require__("9987");
|
|
1974
1981
|
var injectStylesIntoStyleTag_default = /*#__PURE__*/ __webpack_require__.n(injectStylesIntoStyleTag);
|
|
1975
|
-
const styleDomAPI = __webpack_require__("
|
|
1982
|
+
const styleDomAPI = __webpack_require__("24");
|
|
1976
1983
|
var styleDomAPI_default = /*#__PURE__*/ __webpack_require__.n(styleDomAPI);
|
|
1977
|
-
const insertBySelector = __webpack_require__("
|
|
1984
|
+
const insertBySelector = __webpack_require__("4324");
|
|
1978
1985
|
var insertBySelector_default = /*#__PURE__*/ __webpack_require__.n(insertBySelector);
|
|
1979
|
-
const setAttributesWithoutAttributes = __webpack_require__("
|
|
1986
|
+
const setAttributesWithoutAttributes = __webpack_require__("2723");
|
|
1980
1987
|
var setAttributesWithoutAttributes_default = /*#__PURE__*/ __webpack_require__.n(setAttributesWithoutAttributes);
|
|
1981
|
-
const insertStyleElement = __webpack_require__("
|
|
1988
|
+
const insertStyleElement = __webpack_require__("5927");
|
|
1982
1989
|
var insertStyleElement_default = /*#__PURE__*/ __webpack_require__.n(insertStyleElement);
|
|
1983
|
-
const styleTagTransform = __webpack_require__("
|
|
1990
|
+
const styleTagTransform = __webpack_require__("9508");
|
|
1984
1991
|
var styleTagTransform_default = /*#__PURE__*/ __webpack_require__.n(styleTagTransform);
|
|
1985
|
-
const styles_0 = __webpack_require__("
|
|
1992
|
+
const styles_0 = __webpack_require__("2702");
|
|
1986
1993
|
var styles_options = {};
|
|
1987
1994
|
styles_options.styleTagTransform = styleTagTransform_default();
|
|
1988
1995
|
styles_options.setAttributes = setAttributesWithoutAttributes_default();
|
package/dist/types.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export type
|
|
2
|
-
export type
|
|
1
|
+
export type EditorContentType = string;
|
|
2
|
+
export type EditorTheme = 'light' | 'dark';
|
|
3
3
|
/** 图片配置:在通用媒体配置基础上增加图片专属选项 */
|
|
4
|
-
export type
|
|
4
|
+
export type EditorImageConfig = MediaUploadConfig & {
|
|
5
5
|
/** 是否开启图片拖拽缩放,默认 true */
|
|
6
6
|
resizable?: boolean;
|
|
7
7
|
};
|
|
8
8
|
/** 编辑器初始化配置 */
|
|
9
|
-
export interface
|
|
9
|
+
export interface EditorOptions {
|
|
10
10
|
placeholder?: string;
|
|
11
11
|
readOnly?: boolean;
|
|
12
12
|
autoFocus?: boolean;
|
|
13
|
-
defaultContent?:
|
|
14
|
-
defaultTheme?:
|
|
15
|
-
image?:
|
|
13
|
+
defaultContent?: EditorContentType;
|
|
14
|
+
defaultTheme?: EditorTheme;
|
|
15
|
+
image?: EditorImageConfig;
|
|
16
16
|
video?: MediaUploadConfig;
|
|
17
17
|
audio?: MediaUploadConfig;
|
|
18
18
|
attachment?: MediaUploadConfig;
|
|
@@ -24,7 +24,7 @@ export interface EasyxEditorOptions {
|
|
|
24
24
|
maxHeight?: number | string;
|
|
25
25
|
/** 是否启用右下角拖拽手柄调节高度,受 minHeight / maxHeight 约束 */
|
|
26
26
|
resizable?: boolean;
|
|
27
|
-
onChange?: (content:
|
|
27
|
+
onChange?: (content: EditorContentType) => void;
|
|
28
28
|
onReady?: () => void;
|
|
29
29
|
onFocus?: () => void;
|
|
30
30
|
onBlur?: () => void;
|
|
@@ -52,9 +52,9 @@ export interface MediaListResult {
|
|
|
52
52
|
total: number;
|
|
53
53
|
}
|
|
54
54
|
/** 上传进度回调 */
|
|
55
|
-
export type
|
|
55
|
+
export type MediaUploadProgress = (progress: number) => void;
|
|
56
56
|
/** 单个媒体类型的上传 + 列表配置 */
|
|
57
57
|
export interface MediaUploadConfig {
|
|
58
|
-
upload: (file: File, onProgress?:
|
|
58
|
+
upload: (file: File, onProgress?: MediaUploadProgress) => Promise<MediaItem>;
|
|
59
59
|
getList?: (params: MediaListParams) => Promise<MediaListResult>;
|
|
60
60
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type EditorEventHandler = (...args: unknown[]) => void;
|
|
2
2
|
export declare class EventEmitter {
|
|
3
3
|
private handlers;
|
|
4
|
-
on(event: string, handler:
|
|
5
|
-
off(event: string, handler:
|
|
6
|
-
once(event: string, handler:
|
|
4
|
+
on(event: string, handler: EditorEventHandler): void;
|
|
5
|
+
off(event: string, handler: EditorEventHandler): void;
|
|
6
|
+
once(event: string, handler: EditorEventHandler): void;
|
|
7
7
|
emit(event: string, ...args: unknown[]): void;
|
|
8
8
|
removeAllListeners(): void;
|
|
9
9
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Editor } from '@tiptap/core';
|
|
2
|
-
import type {
|
|
2
|
+
import type { EditorOptions } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* 按文件类型路由到对应媒体的 upload 并插入。
|
|
5
5
|
* 用于编辑器内容区粘贴 / 拖入上传;返回 true 表示已接管该文件。
|
|
6
6
|
* @param pos 插入位置,缺省使用当前选区
|
|
7
7
|
* @param onError 上传失败回调(默认静默)
|
|
8
8
|
*/
|
|
9
|
-
export declare function routeMediaUpload(file: File, editor: Editor, options:
|
|
9
|
+
export declare function routeMediaUpload(file: File, editor: Editor, options: EditorOptions, pos?: number, onError?: (file: File, error: unknown) => void): boolean;
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easyx/editor",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "零框架依赖的 Tiptap 富文本编辑器,内置工具栏、气泡菜单、媒体上传与表格增强",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"exports": {
|
|
7
8
|
".": {
|
|
@@ -30,14 +31,14 @@
|
|
|
30
31
|
"@tiptap/extension-list": "^3.27.1",
|
|
31
32
|
"@tiptap/extension-subscript": "^3.27.1",
|
|
32
33
|
"@tiptap/extension-superscript": "^3.27.1",
|
|
34
|
+
"@easyx/tiptap-table-plus": "1.0.1",
|
|
33
35
|
"@tiptap/extension-table": "^3.27.1",
|
|
34
36
|
"@tiptap/extension-text-align": "^3.27.1",
|
|
35
37
|
"@tiptap/extension-text-style": "^3.27.1",
|
|
36
38
|
"@tiptap/extension-typography": "^3.27.1",
|
|
37
39
|
"@tiptap/extensions": "^3.27.1",
|
|
38
40
|
"@tiptap/pm": "^3.27.1",
|
|
39
|
-
"@tiptap/starter-kit": "^3.27.1"
|
|
40
|
-
"@easyx/tiptap-table-plus": "1.0.0"
|
|
41
|
+
"@tiptap/starter-kit": "^3.27.1"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
44
|
"@rsbuild/plugin-sass": "^2.0.1",
|