@easyx/editor 1.1.2 → 2.0.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 +32 -118
- package/dist/core/create-editor.d.ts +2 -2
- package/dist/index.cjs +21 -21
- package/dist/index.d.ts +9 -9
- package/dist/index.js +21 -21
- 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 {
|
|
@@ -1691,7 +1691,7 @@ var __webpack_modules__ = {
|
|
|
1691
1691
|
A: __rspack_default_export
|
|
1692
1692
|
});
|
|
1693
1693
|
},
|
|
1694
|
-
|
|
1694
|
+
968 (module) {
|
|
1695
1695
|
module.exports = function(cssWithMappingToString) {
|
|
1696
1696
|
var list = [];
|
|
1697
1697
|
list.toString = function() {
|
|
@@ -1744,12 +1744,12 @@ var __webpack_modules__ = {
|
|
|
1744
1744
|
return list;
|
|
1745
1745
|
};
|
|
1746
1746
|
},
|
|
1747
|
-
|
|
1747
|
+
879 (module) {
|
|
1748
1748
|
module.exports = function(i) {
|
|
1749
1749
|
return i[1];
|
|
1750
1750
|
};
|
|
1751
1751
|
},
|
|
1752
|
-
|
|
1752
|
+
987 (module) {
|
|
1753
1753
|
var stylesInDOM = [];
|
|
1754
1754
|
function getIndexByIdentifier(identifier) {
|
|
1755
1755
|
var result = -1;
|
|
@@ -1827,7 +1827,7 @@ var __webpack_modules__ = {
|
|
|
1827
1827
|
};
|
|
1828
1828
|
};
|
|
1829
1829
|
},
|
|
1830
|
-
|
|
1830
|
+
324 (module) {
|
|
1831
1831
|
var memo = {};
|
|
1832
1832
|
function getTarget(target) {
|
|
1833
1833
|
if (void 0 === memo[target]) {
|
|
@@ -1848,7 +1848,7 @@ var __webpack_modules__ = {
|
|
|
1848
1848
|
}
|
|
1849
1849
|
module.exports = insertBySelector;
|
|
1850
1850
|
},
|
|
1851
|
-
|
|
1851
|
+
927 (module) {
|
|
1852
1852
|
function insertStyleElement(options) {
|
|
1853
1853
|
var element = document.createElement("style");
|
|
1854
1854
|
options.setAttributes(element, options.attributes);
|
|
@@ -1857,14 +1857,14 @@ var __webpack_modules__ = {
|
|
|
1857
1857
|
}
|
|
1858
1858
|
module.exports = insertStyleElement;
|
|
1859
1859
|
},
|
|
1860
|
-
|
|
1860
|
+
723 (module, __unused_rspack_exports, __webpack_require__) {
|
|
1861
1861
|
function setAttributesWithoutAttributes(styleElement) {
|
|
1862
1862
|
var nonce = __webpack_require__.nc;
|
|
1863
1863
|
if (nonce) styleElement.setAttribute("nonce", nonce);
|
|
1864
1864
|
}
|
|
1865
1865
|
module.exports = setAttributesWithoutAttributes;
|
|
1866
1866
|
},
|
|
1867
|
-
|
|
1867
|
+
24 (module) {
|
|
1868
1868
|
function apply(styleElement, options, obj) {
|
|
1869
1869
|
var css = "";
|
|
1870
1870
|
if (obj.supports) css += "@supports (".concat(obj.supports, ") {");
|
|
@@ -1900,7 +1900,7 @@ var __webpack_modules__ = {
|
|
|
1900
1900
|
}
|
|
1901
1901
|
module.exports = domAPI;
|
|
1902
1902
|
},
|
|
1903
|
-
|
|
1903
|
+
508 (module) {
|
|
1904
1904
|
function styleTagTransform(css, styleElement) {
|
|
1905
1905
|
if (styleElement.styleSheet) styleElement.styleSheet.cssText = css;
|
|
1906
1906
|
else {
|
|
@@ -1965,19 +1965,19 @@ var __webpack_exports__ = {};
|
|
|
1965
1965
|
__webpack_require__.d(__webpack_exports__, {
|
|
1966
1966
|
createEditor: ()=>createEditor
|
|
1967
1967
|
});
|
|
1968
|
-
var injectStylesIntoStyleTag = __webpack_require__(
|
|
1968
|
+
var injectStylesIntoStyleTag = __webpack_require__(987);
|
|
1969
1969
|
var injectStylesIntoStyleTag_default = /*#__PURE__*/ __webpack_require__.n(injectStylesIntoStyleTag);
|
|
1970
|
-
var styleDomAPI = __webpack_require__(
|
|
1970
|
+
var styleDomAPI = __webpack_require__(24);
|
|
1971
1971
|
var styleDomAPI_default = /*#__PURE__*/ __webpack_require__.n(styleDomAPI);
|
|
1972
|
-
var insertBySelector = __webpack_require__(
|
|
1972
|
+
var insertBySelector = __webpack_require__(324);
|
|
1973
1973
|
var insertBySelector_default = /*#__PURE__*/ __webpack_require__.n(insertBySelector);
|
|
1974
|
-
var setAttributesWithoutAttributes = __webpack_require__(
|
|
1974
|
+
var setAttributesWithoutAttributes = __webpack_require__(723);
|
|
1975
1975
|
var setAttributesWithoutAttributes_default = /*#__PURE__*/ __webpack_require__.n(setAttributesWithoutAttributes);
|
|
1976
|
-
var insertStyleElement = __webpack_require__(
|
|
1976
|
+
var insertStyleElement = __webpack_require__(927);
|
|
1977
1977
|
var insertStyleElement_default = /*#__PURE__*/ __webpack_require__.n(insertStyleElement);
|
|
1978
|
-
var styleTagTransform = __webpack_require__(
|
|
1978
|
+
var styleTagTransform = __webpack_require__(508);
|
|
1979
1979
|
var styleTagTransform_default = /*#__PURE__*/ __webpack_require__.n(styleTagTransform);
|
|
1980
|
-
var styles = __webpack_require__(
|
|
1980
|
+
var styles = __webpack_require__(702);
|
|
1981
1981
|
var styles_options = {};
|
|
1982
1982
|
styles_options.styleTagTransform = styleTagTransform_default();
|
|
1983
1983
|
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 {
|
|
@@ -1750,7 +1750,7 @@ __webpack_require__.add({
|
|
|
1750
1750
|
A: __rspack_default_export
|
|
1751
1751
|
});
|
|
1752
1752
|
},
|
|
1753
|
-
|
|
1753
|
+
2968 (module) {
|
|
1754
1754
|
module.exports = function(cssWithMappingToString) {
|
|
1755
1755
|
var list = [];
|
|
1756
1756
|
list.toString = function() {
|
|
@@ -1803,12 +1803,12 @@ __webpack_require__.add({
|
|
|
1803
1803
|
return list;
|
|
1804
1804
|
};
|
|
1805
1805
|
},
|
|
1806
|
-
|
|
1806
|
+
5879 (module) {
|
|
1807
1807
|
module.exports = function(i) {
|
|
1808
1808
|
return i[1];
|
|
1809
1809
|
};
|
|
1810
1810
|
},
|
|
1811
|
-
|
|
1811
|
+
9987 (module) {
|
|
1812
1812
|
var stylesInDOM = [];
|
|
1813
1813
|
function getIndexByIdentifier(identifier) {
|
|
1814
1814
|
var result = -1;
|
|
@@ -1886,7 +1886,7 @@ __webpack_require__.add({
|
|
|
1886
1886
|
};
|
|
1887
1887
|
};
|
|
1888
1888
|
},
|
|
1889
|
-
|
|
1889
|
+
4324 (module) {
|
|
1890
1890
|
var memo = {};
|
|
1891
1891
|
function getTarget(target) {
|
|
1892
1892
|
if (void 0 === memo[target]) {
|
|
@@ -1907,7 +1907,7 @@ __webpack_require__.add({
|
|
|
1907
1907
|
}
|
|
1908
1908
|
module.exports = insertBySelector;
|
|
1909
1909
|
},
|
|
1910
|
-
|
|
1910
|
+
5927 (module) {
|
|
1911
1911
|
function insertStyleElement(options) {
|
|
1912
1912
|
var element = document.createElement("style");
|
|
1913
1913
|
options.setAttributes(element, options.attributes);
|
|
@@ -1916,14 +1916,14 @@ __webpack_require__.add({
|
|
|
1916
1916
|
}
|
|
1917
1917
|
module.exports = insertStyleElement;
|
|
1918
1918
|
},
|
|
1919
|
-
|
|
1919
|
+
2723 (module, __unused_rspack_exports, __webpack_require__) {
|
|
1920
1920
|
function setAttributesWithoutAttributes(styleElement) {
|
|
1921
1921
|
var nonce = __webpack_require__.nc;
|
|
1922
1922
|
if (nonce) styleElement.setAttribute("nonce", nonce);
|
|
1923
1923
|
}
|
|
1924
1924
|
module.exports = setAttributesWithoutAttributes;
|
|
1925
1925
|
},
|
|
1926
|
-
|
|
1926
|
+
24 (module) {
|
|
1927
1927
|
function apply(styleElement, options, obj) {
|
|
1928
1928
|
var css = "";
|
|
1929
1929
|
if (obj.supports) css += "@supports (".concat(obj.supports, ") {");
|
|
@@ -1959,7 +1959,7 @@ __webpack_require__.add({
|
|
|
1959
1959
|
}
|
|
1960
1960
|
module.exports = domAPI;
|
|
1961
1961
|
},
|
|
1962
|
-
|
|
1962
|
+
9508 (module) {
|
|
1963
1963
|
function styleTagTransform(css, styleElement) {
|
|
1964
1964
|
if (styleElement.styleSheet) styleElement.styleSheet.cssText = css;
|
|
1965
1965
|
else {
|
|
@@ -1970,19 +1970,19 @@ __webpack_require__.add({
|
|
|
1970
1970
|
module.exports = styleTagTransform;
|
|
1971
1971
|
}
|
|
1972
1972
|
});
|
|
1973
|
-
const injectStylesIntoStyleTag = __webpack_require__("
|
|
1973
|
+
const injectStylesIntoStyleTag = __webpack_require__("9987");
|
|
1974
1974
|
var injectStylesIntoStyleTag_default = /*#__PURE__*/ __webpack_require__.n(injectStylesIntoStyleTag);
|
|
1975
|
-
const styleDomAPI = __webpack_require__("
|
|
1975
|
+
const styleDomAPI = __webpack_require__("24");
|
|
1976
1976
|
var styleDomAPI_default = /*#__PURE__*/ __webpack_require__.n(styleDomAPI);
|
|
1977
|
-
const insertBySelector = __webpack_require__("
|
|
1977
|
+
const insertBySelector = __webpack_require__("4324");
|
|
1978
1978
|
var insertBySelector_default = /*#__PURE__*/ __webpack_require__.n(insertBySelector);
|
|
1979
|
-
const setAttributesWithoutAttributes = __webpack_require__("
|
|
1979
|
+
const setAttributesWithoutAttributes = __webpack_require__("2723");
|
|
1980
1980
|
var setAttributesWithoutAttributes_default = /*#__PURE__*/ __webpack_require__.n(setAttributesWithoutAttributes);
|
|
1981
|
-
const insertStyleElement = __webpack_require__("
|
|
1981
|
+
const insertStyleElement = __webpack_require__("5927");
|
|
1982
1982
|
var insertStyleElement_default = /*#__PURE__*/ __webpack_require__.n(insertStyleElement);
|
|
1983
|
-
const styleTagTransform = __webpack_require__("
|
|
1983
|
+
const styleTagTransform = __webpack_require__("9508");
|
|
1984
1984
|
var styleTagTransform_default = /*#__PURE__*/ __webpack_require__.n(styleTagTransform);
|
|
1985
|
-
const styles_0 = __webpack_require__("
|
|
1985
|
+
const styles_0 = __webpack_require__("2702");
|
|
1986
1986
|
var styles_options = {};
|
|
1987
1987
|
styles_options.styleTagTransform = styleTagTransform_default();
|
|
1988
1988
|
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.0",
|
|
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",
|