kyle-editor 1.0.2 → 1.0.4
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 +108 -15
- package/dist/keditor.cjs +171 -30
- package/dist/keditor.es.js +171 -30
- package/dist/keditor.umd.js +171 -30
- package/dist/keditor.umd.min.js +483 -0
- package/package.json +8 -6
- package/types/index.d.ts +49 -4
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kyle-editor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "轻量、美观的微信公众号风格富文本编辑器(纯前端,支持图片/视频分片上传、HTML 源码模式),可通过 <script> 引入或作为 Vue 3 组件安装。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/keditor.cjs",
|
|
7
7
|
"module": "./dist/keditor.es.js",
|
|
8
|
-
"unpkg": "./dist/keditor.umd.js",
|
|
9
|
-
"jsdelivr": "./dist/keditor.umd.js",
|
|
8
|
+
"unpkg": "./dist/keditor.umd.min.js",
|
|
9
|
+
"jsdelivr": "./dist/keditor.umd.min.js",
|
|
10
10
|
"types": "./types/index.d.ts",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
@@ -32,16 +32,18 @@
|
|
|
32
32
|
"node": ">=16"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
|
-
"build": "vite build --config vite.config.core.js && vite build --config vite.config.vue.js",
|
|
35
|
+
"build": "vite build --config vite.config.core.js && vite build --config vite.config.vue.js && vite build --config vite.config.min.js",
|
|
36
|
+
"build:min": "vite build --config vite.config.min.js",
|
|
36
37
|
"dev": "python3 -m http.server 5178 --bind 127.0.0.1",
|
|
37
38
|
"test": "node test/run-headless.mjs",
|
|
39
|
+
"test:min": "node test/run-headless.mjs \"http://127.0.0.1:5178/test/smoke.html?bundle=min\"",
|
|
38
40
|
"test:pages": "node test/check-page.mjs",
|
|
39
41
|
"test:types": "node test/check-types.mjs",
|
|
40
42
|
"test:package": "node test/check-package.mjs",
|
|
41
43
|
"test:install": "node test/check-install.mjs",
|
|
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",
|
|
44
|
+
"test:visual": "node test/shoot.mjs rich,uploading,bubble,resize,align,source,preview,color,heading,media,link,custom,customload,customerr,posbtn,wide,widefix,scroll,scroll2,http://127.0.0.1:5178/demo/vue.html",
|
|
43
45
|
"clean": "rm -rf dist",
|
|
44
|
-
"verify": "npm run build && npm test && npm run test:pages && npm run test:types && npm run test:package",
|
|
46
|
+
"verify": "npm run build && npm test && npm run test:min && npm run test:pages && npm run test:types && npm run test:package",
|
|
45
47
|
"pack:check": "npm run build && npm run test:package && npm pack --dry-run",
|
|
46
48
|
"prerelease": "npm run verify && npm run test:install",
|
|
47
49
|
"release": "npm publish --access public --registry=https://registry.npmjs.org",
|
package/types/index.d.ts
CHANGED
|
@@ -141,9 +141,29 @@ export type BuiltinToolbarItem =
|
|
|
141
141
|
| 'source' | 'preview' | 'fullscreen'
|
|
142
142
|
| '|' | ':tail'
|
|
143
143
|
|
|
144
|
-
/**
|
|
144
|
+
/**
|
|
145
|
+
* 工具栏项:内置名称、分隔符 `|`、`:tail`,或 customButtons 里定义的自定义按钮 name */
|
|
145
146
|
export type ToolbarItem = BuiltinToolbarItem | (string & {})
|
|
146
147
|
|
|
148
|
+
/**
|
|
149
|
+
* 按钮在工具栏里的位置(自定义按钮的 `position`,addButton / moveButton 的目标位):
|
|
150
|
+
* - `number`:第 n 个按钮之前(0 起,按视觉顺序计数,分隔符不计数)
|
|
151
|
+
* - `'start'`:工具栏最前
|
|
152
|
+
* - `'end'`:主区末尾(尾栏之前,默认)
|
|
153
|
+
* - `'tail'`:右侧吸附尾栏末尾
|
|
154
|
+
* - `'link'` 等按钮名:插到该按钮之前
|
|
155
|
+
* - `{ before: name }` / `{ after: name }`:显式锚点
|
|
156
|
+
*/
|
|
157
|
+
export type ButtonPosition = number | 'start' | 'end' | 'tail' | (string & {}) | { before: string } | { after: string }
|
|
158
|
+
|
|
159
|
+
/** addButton / moveButton 的位置参数(at 优先于 before / after / index) */
|
|
160
|
+
export interface ButtonPlaceOptions {
|
|
161
|
+
at?: ButtonPosition
|
|
162
|
+
before?: string
|
|
163
|
+
after?: string
|
|
164
|
+
index?: number
|
|
165
|
+
}
|
|
166
|
+
|
|
147
167
|
/* ------------------------------ 自定义工具栏按钮 ------------------------------ */
|
|
148
168
|
|
|
149
169
|
/** 下拉选项;也接受纯字符串或接口原始对象(自动识别 value/id/key、label/name/title 等常见字段) */
|
|
@@ -215,6 +235,17 @@ export interface CustomButtonSpec {
|
|
|
215
235
|
/** 记住选中项并在按钮上回显,默认 true */
|
|
216
236
|
keepValue?: boolean
|
|
217
237
|
|
|
238
|
+
/** 按钮在工具栏中的位置,默认追加到主区末尾(尾栏之前) */
|
|
239
|
+
position?: ButtonPosition
|
|
240
|
+
/** position 别名(与 addButton 的 options.at 同义) */
|
|
241
|
+
at?: ButtonPosition
|
|
242
|
+
/** 简写:插到某按钮之前 */
|
|
243
|
+
before?: string
|
|
244
|
+
/** 简写:插到某按钮之后 */
|
|
245
|
+
after?: string
|
|
246
|
+
/** 简写:第 n 个按钮之前 */
|
|
247
|
+
index?: number
|
|
248
|
+
|
|
218
249
|
/** 数据源①:静态配置 */
|
|
219
250
|
options?: CustomButtonOption[] | string[]
|
|
220
251
|
/** 数据源②:自定义加载函数(可返回 Promise) */
|
|
@@ -255,8 +286,14 @@ export interface KEditorOptions {
|
|
|
255
286
|
minHeight?: number
|
|
256
287
|
/** 主题色,默认微信绿 #07c160 */
|
|
257
288
|
primaryColor?: string
|
|
258
|
-
/**
|
|
289
|
+
/** 版心基准宽度,默认 677(公众号);fluid 模式下它是最小宽度 */
|
|
259
290
|
paperWidth?: number
|
|
291
|
+
/** 版心宽度模式:'fluid'(默认,宽屏版心随容器生长)| 'fixed'(恒定 paperWidth + 64) */
|
|
292
|
+
paperMode?: 'fluid' | 'fixed'
|
|
293
|
+
/** fluid 模式下单侧留白,默认 24 */
|
|
294
|
+
paperGap?: number
|
|
295
|
+
/** fluid 模式下载心最大宽度,0 = 不限 */
|
|
296
|
+
paperMaxWidth?: number
|
|
260
297
|
/** 工具栏配置;false 隐藏。留空且配置了 customButtons 时,自定义按钮自动追加到默认工具栏 */
|
|
261
298
|
toolbar?: ToolbarItem[] | boolean
|
|
262
299
|
/** 自定义工具栏按钮(下拉选择,数据可静态配置或从接口读取) */
|
|
@@ -386,7 +423,9 @@ export declare class KEditor {
|
|
|
386
423
|
openMedia(kind: 'image' | 'video'): void
|
|
387
424
|
openTable(): void
|
|
388
425
|
openCustom(name: string): void
|
|
389
|
-
addButton(spec: CustomButtonSpec, options?:
|
|
426
|
+
addButton(spec: CustomButtonSpec, options?: ButtonPlaceOptions): HTMLElement | null
|
|
427
|
+
moveButton(name: string, where?: ButtonPosition): boolean
|
|
428
|
+
buttonNodes(): HTMLElement[]
|
|
390
429
|
removeButton(name: string): boolean
|
|
391
430
|
setButtonOptions(name: string, items: unknown): CustomButtonOption[]
|
|
392
431
|
}
|
|
@@ -428,8 +467,13 @@ export declare class KEditor {
|
|
|
428
467
|
cancelUploads(): this
|
|
429
468
|
|
|
430
469
|
/** 运行时新增自定义按钮,返回按钮 DOM */
|
|
431
|
-
addButton(spec: CustomButtonSpec, options?:
|
|
470
|
+
addButton(spec: CustomButtonSpec, options?: ButtonPlaceOptions): HTMLElement | null
|
|
471
|
+
/** 移动任意按钮(内置或自定义)到指定位置 */
|
|
472
|
+
moveButton(name: string, where?: ButtonPosition): boolean
|
|
432
473
|
removeButton(name: string): boolean
|
|
474
|
+
/** 运行时调整版心:{ width, mode, gap, maxWidth } */
|
|
475
|
+
setPaper(config?: { width?: number; mode?: 'fluid' | 'fixed'; gap?: number; maxWidth?: number }): { width: number; mode: 'fluid' | 'fixed'; gap: number; maxWidth: number }
|
|
476
|
+
paperOptions(): { width: number; mode: 'fluid' | 'fixed'; gap: number; maxWidth: number }
|
|
433
477
|
/** 外部灌入下拉数据(接口在编辑器之外请求时使用) */
|
|
434
478
|
setButtonOptions(name: string, items: CustomButtonOption[] | string[]): CustomButtonOption[]
|
|
435
479
|
getButtonValue(name: string): CustomButtonOption | null
|
|
@@ -462,6 +506,7 @@ export declare function replace(target: HTMLElement | string, options?: KEditorO
|
|
|
462
506
|
export declare const defaults: KEditorOptions
|
|
463
507
|
export declare const DEFAULT_TOOLBAR: ToolbarItem[]
|
|
464
508
|
export declare function normalizeCustomButtons(list: unknown): CustomButtonSpec[]
|
|
509
|
+
export declare function normalizePosition(spec: unknown): ButtonPosition | null
|
|
465
510
|
export declare function normalizeItems(raw: unknown): CustomButtonOption[]
|
|
466
511
|
export declare function exportHtml(html: string): string
|
|
467
512
|
|