kyle-editor 1.0.7 → 1.0.8
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 +232 -22
- package/dist/keditor-vue.cjs +3 -2
- package/dist/keditor-vue.es.js +3 -2
- package/dist/keditor-vue.umd.js +3 -2
- package/dist/keditor.cjs +2814 -521
- package/dist/keditor.es.js +2814 -521
- package/dist/keditor.umd.js +2812 -519
- package/dist/keditor.umd.min.js +109 -6
- package/docs/api.md +458 -0
- package/docs/integration.md +357 -0
- package/docs/upload-adapter.md +295 -0
- package/package.json +3 -2
- package/types/index.d.ts +273 -23
- package/types/vue.d.ts +2 -2
package/types/index.d.ts
CHANGED
|
@@ -12,6 +12,12 @@ export interface UploadResult {
|
|
|
12
12
|
size?: number
|
|
13
13
|
name?: string
|
|
14
14
|
duration?: number
|
|
15
|
+
/** 实际走的链路:'normal' 普通上传 | 'chunk' 分片上传 */
|
|
16
|
+
mode?: 'normal' | 'chunk'
|
|
17
|
+
/** 分片总数(普通上传恒为 1) */
|
|
18
|
+
chunks?: number
|
|
19
|
+
/** 命中已有文件(秒传)时为 true */
|
|
20
|
+
instant?: boolean
|
|
15
21
|
extra?: Record<string, unknown>
|
|
16
22
|
}
|
|
17
23
|
|
|
@@ -22,6 +28,10 @@ export interface UploadProgressInfo {
|
|
|
22
28
|
index?: number
|
|
23
29
|
speed?: number
|
|
24
30
|
instant?: boolean
|
|
31
|
+
percent?: number
|
|
32
|
+
uploadedChunks?: number
|
|
33
|
+
/** 当前链路:'normal' | 'chunk' */
|
|
34
|
+
mode?: 'normal' | 'chunk'
|
|
25
35
|
}
|
|
26
36
|
|
|
27
37
|
export interface UploadProgressEvent {
|
|
@@ -32,6 +42,8 @@ export interface UploadProgressEvent {
|
|
|
32
42
|
/** 分片上传适配器协议,详见 docs/upload-adapter.md */
|
|
33
43
|
export interface UploadAdapter {
|
|
34
44
|
name?: string
|
|
45
|
+
/** 单接口模式:任一 put 响应带回非空 url 即代表整份文件上传成功(不等 complete) */
|
|
46
|
+
completeOnUrl?: boolean
|
|
35
47
|
/** 初始化:返回 uploadId / 分片数 / 是否秒传 */
|
|
36
48
|
init?: (file: File, ctx: { chunkSize: number; signal: AbortSignal; fingerprint: string }) => Promise<{
|
|
37
49
|
uploadId?: string
|
|
@@ -40,7 +52,7 @@ export interface UploadAdapter {
|
|
|
40
52
|
instant?: UploadResult | false
|
|
41
53
|
chunkSize?: number
|
|
42
54
|
}>
|
|
43
|
-
/**
|
|
55
|
+
/** 上传单个分片;返回 { url } 时表示该响应已可判定上传成功(配合 completeOnUrl) */
|
|
44
56
|
put?: (chunk: Blob, meta: { index: number; total: number; uploadId?: string; file: File; signal: AbortSignal }) => Promise<unknown>
|
|
45
57
|
/** 合并并返回最终地址 */
|
|
46
58
|
complete?: (meta: { uploadId?: string; file: File; total: number; signal: AbortSignal }) => Promise<UploadResult | string>
|
|
@@ -48,39 +60,111 @@ export interface UploadAdapter {
|
|
|
48
60
|
upload?: (file: File, ctx: { onProgress: (loaded: number, total: number) => void; signal: AbortSignal }) => Promise<UploadResult | string>
|
|
49
61
|
}
|
|
50
62
|
|
|
63
|
+
/** 上传适配器协议:普通上传实现 upload(),分片上传实现 put(),详见 docs/upload-adapter.md */
|
|
64
|
+
export interface UploadAdapter {
|
|
65
|
+
name?: string
|
|
66
|
+
/** 响应带回非空 url 即代表上传成功(分片链路据此提前收工) */
|
|
67
|
+
completeOnUrl?: boolean
|
|
68
|
+
/** 初始化:返回 uploadId / 已传分片(断点续传)/ 秒传 url,可选 */
|
|
69
|
+
init?: (file: File, ctx: { chunkSize: number; signal: AbortSignal; fingerprint: string }) => Promise<{
|
|
70
|
+
uploadId?: string
|
|
71
|
+
totalChunks?: number
|
|
72
|
+
uploadedChunks?: number[]
|
|
73
|
+
instant?: UploadResult | false
|
|
74
|
+
chunkSize?: number
|
|
75
|
+
}>
|
|
76
|
+
/** 上传单个分片;返回 { url } 时表示该响应已可判定上传成功(配合 completeOnUrl) */
|
|
77
|
+
put?: (chunk: Blob, meta: { index: number; total: number; uploadId?: string; file: File; signal: AbortSignal }) => Promise<unknown>
|
|
78
|
+
/** 收尾拿最终地址,可选(分片响应里已有 url 时不会被调用) */
|
|
79
|
+
complete?: (meta: { uploadId?: string; file: File; total: number; signal: AbortSignal }) => Promise<UploadResult | string>
|
|
80
|
+
/** 普通上传:整个文件一次请求,返回 url 或 { url } */
|
|
81
|
+
upload?: (file: File, ctx: { onProgress: (loaded: number, total: number) => void; signal: AbortSignal }) => Promise<UploadResult | string>
|
|
82
|
+
}
|
|
83
|
+
|
|
51
84
|
export interface UploadOptions {
|
|
85
|
+
/** 链路选择:'auto' 按体积自动选 | 'normal' 只走普通上传 | 'chunk' 只走分片上传,默认 'auto' */
|
|
86
|
+
mode?: 'auto' | 'normal' | 'chunk'
|
|
87
|
+
/** auto 模式下达到该体积才走分片上传,默认 5MB */
|
|
88
|
+
chunkThreshold?: number
|
|
52
89
|
/** 分片大小,默认 1MB */
|
|
53
90
|
chunkSize?: number
|
|
54
91
|
/** 并发分片数,默认 3 */
|
|
55
92
|
concurrency?: number
|
|
56
93
|
/** 单片失败重试次数,默认 2 */
|
|
57
94
|
retries?: number
|
|
95
|
+
/** 重试退避基数(ms),默认 600 */
|
|
96
|
+
retryDelay?: number
|
|
58
97
|
/** 指纹算法:'none' | 'fast' | 'strong' */
|
|
59
98
|
fingerprint?: 'none' | 'fast' | 'strong'
|
|
99
|
+
/** 覆盖「响应带 url 即成功」判定,默认取 adapter.completeOnUrl */
|
|
100
|
+
completeOnUrl?: boolean
|
|
60
101
|
}
|
|
61
102
|
|
|
103
|
+
/** 真实后端适配器:只认一个接口地址,两种链路共用 */
|
|
62
104
|
export interface HttpAdapterConfig extends Partial<UploadOptions> {
|
|
63
105
|
type: 'http'
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
106
|
+
/** 上传地址:分片与整包都打到它 */
|
|
107
|
+
url: string
|
|
108
|
+
/** 默认 'formdata'(multipart)| 'raw'(裸 body + 查询串) */
|
|
109
|
+
mode?: 'formdata' | 'raw'
|
|
110
|
+
/** 默认:'formdata' → POST,'raw' → PUT */
|
|
111
|
+
method?: 'POST' | 'PUT'
|
|
112
|
+
/** multipart 里的文件字段名,默认 'file' */
|
|
113
|
+
fieldName?: string
|
|
114
|
+
headers?: Record<string, string> | (() => Record<string, string>)
|
|
115
|
+
withCredentials?: boolean
|
|
116
|
+
/** 解开服务端响应外层包装,默认取 json.data */
|
|
117
|
+
parse?: (json: unknown) => unknown
|
|
118
|
+
/** 自定义从响应里取上传地址的规则,默认读 url / fileUrl / src */
|
|
119
|
+
pickUrl?: (payload: unknown) => string
|
|
120
|
+
/** 动态分片地址(如不同分片打不同节点) */
|
|
121
|
+
chunkUrlFor?: (ctx: { index: number; total: number }) => string
|
|
72
122
|
}
|
|
73
123
|
|
|
74
|
-
export type UploaderOption =
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
124
|
+
export type UploaderOption =
|
|
125
|
+
| 'mock'
|
|
126
|
+
| null
|
|
127
|
+
/** 接口地址,如 '/api/upload'(等价于 { type:'http', url }) */
|
|
128
|
+
| (string & {})
|
|
129
|
+
| UploadAdapter
|
|
130
|
+
| HttpAdapterConfig
|
|
131
|
+
| SimpleUploader
|
|
132
|
+
| ChunkUploader
|
|
133
|
+
| ((file: File, ctx: { onProgress: (loaded: number, total: number) => void; signal?: AbortSignal }) => Promise<UploadResult | string>)
|
|
134
|
+
|
|
135
|
+
/** 普通上传:整个文件一次请求 */
|
|
136
|
+
export class SimpleUploader {
|
|
137
|
+
constructor(adapter: UploadAdapter, options?: UploadOptions)
|
|
138
|
+
readonly mode: 'normal'
|
|
139
|
+
upload(file: File, opts?: { signal?: AbortSignal; onProgress?: (ratio: number, info: UploadProgressInfo) => void }): Promise<UploadResult>
|
|
140
|
+
destroy(): void
|
|
141
|
+
}
|
|
79
142
|
|
|
143
|
+
/** 分片上传:切片并发,响应带 url 即成功 */
|
|
80
144
|
export class ChunkUploader {
|
|
81
145
|
constructor(adapter: UploadAdapter, options?: UploadOptions)
|
|
82
|
-
|
|
83
|
-
|
|
146
|
+
readonly mode: 'chunk'
|
|
147
|
+
/** 拿到响应里的 url 即结束(不再调用 complete) */
|
|
148
|
+
completeOnUrl: boolean
|
|
149
|
+
chunkSize: number
|
|
150
|
+
concurrency: number
|
|
151
|
+
retries: number
|
|
152
|
+
upload(file: File, opts?: { signal?: AbortSignal; onProgress?: (ratio: number, info: UploadProgressInfo) => void }): Promise<UploadResult>
|
|
153
|
+
destroy(): void
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** 选路器:按 upload.mode / 体积在两条链路之间选择 */
|
|
157
|
+
export class UploadPipeline {
|
|
158
|
+
constructor(normal: SimpleUploader | null, chunk: ChunkUploader | null, options?: UploadOptions)
|
|
159
|
+
readonly normal: SimpleUploader | null
|
|
160
|
+
readonly chunk: ChunkUploader | null
|
|
161
|
+
readonly mode: 'auto' | 'normal' | 'chunk'
|
|
162
|
+
readonly chunkThreshold: number
|
|
163
|
+
/** 该文件走哪条链路 */
|
|
164
|
+
pick(file: File): 'normal' | 'chunk'
|
|
165
|
+
uploaderFor(file: File): SimpleUploader | ChunkUploader | null
|
|
166
|
+
upload(file: File, opts?: { signal?: AbortSignal; onProgress?: (ratio: number, info: UploadProgressInfo) => void }): Promise<UploadResult>
|
|
167
|
+
destroy(): void
|
|
84
168
|
}
|
|
85
169
|
|
|
86
170
|
export declare function mockAdapter(opts?: {
|
|
@@ -93,13 +177,89 @@ export declare function mockAdapter(opts?: {
|
|
|
93
177
|
export declare function httpAdapter(config: HttpAdapterConfig): UploadAdapter
|
|
94
178
|
|
|
95
179
|
export declare function simpleAdapter(
|
|
96
|
-
fn: (file: File, onProgress: (loaded: number, total: number) => void
|
|
180
|
+
fn: (file: File, ctx: { onProgress: (loaded: number, total: number) => void; signal?: AbortSignal }) => Promise<UploadResult | string>,
|
|
97
181
|
): UploadAdapter
|
|
98
182
|
|
|
99
|
-
|
|
183
|
+
/** 构造普通上传链路 */
|
|
184
|
+
export declare function createSimpleUploader(option: UploaderOption, config?: UploadOptions): SimpleUploader
|
|
185
|
+
|
|
186
|
+
/** 构造分片上传链路 */
|
|
187
|
+
export declare function createChunkUploader(option: UploaderOption, config?: UploadOptions): ChunkUploader
|
|
100
188
|
|
|
101
189
|
/* ------------------------------ 配置 ------------------------------ */
|
|
102
190
|
|
|
191
|
+
/** 代码块语言项(内置 20 种,可用 options.code.languages 裁剪) */
|
|
192
|
+
export interface CodeLanguage {
|
|
193
|
+
/** 语言主名,如 'javascript' / 'python' / 'plaintext' */
|
|
194
|
+
value: string
|
|
195
|
+
/** 展示名,如 'JavaScript' */
|
|
196
|
+
label: string
|
|
197
|
+
/** 一句话说明 */
|
|
198
|
+
hint: string
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export interface CodeOptions {
|
|
202
|
+
/**
|
|
203
|
+
* 允许的语言:主名或别名(如 'js' / 'mysql' / 'yml');
|
|
204
|
+
* 留空 = 全部内置语言;裁剪后 defaultLanguage 不在其中会自动回落到第一项
|
|
205
|
+
*/
|
|
206
|
+
languages?: string[]
|
|
207
|
+
/** 新建代码块的默认语言,默认 'plaintext' */
|
|
208
|
+
defaultLanguage?: string
|
|
209
|
+
/** 是否语法高亮(false = 只保留纯文本,语言标记仍然写入),默认 true */
|
|
210
|
+
highlight?: boolean
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Markdown 导入的落点:replace 替换全文(默认)| append 追加到文末 | cursor 插入到光标处 */
|
|
214
|
+
export type MarkdownInsertMode = 'replace' | 'append' | 'cursor'
|
|
215
|
+
|
|
216
|
+
export interface MarkdownOptions {
|
|
217
|
+
/** 导入后内容落到哪里,默认 'replace'(面板里可临时改) */
|
|
218
|
+
insertMode?: MarkdownInsertMode
|
|
219
|
+
/** 单个文件体积上限(字节),默认 5MB,0 = 不限制 */
|
|
220
|
+
maxSize?: number
|
|
221
|
+
/** GFM 扩展:表格 / 删除线 / 任务列表 / 裸链接,默认 true */
|
|
222
|
+
gfm?: boolean
|
|
223
|
+
/** 段落内的单换行是否转成 <br>,默认 false(按空格处理) */
|
|
224
|
+
breaks?: boolean
|
|
225
|
+
/** 链接是否加 target="_blank" rel="noopener noreferrer",默认 false */
|
|
226
|
+
linkTarget?: boolean | string
|
|
227
|
+
/** 是否丢弃开头的 YAML front matter,默认 true */
|
|
228
|
+
frontMatter?: boolean
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Markdown 转换结果的块级统计 */
|
|
232
|
+
export interface MarkdownSummary {
|
|
233
|
+
headings: number
|
|
234
|
+
paragraphs: number
|
|
235
|
+
lists: number
|
|
236
|
+
items: number
|
|
237
|
+
codeBlocks: number
|
|
238
|
+
quotes: number
|
|
239
|
+
tables: number
|
|
240
|
+
images: number
|
|
241
|
+
links: number
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export interface MarkdownImportResult {
|
|
245
|
+
ok: boolean
|
|
246
|
+
/** ok 为 true 时的转换结果 HTML */
|
|
247
|
+
html?: string
|
|
248
|
+
summary?: MarkdownSummary
|
|
249
|
+
/** 实际使用的落点 */
|
|
250
|
+
mode?: MarkdownInsertMode
|
|
251
|
+
/** 源文本字符数 */
|
|
252
|
+
chars?: number
|
|
253
|
+
/** 文件名(导入文件时) */
|
|
254
|
+
name?: string
|
|
255
|
+
/** ok 为 false 时的原因 */
|
|
256
|
+
reason?: 'readonly' | 'error'
|
|
257
|
+
error?: Error
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** 可导入的 Markdown 源:文本、File/Blob,或 { name, content } */
|
|
261
|
+
export type MarkdownSource = string | Blob | { name?: string; content: string }
|
|
262
|
+
|
|
103
263
|
export interface ImageCompressOptions {
|
|
104
264
|
maxWidth?: number
|
|
105
265
|
quality?: number
|
|
@@ -137,7 +297,7 @@ export type BuiltinToolbarItem =
|
|
|
137
297
|
| 'foreColor' | 'backColor'
|
|
138
298
|
| 'alignLeft' | 'alignCenter' | 'alignRight' | 'alignJustify'
|
|
139
299
|
| 'ul' | 'ol' | 'quote'
|
|
140
|
-
| 'link' | 'image' | 'video' | 'table' | 'code' | 'hr' | 'clear'
|
|
300
|
+
| 'link' | 'image' | 'video' | 'table' | 'code' | 'markdown' | 'hr' | 'clear'
|
|
141
301
|
| 'source' | 'preview' | 'fullscreen'
|
|
142
302
|
| '|' | ':tail'
|
|
143
303
|
|
|
@@ -281,8 +441,13 @@ export interface CustomButtonSpec {
|
|
|
281
441
|
export interface KEditorOptions {
|
|
282
442
|
value?: string
|
|
283
443
|
placeholder?: string
|
|
284
|
-
/**
|
|
285
|
-
|
|
444
|
+
/**
|
|
445
|
+
* 内容区高度:
|
|
446
|
+
* - 不写 / `0` / `'auto'`:随内容自动撑开(整页滚动,工具栏吸附视口顶部)
|
|
447
|
+
* - 填 px:固定高度,内容超出时编辑区内部滚动
|
|
448
|
+
*/
|
|
449
|
+
height?: number | 'auto'
|
|
450
|
+
/** 内容区最小高度(px),两种高度模式下都生效,默认 320 */
|
|
286
451
|
minHeight?: number
|
|
287
452
|
/** 主题色,默认微信绿 #07c160 */
|
|
288
453
|
primaryColor?: string
|
|
@@ -308,8 +473,16 @@ export interface KEditorOptions {
|
|
|
308
473
|
/** 是否对输入内容做白名单净化,默认 true */
|
|
309
474
|
sanitize?: boolean
|
|
310
475
|
historyLimit?: number
|
|
476
|
+
/** 普通上传(整个文件一次请求):'mock' | 接口地址 | {url,…} | adapter | fn */
|
|
311
477
|
uploader?: UploaderOption
|
|
478
|
+
/** 分片上传(切片并发,接口返回 url 即成功):写法同 uploader;不配置则不启用分片 */
|
|
479
|
+
chunkUploader?: UploaderOption
|
|
480
|
+
/** 上传链路参数(mode / chunkThreshold / chunkSize / concurrency / retries) */
|
|
312
481
|
upload?: UploadOptions
|
|
482
|
+
/** 代码块:可选语言清单 + 默认语言 + 是否语法高亮 */
|
|
483
|
+
code?: CodeOptions
|
|
484
|
+
/** Markdown 导入:默认落点 / 文件体积上限 / 转换选项 */
|
|
485
|
+
markdown?: MarkdownOptions
|
|
313
486
|
image?: ImageOptions
|
|
314
487
|
maxImageSize?: number
|
|
315
488
|
maxVideoSize?: number
|
|
@@ -348,6 +521,8 @@ export interface EditorState {
|
|
|
348
521
|
selectionText: string
|
|
349
522
|
canUndo: boolean
|
|
350
523
|
canRedo: boolean
|
|
524
|
+
/** 光标是否落在代码块内 */
|
|
525
|
+
inCode: boolean
|
|
351
526
|
source: boolean
|
|
352
527
|
preview: boolean
|
|
353
528
|
fullscreen: boolean
|
|
@@ -386,7 +561,12 @@ export declare class Commands {
|
|
|
386
561
|
createLink(payload: { url: string; text?: string; target?: boolean }): void
|
|
387
562
|
removeLink(): void
|
|
388
563
|
insertTable(cols: number, rows: number): HTMLTableElement
|
|
389
|
-
|
|
564
|
+
/** 插入代码块(code 为源码,lang 缺省用 code.defaultLanguage) */
|
|
565
|
+
insertCodeBlock(code?: string, lang?: string): HTMLElement
|
|
566
|
+
/** 切换代码块语言并重新高亮;target 缺省取光标所在块,返回 null = 不在代码块中 */
|
|
567
|
+
setCodeLanguage(lang: string, target?: HTMLElement | null): string | null
|
|
568
|
+
/** 光标所在代码块的语言;不在代码块中返回空串 */
|
|
569
|
+
currentCodeLang(): string
|
|
390
570
|
insertDivider(): HTMLElement
|
|
391
571
|
insertHTML(html: string): void
|
|
392
572
|
insertNode(node: Node): void
|
|
@@ -414,7 +594,10 @@ export declare class KEditor {
|
|
|
414
594
|
cancelAll(): void
|
|
415
595
|
tasks: Map<string, unknown>
|
|
416
596
|
}
|
|
417
|
-
|
|
597
|
+
/** 选路器(按 upload.mode / 体积在普通与分片之间选择) */
|
|
598
|
+
readonly uploader: UploadPipeline
|
|
599
|
+
/** 两条原始链路:{ normal: SimpleUploader, chunk: ChunkUploader | null } */
|
|
600
|
+
readonly uploaders: { normal: SimpleUploader; chunk: ChunkUploader | null }
|
|
418
601
|
readonly toolbar: {
|
|
419
602
|
el: HTMLElement
|
|
420
603
|
buttons: Map<string, HTMLElement>
|
|
@@ -422,6 +605,9 @@ export declare class KEditor {
|
|
|
422
605
|
openLink(): void
|
|
423
606
|
openMedia(kind: 'image' | 'video'): void
|
|
424
607
|
openTable(): void
|
|
608
|
+
/** 打开代码块语言面板(插入新块或改写光标所在块) */
|
|
609
|
+
openCode(): void
|
|
610
|
+
openMarkdown(): void
|
|
425
611
|
openCustom(name: string): void
|
|
426
612
|
addButton(spec: CustomButtonSpec, options?: ButtonPlaceOptions): HTMLElement | null
|
|
427
613
|
moveButton(name: string, where?: ButtonPosition): boolean
|
|
@@ -438,6 +624,8 @@ export declare class KEditor {
|
|
|
438
624
|
readonly fullscreen: boolean
|
|
439
625
|
readonly readOnly: boolean
|
|
440
626
|
readonly destroyed: boolean
|
|
627
|
+
/** 最近一次选择的代码块语言(下次插入默认沿用) */
|
|
628
|
+
lastCodeLang: string
|
|
441
629
|
|
|
442
630
|
get element(): HTMLElement
|
|
443
631
|
get editorElement(): HTMLElement
|
|
@@ -474,6 +662,34 @@ export declare class KEditor {
|
|
|
474
662
|
/** 运行时调整版心:{ width, mode, gap, maxWidth } */
|
|
475
663
|
setPaper(config?: { width?: number; mode?: 'fluid' | 'fixed'; gap?: number; maxWidth?: number }): { width: number; mode: 'fluid' | 'fixed'; gap: number; maxWidth: number }
|
|
476
664
|
paperOptions(): { width: number; mode: 'fluid' | 'fixed'; gap: number; maxWidth: number }
|
|
665
|
+
/** 运行时切换内容区高度:传 px 固定,传 0 / 'auto' 恢复自适应;返回实际生效的高度(0 = 自适应) */
|
|
666
|
+
setHeight(value: number | 'auto'): number
|
|
667
|
+
heightOptions(): { height: number; auto: boolean }
|
|
668
|
+
/** 可选语言清单(受 options.code.languages 裁剪) */
|
|
669
|
+
codeLanguages(): CodeLanguage[]
|
|
670
|
+
/** 重新高亮正文里所有代码块,返回处理的代码块数量 */
|
|
671
|
+
highlightCode(): number
|
|
672
|
+
/** 插入代码块:code 为源码,lang 缺省用 code.defaultLanguage */
|
|
673
|
+
insertCode(code?: string, lang?: string): HTMLElement
|
|
674
|
+
/** 切换代码块语言并重新高亮;target 缺省取光标所在块 */
|
|
675
|
+
setCodeLanguage(lang: string, target?: HTMLElement | null): string | null
|
|
676
|
+
/** 光标所在代码块的语言;不在代码块中返回空串 */
|
|
677
|
+
getCodeLanguage(): string
|
|
678
|
+
|
|
679
|
+
/* Markdown 导入 */
|
|
680
|
+
|
|
681
|
+
/** 导入 Markdown(文本 / File / {name,content})并转为 HTML,落点默认取 options.markdown.insertMode */
|
|
682
|
+
importMarkdown(source: MarkdownSource, options?: { mode?: MarkdownInsertMode; silent?: boolean }): Promise<MarkdownImportResult>
|
|
683
|
+
/** 导入并替换全文 */
|
|
684
|
+
setMarkdown(source: MarkdownSource, options?: { silent?: boolean }): Promise<MarkdownImportResult>
|
|
685
|
+
/** 导入并插入到光标处 */
|
|
686
|
+
insertMarkdown(source: MarkdownSource, options?: { silent?: boolean }): Promise<MarkdownImportResult>
|
|
687
|
+
/** 导入并追加到文末 */
|
|
688
|
+
appendMarkdown(source: MarkdownSource, options?: { silent?: boolean }): Promise<MarkdownImportResult>
|
|
689
|
+
/** 光标 / 选区移到正文末尾 */
|
|
690
|
+
moveCaretToEnd(): this
|
|
691
|
+
/** 当前 Markdown 导入配置 */
|
|
692
|
+
markdownOptions(): { insertMode: MarkdownInsertMode; maxSize: number; auto: boolean }
|
|
477
693
|
/** 外部灌入下拉数据(接口在编辑器之外请求时使用) */
|
|
478
694
|
setButtonOptions(name: string, items: CustomButtonOption[] | string[]): CustomButtonOption[]
|
|
479
695
|
getButtonValue(name: string): CustomButtonOption | null
|
|
@@ -506,6 +722,40 @@ export declare function replace(target: HTMLElement | string, options?: KEditorO
|
|
|
506
722
|
export declare const defaults: KEditorOptions
|
|
507
723
|
export declare const DEFAULT_TOOLBAR: ToolbarItem[]
|
|
508
724
|
export declare function normalizeCustomButtons(list: unknown): CustomButtonSpec[]
|
|
725
|
+
|
|
726
|
+
/* ------------------------------ 代码块 ------------------------------ */
|
|
727
|
+
|
|
728
|
+
/** 内置语言清单(value / label / aliases / hint) */
|
|
729
|
+
export declare const LANGUAGES: Array<CodeLanguage & { aliases: string[] }>
|
|
730
|
+
/** 把代码文本渲染成带 ke-tok-* span 的 HTML 片段(内部转义,可直接赋值给 innerHTML) */
|
|
731
|
+
export declare function highlightCode(code: string, lang?: string): string
|
|
732
|
+
/** 别名/大小写归一为语言主名,未知语言回落 'plaintext' */
|
|
733
|
+
export declare function normalizeLang(lang?: string): string
|
|
734
|
+
/** 语言展示名 */
|
|
735
|
+
export declare function languageLabel(lang?: string): string
|
|
736
|
+
/** 语言清单(可按主名/别名裁剪,返回 { value, label, hint }) */
|
|
737
|
+
export declare function listLanguages(only?: string[]): CodeLanguage[]
|
|
738
|
+
/** 节点是否为代码块(<pre> 且带 data-k-lang 或内含 <code>) */
|
|
739
|
+
export declare function isCodeBlock(node: Node | null): boolean
|
|
740
|
+
|
|
741
|
+
/* ------------------------------ Markdown 导入 ------------------------------ */
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* Markdown → HTML(零依赖,GFM 子集)
|
|
745
|
+
* 产物已是编辑器正文规范(<p>/<h1-6>/<ul>/<table>/<pre data-k-lang>…),默认再过一遍白名单净化
|
|
746
|
+
*/
|
|
747
|
+
export declare function markdownToHtml(markdown: string, options?: MarkdownOptions & { sanitize?: boolean }): string
|
|
748
|
+
/** 统计 HTML 里的块级元素数量 */
|
|
749
|
+
export declare function markdownSummary(html: string): MarkdownSummary
|
|
750
|
+
/** 拖拽/粘贴的文件是否为 Markdown(按 MIME 与扩展名,含 .txt) */
|
|
751
|
+
export declare function isMarkdownFile(file: { name?: string; type?: string } | null | undefined): boolean
|
|
752
|
+
/** 读取 Markdown 文件文本:严格 UTF-8 优先,失败回退 gb18030 / gbk / big5 */
|
|
753
|
+
export declare function readMarkdownFile(file: Blob): Promise<string>
|
|
754
|
+
/** 落点模式归一,非法值回落 'replace' */
|
|
755
|
+
export declare function normalizeInsertMode(value?: string): MarkdownInsertMode
|
|
756
|
+
/** <input accept> 用:.md,.markdown,.txt,text/markdown,text/plain */
|
|
757
|
+
export declare const MARKDOWN_ACCEPT: string
|
|
758
|
+
|
|
509
759
|
export declare function normalizePosition(spec: unknown): ButtonPosition | null
|
|
510
760
|
export declare function normalizeItems(raw: unknown): CustomButtonOption[]
|
|
511
761
|
export declare function exportHtml(html: string): string
|
package/types/vue.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export interface KEditorVueProps {
|
|
|
9
9
|
options?: KEditorOptions
|
|
10
10
|
/** 只读 */
|
|
11
11
|
disabled?: boolean
|
|
12
|
-
/**
|
|
13
|
-
height?: number
|
|
12
|
+
/** 内容区高度(px):优先级高于 options.height;不传 / 'auto' = 随内容自动撑开 */
|
|
13
|
+
height?: number | 'auto'
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export interface KEditorVueEmits {
|