kyle-editor 1.0.0 → 1.0.2
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 +103 -69
- package/dist/keditor.cjs +849 -217
- package/dist/keditor.es.js +849 -217
- package/dist/keditor.umd.js +849 -217
- package/package.json +3 -7
- package/types/index.d.ts +136 -4
- package/docs/api.md +0 -223
- package/docs/index.md +0 -8
- package/docs/integration.md +0 -296
- package/docs/npm-publish.md +0 -412
- package/docs/upload-adapter.md +0 -186
- package/src/core/commands.js +0 -311
- package/src/core/editor.js +0 -795
- package/src/core/format.js +0 -64
- package/src/core/history.js +0 -92
- package/src/core/icons.js +0 -49
- package/src/core/paste.js +0 -140
- package/src/core/sanitize.js +0 -182
- package/src/core/selection.js +0 -129
- package/src/core/toolbar.js +0 -465
- package/src/core/utils.js +0 -95
- package/src/index.js +0 -33
- package/src/media/media.js +0 -331
- package/src/ui/bubble.js +0 -270
- package/src/ui/popover.js +0 -507
- package/src/ui/preview.js +0 -59
- package/src/ui/source.js +0 -97
- package/src/ui/styles.js +0 -447
- package/src/ui/toast.js +0 -56
- package/src/upload/adapters.js +0 -206
- package/src/upload/chunk-uploader.js +0 -193
- package/src/upload/fingerprint.js +0 -38
- package/src/vue/index.js +0 -104
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kyle-editor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "轻量、美观的微信公众号风格富文本编辑器(纯前端,支持图片/视频分片上传、HTML 源码模式),可通过 <script> 引入或作为 Vue 3 组件安装。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/keditor.cjs",
|
|
@@ -24,9 +24,7 @@
|
|
|
24
24
|
"sideEffects": true,
|
|
25
25
|
"files": [
|
|
26
26
|
"dist",
|
|
27
|
-
"src",
|
|
28
27
|
"types",
|
|
29
|
-
"docs",
|
|
30
28
|
"README.md",
|
|
31
29
|
"LICENSE"
|
|
32
30
|
],
|
|
@@ -41,7 +39,7 @@
|
|
|
41
39
|
"test:types": "node test/check-types.mjs",
|
|
42
40
|
"test:package": "node test/check-package.mjs",
|
|
43
41
|
"test:install": "node test/check-install.mjs",
|
|
44
|
-
"test:visual": "node test/shoot.mjs rich,uploading,bubble,resize,align,source,preview,color,heading,media,link,scroll,scroll2",
|
|
42
|
+
"test:visual": "node test/shoot.mjs rich,uploading,bubble,resize,align,source,preview,color,heading,media,link,custom,customload,customerr,scroll,scroll2,http://127.0.0.1:5178/demo/vue.html",
|
|
45
43
|
"clean": "rm -rf dist",
|
|
46
44
|
"verify": "npm run build && npm test && npm run test:pages && npm run test:types && npm run test:package",
|
|
47
45
|
"pack:check": "npm run build && npm run test:package && npm pack --dry-run",
|
|
@@ -54,12 +52,10 @@
|
|
|
54
52
|
"editor",
|
|
55
53
|
"wechat",
|
|
56
54
|
"富文本编辑器",
|
|
57
|
-
"chunk-upload",
|
|
58
|
-
"分片上传",
|
|
59
55
|
"vue3"
|
|
60
56
|
],
|
|
61
57
|
"license": "MIT",
|
|
62
|
-
"author": "kyle <
|
|
58
|
+
"author": "kyle <1399860604@qq.com>",
|
|
63
59
|
"publishConfig": {
|
|
64
60
|
"access": "public",
|
|
65
61
|
"registry": "https://registry.npmjs.org"
|
package/types/index.d.ts
CHANGED
|
@@ -130,8 +130,8 @@ export interface UploadHookPayload {
|
|
|
130
130
|
error?: Error
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
/**
|
|
134
|
-
export type
|
|
133
|
+
/** 内置工具栏项名称 */
|
|
134
|
+
export type BuiltinToolbarItem =
|
|
135
135
|
| 'undo' | 'redo' | 'heading' | 'fontsize'
|
|
136
136
|
| 'bold' | 'italic' | 'underline' | 'strike'
|
|
137
137
|
| 'foreColor' | 'backColor'
|
|
@@ -141,6 +141,112 @@ export type ToolbarItem =
|
|
|
141
141
|
| 'source' | 'preview' | 'fullscreen'
|
|
142
142
|
| '|' | ':tail'
|
|
143
143
|
|
|
144
|
+
/** 工具栏项:内置名称、分隔符 `|`、`:tail`,或 customButtons 里定义的自定义按钮 name */
|
|
145
|
+
export type ToolbarItem = BuiltinToolbarItem | (string & {})
|
|
146
|
+
|
|
147
|
+
/* ------------------------------ 自定义工具栏按钮 ------------------------------ */
|
|
148
|
+
|
|
149
|
+
/** 下拉选项;也接受纯字符串或接口原始对象(自动识别 value/id/key、label/name/title 等常见字段) */
|
|
150
|
+
export interface CustomButtonOption {
|
|
151
|
+
value?: string | number
|
|
152
|
+
label?: string
|
|
153
|
+
/** 副标题说明 */
|
|
154
|
+
desc?: string
|
|
155
|
+
/** 该项自带的跳转地址(link:true 时直接使用) */
|
|
156
|
+
url?: string
|
|
157
|
+
/** 分组名,同组选项会归到一个小标题下 */
|
|
158
|
+
group?: string
|
|
159
|
+
/** 选中后直接插入的 HTML(insert:'html' 或 auto 且无链接时使用) */
|
|
160
|
+
html?: string
|
|
161
|
+
disabled?: boolean
|
|
162
|
+
[key: string]: unknown
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** 选中后的跳转链接配置;字符串模板支持 {value} {label} 及选项任意字段占位符 */
|
|
166
|
+
export type CustomButtonLink =
|
|
167
|
+
| boolean
|
|
168
|
+
| string
|
|
169
|
+
| {
|
|
170
|
+
/** insert = 插入到正文(默认);open = 直接新窗口打开 */
|
|
171
|
+
mode?: 'insert' | 'open'
|
|
172
|
+
url?: string | ((item: CustomButtonOption, editor: KEditor) => string)
|
|
173
|
+
text?: string | ((item: CustomButtonOption, editor: KEditor) => string)
|
|
174
|
+
title?: string | ((item: CustomButtonOption, editor: KEditor) => string)
|
|
175
|
+
target?: '_blank' | '_self' | boolean
|
|
176
|
+
}
|
|
177
|
+
| ((item: CustomButtonOption, editor: KEditor) => string | { mode?: 'insert' | 'open'; url?: string; text?: string; target?: '_blank' | '_self' } | null)
|
|
178
|
+
|
|
179
|
+
export interface CustomButtonFetchOptions {
|
|
180
|
+
method?: string
|
|
181
|
+
headers?: Record<string, string>
|
|
182
|
+
body?: BodyInit | null
|
|
183
|
+
credentials?: RequestCredentials
|
|
184
|
+
/** 超时毫秒,默认 10000 */
|
|
185
|
+
timeout?: number
|
|
186
|
+
/** 自定义 fetch 实现(如 axios 包装) */
|
|
187
|
+
fetch?: typeof fetch
|
|
188
|
+
/** 自定义响应解析,默认 res.json() */
|
|
189
|
+
parser?: (res: Response) => unknown | Promise<unknown>
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export interface CustomButtonSpec {
|
|
193
|
+
/** 唯一标识,用于在 toolbar 数组中定位;也作为事件载荷的 name */
|
|
194
|
+
name: string
|
|
195
|
+
/** select = 下拉选择(默认);button = 普通按钮 */
|
|
196
|
+
type?: 'select' | 'button'
|
|
197
|
+
/** tooltip */
|
|
198
|
+
title?: string
|
|
199
|
+
/** 按钮文字;下拉按钮选中后会替换为选项文字 */
|
|
200
|
+
text?: string
|
|
201
|
+
/** 未选中时的占位文字,默认取 text */
|
|
202
|
+
placeholder?: string
|
|
203
|
+
/** 内置图标名或原始 SVG 字符串 */
|
|
204
|
+
icon?: string
|
|
205
|
+
/** 面板宽度 px(200–420) */
|
|
206
|
+
width?: number
|
|
207
|
+
/** 面板内显示搜索框(客户端过滤) */
|
|
208
|
+
searchable?: boolean
|
|
209
|
+
/** 面板右上角提示文字 */
|
|
210
|
+
note?: string
|
|
211
|
+
/** 空数据提示 */
|
|
212
|
+
emptyText?: string
|
|
213
|
+
/** 缓存接口结果,默认 true;面板内刷新按钮可强制重新请求 */
|
|
214
|
+
cache?: boolean
|
|
215
|
+
/** 记住选中项并在按钮上回显,默认 true */
|
|
216
|
+
keepValue?: boolean
|
|
217
|
+
|
|
218
|
+
/** 数据源①:静态配置 */
|
|
219
|
+
options?: CustomButtonOption[] | string[]
|
|
220
|
+
/** 数据源②:自定义加载函数(可返回 Promise) */
|
|
221
|
+
load?: (editor: KEditor) => CustomButtonOption[] | Promise<CustomButtonOption[] | unknown> | unknown
|
|
222
|
+
/** 数据源③:接口地址,内部 fetch;优先级 load > url > options */
|
|
223
|
+
url?: string
|
|
224
|
+
fetchOptions?: CustomButtonFetchOptions
|
|
225
|
+
/** 从接口响应中提取数组;默认自动识别 items/list/data/rows/records/result(含一层嵌套) */
|
|
226
|
+
pick?: (payload: unknown, editor: KEditor) => unknown
|
|
227
|
+
|
|
228
|
+
/** 选中后的跳转链接配置 */
|
|
229
|
+
link?: CustomButtonLink
|
|
230
|
+
/** 插入方式:auto(默认,链接 > html > 纯文本)| link | html | text | false(不改正文) */
|
|
231
|
+
insert?: 'auto' | 'link' | 'html' | 'text' | false | 'none'
|
|
232
|
+
/** 自定义选中处理;返回 false 表示已自行处理,跳过默认插入 */
|
|
233
|
+
onSelect?: (item: CustomButtonOption, ctx: {
|
|
234
|
+
editor: KEditor
|
|
235
|
+
item: CustomButtonOption
|
|
236
|
+
link: { mode: 'insert' | 'open'; url: string; text: string; target: '_blank' | '_self'; title: string } | null
|
|
237
|
+
insertLink: (override?: Record<string, unknown>) => void
|
|
238
|
+
insertHtml: (html: string) => void
|
|
239
|
+
insertText: (text: string) => void
|
|
240
|
+
open: (url?: string, target?: string) => void
|
|
241
|
+
}) => void | boolean | Promise<void | boolean>
|
|
242
|
+
/** type:'button' 的点击处理 */
|
|
243
|
+
onClick?: (ctx: { editor: KEditor; name: string }) => void | Promise<void>
|
|
244
|
+
/** 高亮条件 */
|
|
245
|
+
active?: (state: EditorState, editor: KEditor) => boolean
|
|
246
|
+
/** 可用条件 */
|
|
247
|
+
enabled?: (state: EditorState, editor: KEditor) => boolean
|
|
248
|
+
}
|
|
249
|
+
|
|
144
250
|
export interface KEditorOptions {
|
|
145
251
|
value?: string
|
|
146
252
|
placeholder?: string
|
|
@@ -151,8 +257,10 @@ export interface KEditorOptions {
|
|
|
151
257
|
primaryColor?: string
|
|
152
258
|
/** 正文版心宽度,默认 677(公众号) */
|
|
153
259
|
paperWidth?: number
|
|
154
|
-
/** 工具栏配置;false
|
|
260
|
+
/** 工具栏配置;false 隐藏。留空且配置了 customButtons 时,自定义按钮自动追加到默认工具栏 */
|
|
155
261
|
toolbar?: ToolbarItem[] | boolean
|
|
262
|
+
/** 自定义工具栏按钮(下拉选择,数据可静态配置或从接口读取) */
|
|
263
|
+
customButtons?: CustomButtonSpec[]
|
|
156
264
|
hideToolbar?: boolean
|
|
157
265
|
hideStatusbar?: boolean
|
|
158
266
|
readOnly?: boolean
|
|
@@ -223,6 +331,8 @@ export interface EditorEventMap {
|
|
|
223
331
|
uploadcancel: [{ file: File; kind: 'image' | 'video' }]
|
|
224
332
|
insertmedia: [{ kind: 'image' | 'video'; url: string; node: HTMLElement }]
|
|
225
333
|
sourcechange: [{ mode: 'source' | 'visual' }]
|
|
334
|
+
customselect: [{ name: string; item: CustomButtonOption; link: { mode: 'insert' | 'open'; url: string; text: string; target: string; title: string } | null; action: 'link' | 'html' | 'text' | 'open' | 'none'; editor: KEditor }]
|
|
335
|
+
customclick: [{ name: string; editor: KEditor }]
|
|
226
336
|
}
|
|
227
337
|
|
|
228
338
|
/* ------------------------------ 实例 ------------------------------ */
|
|
@@ -268,7 +378,18 @@ export declare class KEditor {
|
|
|
268
378
|
tasks: Map<string, unknown>
|
|
269
379
|
}
|
|
270
380
|
readonly uploader: ChunkUploader
|
|
271
|
-
readonly toolbar: {
|
|
381
|
+
readonly toolbar: {
|
|
382
|
+
el: HTMLElement
|
|
383
|
+
buttons: Map<string, HTMLElement>
|
|
384
|
+
custom: Map<string, { spec: CustomButtonSpec; button: HTMLElement | null }>
|
|
385
|
+
openLink(): void
|
|
386
|
+
openMedia(kind: 'image' | 'video'): void
|
|
387
|
+
openTable(): void
|
|
388
|
+
openCustom(name: string): void
|
|
389
|
+
addButton(spec: CustomButtonSpec, options?: { at?: number }): HTMLElement | null
|
|
390
|
+
removeButton(name: string): boolean
|
|
391
|
+
setButtonOptions(name: string, items: unknown): CustomButtonOption[]
|
|
392
|
+
}
|
|
272
393
|
readonly popover: { el: HTMLElement; open: (...args: unknown[]) => void; close(): void; isOpen: boolean }
|
|
273
394
|
readonly bubble: { el: HTMLElement; show(node: HTMLElement): void; hide(): void }
|
|
274
395
|
readonly source: { el: HTMLElement; show(html: string): void; apply(opts?: { silent?: boolean }): void }
|
|
@@ -306,6 +427,15 @@ export declare class KEditor {
|
|
|
306
427
|
insertVideo(url: string, label?: string): HTMLElement
|
|
307
428
|
cancelUploads(): this
|
|
308
429
|
|
|
430
|
+
/** 运行时新增自定义按钮,返回按钮 DOM */
|
|
431
|
+
addButton(spec: CustomButtonSpec, options?: { at?: number }): HTMLElement | null
|
|
432
|
+
removeButton(name: string): boolean
|
|
433
|
+
/** 外部灌入下拉数据(接口在编辑器之外请求时使用) */
|
|
434
|
+
setButtonOptions(name: string, items: CustomButtonOption[] | string[]): CustomButtonOption[]
|
|
435
|
+
getButtonValue(name: string): CustomButtonOption | null
|
|
436
|
+
setButtonValue(name: string, value: string | number): CustomButtonOption | null
|
|
437
|
+
reportError(type: string, error: unknown): this
|
|
438
|
+
|
|
309
439
|
toggleSource(): boolean
|
|
310
440
|
enterSource(): void
|
|
311
441
|
exitSource(): void
|
|
@@ -331,6 +461,8 @@ export declare const mount: typeof create
|
|
|
331
461
|
export declare function replace(target: HTMLElement | string, options?: KEditorOptions): KEditor
|
|
332
462
|
export declare const defaults: KEditorOptions
|
|
333
463
|
export declare const DEFAULT_TOOLBAR: ToolbarItem[]
|
|
464
|
+
export declare function normalizeCustomButtons(list: unknown): CustomButtonSpec[]
|
|
465
|
+
export declare function normalizeItems(raw: unknown): CustomButtonOption[]
|
|
334
466
|
export declare function exportHtml(html: string): string
|
|
335
467
|
|
|
336
468
|
export declare function sanitizeHtml(html: string, opts?: { allowVideoCard?: boolean }): string
|
package/docs/api.md
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
# API 参考
|
|
2
|
-
|
|
3
|
-
## 一、创建实例
|
|
4
|
-
|
|
5
|
-
```js
|
|
6
|
-
import { KEditor } from 'kyle-editor'
|
|
7
|
-
|
|
8
|
-
const editor = new KEditor('#editor', { /* options */ })
|
|
9
|
-
// 或
|
|
10
|
-
const editor = KEditor.create(el, options) // el: 选择器 / HTMLElement / Vue ref.$el
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
## 二、配置项 options
|
|
16
|
-
|
|
17
|
-
| 配置 | 类型 | 默认值 | 说明 |
|
|
18
|
-
|------|------|--------|------|
|
|
19
|
-
| `value` | `string` | `''` | 初始 HTML;留空时取挂载节点的 `innerHTML` |
|
|
20
|
-
| `placeholder` | `string` | `'开始撰写内容…'` | 空内容占位文案 |
|
|
21
|
-
| `height` | `number` | `460` | 编辑区可视高度(px),`0` 为自适应内容高度 |
|
|
22
|
-
| `minHeight` | `number` | `320` | 纸张最小高度 |
|
|
23
|
-
| `paperWidth` | `number` | `677` | 正文版心宽度(与公众号一致) |
|
|
24
|
-
| `primaryColor` | `string` | `'#07c160'` | 主题色(CSS 变量 `--ke-primary`) |
|
|
25
|
-
| `toolbar` | `string[] \| false` | `DEFAULT_TOOLBAR` | 工具栏项,见下表;`false` 隐藏 |
|
|
26
|
-
| `hideToolbar` | `boolean` | `false` | 隐藏工具栏 |
|
|
27
|
-
| `hideStatusbar` | `boolean` | `false` | 隐藏底部状态栏 |
|
|
28
|
-
| `readOnly` | `boolean` | `false` | 只读 |
|
|
29
|
-
| `autofocus` | `boolean` | `false` | 创建后自动聚焦 |
|
|
30
|
-
| `maxLength` | `number` | `0` | 超出后提示(软限制,不截断输入) |
|
|
31
|
-
| `wordCount` | `boolean` | `true` | 底部字数/媒体统计 |
|
|
32
|
-
| `sanitize` | `boolean` | `true` | 初始化与 `setContent` 时净化 HTML |
|
|
33
|
-
| `historyLimit` | `number` | `60` | 撤销栈深度 |
|
|
34
|
-
| `uploader` | `'mock' \| object \| fn \| ChunkUploader` | `'mock'` | 上传适配器,见 [upload-adapter.md](upload-adapter.md) |
|
|
35
|
-
| `upload` | `object` | `{chunkSize:1MB, concurrency:3, retries:2, fingerprint:'fast'}` | 分片参数 |
|
|
36
|
-
| `image.compress` | `object\|false` | `{maxWidth:1440, quality:0.85, minSize:300KB}` | 上传前大图压缩 |
|
|
37
|
-
| `maxImageSize` | `number` | `20MB` | 图片体积上限,超限拦截 |
|
|
38
|
-
| `maxVideoSize` | `number` | `512MB` | 视频体积上限 |
|
|
39
|
-
| `imageAccept` / `videoAccept` | `string` | 常见图/视频类型 | 文件选择器 `accept` |
|
|
40
|
-
| `paste.enabled` | `boolean` | `true` | 接管粘贴 |
|
|
41
|
-
| `paste.clean` | `boolean` | `true` | 粘贴内容净化(Word/WPS 自动清洗) |
|
|
42
|
-
| `paste.uploadFiles` | `boolean` | `true` | 粘贴截图/文件即上传 |
|
|
43
|
-
| `paste.localizeImages` | `boolean` | `false` | 尝试把外链图片下载后本地化 |
|
|
44
|
-
|
|
45
|
-
### 工具栏项
|
|
46
|
-
|
|
47
|
-
`undo` `redo` `heading` `fontsize` `bold` `italic` `underline` `strike` `foreColor` `backColor`
|
|
48
|
-
`alignLeft` `alignCenter` `alignRight` `alignJustify` `ul` `ol` `quote` `link` `image` `video`
|
|
49
|
-
`table` `code` `hr` `clear` `source` `preview` `fullscreen`;分隔符 `'|'`,右对齐标记 `':tail'`。
|
|
50
|
-
|
|
51
|
-
```js
|
|
52
|
-
toolbar: ['undo', 'redo', '|', 'bold', 'italic', '|', 'image', 'video', ':tail', 'source']
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
工具栏始终单行显示,放不下时可**左右滑动**,并有四重提示保证可发现性:
|
|
56
|
-
|
|
57
|
-
| 提示 | 作用 |
|
|
58
|
-
| --- | --- |
|
|
59
|
-
| 常显滚动条 | 静止时也能从滑块长度看出「还有更多工具」 |
|
|
60
|
-
| 尾部左缘渐隐 + 阴影 | 明确表达「有工具正藏在这块底下」,滑到最右自动消失 |
|
|
61
|
-
| 左缘渐隐 | 已向右滑出时提示左边还有内容 |
|
|
62
|
-
| 首次引导气泡 | 「工具栏可左右滑动」,3.8s 后或首次滑动后消失,`localStorage` 记忆不重复弹 |
|
|
63
|
-
|
|
64
|
-
鼠标还可**直接按住拖动**平移工具栏(光标变为抓握状);触屏沿用系统原生滑动。`:tail` 之后的「源码 / 预览 / 全屏」始终吸附在右端可见。
|
|
65
|
-
|
|
66
|
-
#### 下拉面板一览
|
|
67
|
-
|
|
68
|
-
| 按钮 | 点击行为 | 面板内容 |
|
|
69
|
-
|------|----------|----------|
|
|
70
|
-
| `heading` | 展开「段落样式」面板 | 正文 / 标题一 / 标题二 / 标题三,每档给出**真实字号预览 + 用途说明**(如「标题一 · 大标题 · 22px 加粗,全文主标题(建议只用一次)」),按钮文案跟随当前段落 |
|
|
71
|
-
| `fontsize` | 展开「字号」面板 | 12–32px 网格,当前字号高亮 |
|
|
72
|
-
| `foreColor` | **一次点击直接展开颜色面板** | 最近使用(本次会话)+ 主题颜色 + 标准颜色,色块带中文名称 tooltip,底部为取色器 + HEX 输入 + 应用;右上角「恢复默认」清除上色 |
|
|
73
|
-
| `backColor` | 同上(底色) | 推荐底色 + 主题颜色 + 自定义;按钮上的「A」用当前底色做高亮示意 |
|
|
74
|
-
| `image` / `video` | 展开插入面板 | 两个页签:**本地上传**(点击或拖拽到虚线区)/ **网络链接**(粘贴地址即可插入,附带可访问性校验提示) |
|
|
75
|
-
| `table` | 展开网格 | 10×8 规格选择,实时显示「N 列 × M 行」 |
|
|
76
|
-
| `link` | 展开表单 | 文字 / 地址 / 新窗口打开,已链接时提供「移除链接」 |
|
|
77
|
-
|
|
78
|
-
面板统一样式:圆角卡片 + 标题栏 + 分区小标题 + 入场动画;打开时会自动记录正文选区,操作后还原,因此**先选文字再点颜色**一定生效。
|
|
79
|
-
|
|
80
|
-
#### 图片缩放
|
|
81
|
-
|
|
82
|
-
点击正文中的图片会浮出气泡工具条(对齐 / 宽度 30%·60%·100% / 圆角 / 查看大图 / 替换 / 删除),同时图片**右下角出现圆形拖拽把手**:
|
|
83
|
-
|
|
84
|
-
- 按住把手左右拖动,实时按**容器宽度百分比**等比缩放,顶部浮层显示当前宽度(如 `58%`)
|
|
85
|
-
- 范围限制 15%–100%,不会拖出正文版心;松开即写入撤销栈,可 `⌘/Ctrl+Z` 回退
|
|
86
|
-
- 把手与浮层挂在编辑器容器上,**不进入内容区**,不会污染 `getHTML()` 导出与历史快照
|
|
87
|
-
- 视频卡片不支持拖拽缩放(保持固定比例),可用气泡工具条的「窄版 / 宽版」切换
|
|
88
|
-
|
|
89
|
-
#### 图片对齐
|
|
90
|
-
|
|
91
|
-
选中图片后,**工具栏的「左对齐 / 居中 / 右对齐」与气泡工具条的对齐按钮效果完全一致**——都作用于图片本身(`img` 为块级元素,靠 `margin:auto` 定位),而非所在段落:
|
|
92
|
-
|
|
93
|
-
- 图片宽度为 100% 时居中无视觉差异,**先缩小(拖拽把手或宽度按钮)再居中**即可看到图片在正文中水平居中
|
|
94
|
-
- 对齐写入撤销栈,可 `⌘/Ctrl+Z` 回退;工具栏对齐按钮会随选中图片的对齐状态高亮
|
|
95
|
-
|
|
96
|
-
#### 快捷键
|
|
97
|
-
|
|
98
|
-
| 快捷键 | 作用 |
|
|
99
|
-
|--------|------|
|
|
100
|
-
| `⌘/Ctrl + B / I / U` | 加粗 / 斜体 / 下划线 |
|
|
101
|
-
| `⌘/Ctrl + K` | 插入链接 |
|
|
102
|
-
| `⌘/Ctrl + Shift + K` | 切换 HTML 源码模式 |
|
|
103
|
-
| `⌘/Ctrl + Z` / `Shift + Z` / `Y` | 撤销 / 重做 |
|
|
104
|
-
| `⌘/Ctrl + S` | 触发 `save` 事件 |
|
|
105
|
-
| `Esc` | 关闭面板 / 退出预览 |
|
|
106
|
-
|
|
107
|
-
### 回调
|
|
108
|
-
|
|
109
|
-
| 回调 | 签名 | 说明 |
|
|
110
|
-
|------|------|------|
|
|
111
|
-
| `onChange(html, editor)` | | 内容变化(160ms 防抖) |
|
|
112
|
-
| `onReady(editor)` | | 实例可用 |
|
|
113
|
-
| `onError(error)` | | 内部异常 |
|
|
114
|
-
| `onUpload({stage, file, kind, url, percent, info})` | | `uploadstart/uploaddone/uploaderror/uploadcancel` |
|
|
115
|
-
| `beforeUpload(file, kind)` | 返回 `File` 改写、`false` 拦截 | 上传前钩子(加水印、二次校验等) |
|
|
116
|
-
|
|
117
|
-
---
|
|
118
|
-
|
|
119
|
-
## 三、实例属性与方法
|
|
120
|
-
|
|
121
|
-
```ts
|
|
122
|
-
editor.id // 实例 id
|
|
123
|
-
editor.el // 最外层容器
|
|
124
|
-
editor.root // contenteditable 节点
|
|
125
|
-
editor.options // 合并后的配置
|
|
126
|
-
editor.commands // 指令集(可程序化调用)
|
|
127
|
-
editor.media // 上传/媒体管理
|
|
128
|
-
editor.uploader // ChunkUploader 实例
|
|
129
|
-
editor.history // 撤销栈
|
|
130
|
-
editor.readOnly / sourceMode / previewMode / fullscreen
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
| 方法 | 说明 |
|
|
134
|
-
|------|------|
|
|
135
|
-
| `getHTML({clean?})` | 取当前 HTML,默认剔除编辑器内部属性、未完成占位块 |
|
|
136
|
-
| `getText()` | 纯文本 |
|
|
137
|
-
| `getJSON()` | `{html, text, counts}` |
|
|
138
|
-
| `setContent(html, {sanitize?, silent?})` | 覆盖内容 |
|
|
139
|
-
| `appendHTML(html)` | 在光标处插入 |
|
|
140
|
-
| `clear()` | 清空并取消所有上传 |
|
|
141
|
-
| `focus()` / `blur()` | 聚焦/失焦 |
|
|
142
|
-
| `setReadOnly(bool)` | 切换只读 |
|
|
143
|
-
| `undo()` / `redo()` | 撤销/重做(含光标位置恢复) |
|
|
144
|
-
| `insertImage(url, alt?)` / `insertVideo(url, label?)` | 按地址插入媒体(等同工具栏「网络链接」页签) |
|
|
145
|
-
| `upload(file, kind?)` | 手动触发一次上传(自动判断图片/视频) |
|
|
146
|
-
| `cancelUploads()` | 取消全部进行中任务 |
|
|
147
|
-
| `counts()` | `{chars, words, images, videos, uploading}` |
|
|
148
|
-
| `enterSource()` / `exitSource()` / `toggleSource()` | 源码模式 |
|
|
149
|
-
| `openPreview()` / `closePreview()` / `togglePreview()` | 预览模式 |
|
|
150
|
-
| `toggleFullscreen()` | 全屏编辑 |
|
|
151
|
-
| `on(type, fn)` / `off(type, fn)` | 事件订阅,返回取消函数 |
|
|
152
|
-
| `destroy()` | 卸载实例、清理监听与临时 URL |
|
|
153
|
-
|
|
154
|
-
### 事件
|
|
155
|
-
|
|
156
|
-
| 事件 | 载荷 | 触发时机 |
|
|
157
|
-
|------|------|----------|
|
|
158
|
-
| `ready` | `{editor}` | 实例挂载完成 |
|
|
159
|
-
| `change` | `{html, text}` | 内容变化 |
|
|
160
|
-
| `focus` / `blur` | | 编辑区聚焦/失焦 |
|
|
161
|
-
| `save` | `{html}` | ⌘/Ctrl + S |
|
|
162
|
-
| `uploadstart` | `{file, kind}` | 开始上传 |
|
|
163
|
-
| `uploaddone` | `{file, kind, url}` | 上传完成 |
|
|
164
|
-
| `uploaderror` | `{file, kind, error}` | 失败(已重试后) |
|
|
165
|
-
| `uploadcancel` | `{file, kind}` | 取消 |
|
|
166
|
-
| `insertmedia` | `{kind, url, node}` | 通过「网络链接」页签插入图片/视频 |
|
|
167
|
-
| `sourcechange` | `{mode: 'source'\|'visual'}` | 源码模式切换 |
|
|
168
|
-
|
|
169
|
-
---
|
|
170
|
-
|
|
171
|
-
## 四、指令集 commands
|
|
172
|
-
|
|
173
|
-
```js
|
|
174
|
-
editor.commands.toggleMark('bold' | 'italic' | 'underline' | 'strike')
|
|
175
|
-
editor.commands.setFontSize(18)
|
|
176
|
-
editor.commands.setColor('fore' | 'back', '#07c160') // color=null 恢复默认
|
|
177
|
-
editor.commands.setAlign('left' | 'center' | 'right' | 'justify')
|
|
178
|
-
editor.commands.toggleList('ordered' | 'unordered')
|
|
179
|
-
editor.commands.setHeading('p' | 'h1' | 'h2' | 'h3')
|
|
180
|
-
editor.commands.toggleBlockquote()
|
|
181
|
-
editor.commands.createLink({ url, text, target })
|
|
182
|
-
editor.commands.removeLink()
|
|
183
|
-
editor.commands.insertTable(3, 2) // 列, 行
|
|
184
|
-
editor.commands.insertCodeBlock('const a = 1')
|
|
185
|
-
editor.commands.insertDivider()
|
|
186
|
-
editor.commands.insertHTML('<p>富文本片段</p>')
|
|
187
|
-
editor.commands.clearFormat()
|
|
188
|
-
editor.getState() // 当前选区状态(工具栏高亮用)
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
## 五、独立可用的工具函数
|
|
192
|
-
|
|
193
|
-
```js
|
|
194
|
-
import { sanitizeHtml, formatHtml, escapeHtml, isSafeUrl, cleanWordHtml, mockAdapter, httpAdapter, simpleAdapter, ChunkUploader } from 'kyle-editor'
|
|
195
|
-
|
|
196
|
-
sanitizeHtml(dirtyHtml) // 白名单净化,返回安全 HTML
|
|
197
|
-
formatHtml(html) // 缩进美化(编辑器源码模式同款)
|
|
198
|
-
cleanWordHtml(wordHtml) // 粘贴前的 Word/WPS 清洗
|
|
199
|
-
isSafeUrl('javascript:1') // => false
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
UMD / 默认导出上也挂了一批静态成员,`<script>` 引入时直接可用:
|
|
203
|
-
|
|
204
|
-
```js
|
|
205
|
-
KEditor.version // '1.0.0'
|
|
206
|
-
KEditor.sanitizeHtml(html) // 白名单净化
|
|
207
|
-
KEditor.formatHtml(html) // 源码美化
|
|
208
|
-
KEditor.cleanWordHtml(html) // Word 清洗
|
|
209
|
-
KEditor.mockAdapter({speed}) // 内置分片模拟适配器
|
|
210
|
-
KEditor.httpAdapter(config) // 真实后端适配器
|
|
211
|
-
KEditor.simpleAdapter(fn) // 单次直传适配器
|
|
212
|
-
KEditor.chunkUploader(file, adapter, opts) // 分片调度器
|
|
213
|
-
KEditor.utils // { uid, escapeHtml }
|
|
214
|
-
KEditor.create(el, options) // 工厂方法,等价于 new KEditor(...)
|
|
215
|
-
KEditor.plugin // Vue 3 插件(仅 keditor-vue.umd.js)
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
> TypeScript:包内自带 `types/index.d.ts` 与 `types/vue.d.ts`,`import KEditor from 'kyle-editor'` 即有完整提示,无需额外安装。
|
|
219
|
-
|
|
220
|
-
## 六、安全说明
|
|
221
|
-
|
|
222
|
-
- 所有进入编辑器的外部 HTML(`value`、`setContent`、粘贴)都会经过 `sanitizeHtml`:标签/属性双白名单、`on*` 事件属性剔除、`javascript:`/`vbscript:`/`file:`/非法 `data:` 协议拦截、`style` 声明逐条过滤(丢弃 `expression`、`behavior` 等)。
|
|
223
|
-
- `getHTML({clean: false})` 会返回含编辑器内部属性的原始 HTML,请仅在调试时使用;入库前建议再跑一次 `sanitizeHtml`。
|
package/docs/index.md
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 集成文档索引
|
|
3
|
-
* - [README.md](../README.md) — 快速开始
|
|
4
|
-
* - [integration.md](integration.md) — 三种集成方式(script / ESM / Vue3)
|
|
5
|
-
* - [api.md](api.md) — 配置项、实例方法、事件
|
|
6
|
-
* - [upload-adapter.md](upload-adapter.md) — 分片上传协议与后端接口约定
|
|
7
|
-
*/
|
|
8
|
-
export default ['README.md', 'integration.md', 'api.md', 'upload-adapter.md']
|