kyle-editor 0.0.0-stage → 1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 kyle
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,3 +1,138 @@
1
- # Temporary Holding Version
1
+ # KEditor
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 轻量、美观的**微信公众号风格富文本编辑器**。纯前端实现,无任何后端依赖:图片/视频走**分片上传**(并发、重试、取消、秒传、断点续传),随时切换 **HTML 源码模式**查看或改写产物。支持 `<script>` 直接引入与 Vue 3 安装集成。
4
+
5
+ - 体积:`dist/keditor.umd.js` 约 139 KB(gzip 37 KB),零运行时依赖,样式随 JS 注入
6
+ - 版式:677px 正文版心、17px/1.75 行距,与公众号观感一致
7
+ - 安全:标签/属性白名单净化,拦截 `on*`、`javascript:`、`script/iframe`
8
+
9
+ ## 功能
10
+
11
+ | 分类 | 能力 |
12
+ |------|------|
13
+ | 排版 | 段落样式面板(正文/标题一/标题二/标题三,带真实字号预览与用途说明)、字号面板(12–32px)、字体颜色与背景高亮(主题色 + 标准色 + 最近使用 + 自定义取色)、粗斜下删、四种对齐、有序/无序列表、引用、表格(网格选择)、代码块、分割线、链接、清除格式 |
14
+ | 媒体 | 图片/视频**本地上传**(点击、拖拽、粘贴截图)或**直接填网络链接**插入(自动校验可访问性);分片进度与速度、取消、失败重试、多图多选、大图自动压缩、双击看原图、气泡工具条(对齐/宽度/圆角/替换/删除)、**选中图片后拖拽右下角把手实时缩放** |
15
+ | 上传 | `chunkSize / concurrency / retries / fingerprint` 可配;内置 mock、http、simple 适配器,也可自定义 `init/put/complete` |
16
+ | 源码 | 工具栏右侧常驻「源码」按钮(`⌘/Ctrl+Shift+K`),进入后正文按钮置灰;格式化缩进、复制、直接编辑并应用(回填自动净化) |
17
+ | 其他 | 实时字数/词数/图片视频统计、预览(手机/平板/电脑屏宽)、全屏编辑、撤销重做(保留光标位置)、只读、窄屏工具栏可左右滑动(常显滚动条 + 边缘渐隐 + 首次引导气泡 + 鼠标拖拽平移)且「源码/预览/全屏」固定右端 |
18
+
19
+ ## 安装
20
+
21
+ ```bash
22
+ npm install kyle-editor
23
+ # 使用 Vue 组件的项目
24
+ npm install kyle-editor vue@^3
25
+ ```
26
+
27
+ 或直接用 CDN(无需安装):
28
+
29
+ ```html
30
+ <script src="https://unpkg.com/kyle-editor/dist/keditor.umd.js"></script>
31
+ ```
32
+
33
+ > 零运行时依赖;样式随 JS 注入,**不需要额外引入 CSS**。Vue 是可选 peerDependency,只用核心 API 的项目不会被强制安装。
34
+
35
+ ## 快速开始
36
+
37
+ ### 方式一:`<script>` 引入(零构建)
38
+
39
+ ```html
40
+ <div id="editor"></div>
41
+ <script src="https://unpkg.com/kyle-editor/dist/keditor.umd.js"></script>
42
+ <!-- 本地开发时也可用相对路径:<script src="dist/keditor.umd.js"></script> -->
43
+ <script>
44
+ const editor = KEditor.create('#editor', {
45
+ placeholder: '开始撰写内容,支持拖拽 / 粘贴图片与视频…',
46
+ height: 460,
47
+ })
48
+ editor.on('change', ({ html }) => console.log(html))
49
+ </script>
50
+ ```
51
+
52
+ ### 方式二:ESM / 打包器
53
+
54
+ ```js
55
+ import KEditor from 'kyle-editor'
56
+
57
+ const editor = KEditor.create('#editor', { height: 460 })
58
+ ```
59
+
60
+ ### 方式三:Vue 3 安装集成
61
+
62
+ ```js
63
+ // main.js
64
+ import { createApp } from 'vue'
65
+ import KEditorVue from 'kyle-editor/vue'
66
+
67
+ createApp(App).use(KEditorVue).mount('#app')
68
+ ```
69
+
70
+ ```vue
71
+ <template>
72
+ <k-editor v-model="form.content" :options="options" :disabled="saving" @upload="onUpload" />
73
+ </template>
74
+
75
+ <script setup>
76
+ import { ref } from 'vue'
77
+
78
+ const form = ref({ content: '' })
79
+ const options = {
80
+ height: 420,
81
+ // 无后端时保持默认 'mock';上线时换成下面这行即可
82
+ uploader: { type: 'http', initUrl: '/api/upload/init', chunkUrl: '/api/upload/chunk', completeUrl: '/api/upload/complete' },
83
+ upload: { chunkSize: 5 * 1024 * 1024, concurrency: 4 },
84
+ }
85
+ const onUpload = (payload) => console.log(payload.stage, payload.percent)
86
+ </script>
87
+ ```
88
+
89
+ > `kyle-editor/vue` 的默认导出是**组件本身(自带 `install`)**,所以上面两种写法等价:
90
+ > `app.use(KEditorVue)` 后模板里用全局标签 `<k-editor>`;也可以 `import KEditorVue from 'kyle-editor/vue'` 直接当组件用 `<KEditorVue v-model="html" />`。
91
+ > 只想显式拿插件时用 `import { KEditorPlugin } from 'kyle-editor/vue'`。
92
+ >
93
+ > ESM / Webpack / Vite / React 用法见 [docs/integration.md](docs/integration.md)。
94
+
95
+ ## 本地运行
96
+
97
+ ```bash
98
+ npm install
99
+ npm run build # 产出 dist/(es + cjs + umd,含 Vue 版本)
100
+ npm run dev # 静态服务 http://127.0.0.1:5178
101
+ ```
102
+
103
+ 打开:
104
+
105
+ - `index.html` — 说明首页
106
+ - `demo/script.html` — UMD 引入 + 分片日志面板
107
+ - `demo/esm.html` — 自定义上传适配器演示
108
+ - `demo/vue.html` — Vue 3 组件 + `v-model`
109
+ - `test/smoke.html` — 40 条内置冒烟用例(可视化结果)
110
+
111
+ ## 验证
112
+
113
+ ```bash
114
+ npm run build
115
+ npm run dev & # 启动静态服务
116
+ ```
117
+
118
+ 当前状态:`40/40` 用例通过,demo 页面无控制台报错。
119
+
120
+ ## 文档
121
+
122
+ | 文档 | 内容 |
123
+ |------|------|
124
+ | [docs/integration.md](docs/integration.md) | Script / ESM / Vue3 / React / Nuxt 集成,常见问题 |
125
+ | [docs/api.md](docs/api.md) | 全部配置项、实例方法与事件、工具栏自定义 |
126
+ | [docs/upload-adapter.md](docs/upload-adapter.md) | 分片上传流程、后端接口约定、自定义适配器 |
127
+
128
+
129
+ ## 已知限制
130
+
131
+ - 依赖浏览器 `contenteditable` + `document.execCommand`(主流浏览器均支持,Chrome/Safari/Edge/Firefox 已验证);不兼容 IE。
132
+ - 表格支持插入与行列增删,未内置单元格合并;需要时可自行扩展 `commands.js`。
133
+ - 默认适配器产生的 `blob:` 地址仅当前会话有效,正式环境请配置真实 `uploader`(见文档)。
134
+ - 强指纹(`fingerprint: 'strong'`)依赖 `crypto.subtle`,需 HTTPS 或 localhost 环境。
135
+
136
+ ## License
137
+
138
+ MIT
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const vue = require("vue");
4
+ const kyleEditor = require("kyle-editor");
5
+ const KEditorVue = {
6
+ name: "KEditor",
7
+ props: {
8
+ modelValue: { type: String, default: "" },
9
+ options: { type: Object, default: () => ({}) },
10
+ disabled: { type: Boolean, default: false },
11
+ height: { type: Number, default: null }
12
+ },
13
+ emits: ["update:modelValue", "ready", "change", "upload", "error", "save", "blur", "focus"],
14
+ setup(props, { emit, expose }) {
15
+ const host = vue.ref(null);
16
+ const instance = vue.shallowRef(null);
17
+ const buildOptions = () => {
18
+ const opts = { ...kyleEditor.defaults, ...props.options, value: props.modelValue || "" };
19
+ if (props.height) opts.height = props.height;
20
+ opts.onChange = (html) => {
21
+ emit("update:modelValue", html);
22
+ emit("change", html);
23
+ };
24
+ opts.onReady = (editor) => emit("ready", editor);
25
+ opts.onError = (error) => emit("error", error);
26
+ opts.onUpload = (payload) => emit("upload", payload);
27
+ return opts;
28
+ };
29
+ expose({
30
+ get editor() {
31
+ return instance.value;
32
+ },
33
+ getHTML: () => {
34
+ var _a;
35
+ return ((_a = instance.value) == null ? void 0 : _a.getHTML()) || "";
36
+ },
37
+ getText: () => {
38
+ var _a;
39
+ return ((_a = instance.value) == null ? void 0 : _a.getText()) || "";
40
+ },
41
+ counts: () => {
42
+ var _a;
43
+ return ((_a = instance.value) == null ? void 0 : _a.counts()) || null;
44
+ },
45
+ focus: () => {
46
+ var _a;
47
+ return (_a = instance.value) == null ? void 0 : _a.focus();
48
+ },
49
+ setContent: (html) => {
50
+ var _a;
51
+ return (_a = instance.value) == null ? void 0 : _a.setContent(html);
52
+ },
53
+ enterSource: () => {
54
+ var _a;
55
+ return (_a = instance.value) == null ? void 0 : _a.enterSource();
56
+ },
57
+ openPreview: () => {
58
+ var _a;
59
+ return (_a = instance.value) == null ? void 0 : _a.openPreview();
60
+ }
61
+ });
62
+ vue.onMounted(() => {
63
+ instance.value = new kyleEditor.KEditor(host.value, buildOptions());
64
+ instance.value.on("save", (payload) => emit("save", payload));
65
+ instance.value.on("blur", () => emit("blur"));
66
+ instance.value.on("focus", () => emit("focus"));
67
+ host.value.__keditor__ = instance.value;
68
+ });
69
+ vue.onBeforeUnmount(() => {
70
+ var _a;
71
+ host.value.__keditor__ = null;
72
+ (_a = instance.value) == null ? void 0 : _a.destroy();
73
+ instance.value = null;
74
+ });
75
+ vue.watch(
76
+ () => props.modelValue,
77
+ (value) => {
78
+ const editor = instance.value;
79
+ if (!editor || editor.sourceMode) return;
80
+ if (value === editor.getHTML()) return;
81
+ editor.setContent(value || "", { silent: true });
82
+ }
83
+ );
84
+ vue.watch(
85
+ () => props.disabled,
86
+ (value) => {
87
+ var _a;
88
+ return (_a = instance.value) == null ? void 0 : _a.setReadOnly(value);
89
+ }
90
+ );
91
+ return () => vue.h("div", { ref: host, class: "ke-vue-host" });
92
+ }
93
+ };
94
+ const KEditorPlugin = {
95
+ install(app, { name = "KEditor" } = {}) {
96
+ app.component(name, KEditorVue);
97
+ app.config.globalProperties.$keditor = { KEditor: kyleEditor.KEditor, defaults: kyleEditor.defaults };
98
+ }
99
+ };
100
+ function useKEditor(options = {}) {
101
+ const host = vue.ref(null);
102
+ const instance = vue.shallowRef(null);
103
+ vue.onMounted(() => {
104
+ instance.value = new kyleEditor.KEditor(host.value, options);
105
+ });
106
+ vue.onBeforeUnmount(() => {
107
+ var _a;
108
+ return (_a = instance.value) == null ? void 0 : _a.destroy();
109
+ });
110
+ return { host, editor: instance };
111
+ }
112
+ KEditorVue.install = (app, options) => KEditorPlugin.install(app, options);
113
+ Object.defineProperty(exports, "KEditor", {
114
+ enumerable: true,
115
+ get: () => kyleEditor.KEditor
116
+ });
117
+ exports.KEditorPlugin = KEditorPlugin;
118
+ exports.KEditorVue = KEditorVue;
119
+ exports.default = KEditorVue;
120
+ exports.useKEditor = useKEditor;
@@ -0,0 +1,118 @@
1
+ import { ref, shallowRef, onMounted, onBeforeUnmount, watch, h } from "vue";
2
+ import { KEditor, defaults } from "kyle-editor";
3
+ import { KEditor as KEditor2 } from "kyle-editor";
4
+ const KEditorVue = {
5
+ name: "KEditor",
6
+ props: {
7
+ modelValue: { type: String, default: "" },
8
+ options: { type: Object, default: () => ({}) },
9
+ disabled: { type: Boolean, default: false },
10
+ height: { type: Number, default: null }
11
+ },
12
+ emits: ["update:modelValue", "ready", "change", "upload", "error", "save", "blur", "focus"],
13
+ setup(props, { emit, expose }) {
14
+ const host = ref(null);
15
+ const instance = shallowRef(null);
16
+ const buildOptions = () => {
17
+ const opts = { ...defaults, ...props.options, value: props.modelValue || "" };
18
+ if (props.height) opts.height = props.height;
19
+ opts.onChange = (html) => {
20
+ emit("update:modelValue", html);
21
+ emit("change", html);
22
+ };
23
+ opts.onReady = (editor) => emit("ready", editor);
24
+ opts.onError = (error) => emit("error", error);
25
+ opts.onUpload = (payload) => emit("upload", payload);
26
+ return opts;
27
+ };
28
+ expose({
29
+ get editor() {
30
+ return instance.value;
31
+ },
32
+ getHTML: () => {
33
+ var _a;
34
+ return ((_a = instance.value) == null ? void 0 : _a.getHTML()) || "";
35
+ },
36
+ getText: () => {
37
+ var _a;
38
+ return ((_a = instance.value) == null ? void 0 : _a.getText()) || "";
39
+ },
40
+ counts: () => {
41
+ var _a;
42
+ return ((_a = instance.value) == null ? void 0 : _a.counts()) || null;
43
+ },
44
+ focus: () => {
45
+ var _a;
46
+ return (_a = instance.value) == null ? void 0 : _a.focus();
47
+ },
48
+ setContent: (html) => {
49
+ var _a;
50
+ return (_a = instance.value) == null ? void 0 : _a.setContent(html);
51
+ },
52
+ enterSource: () => {
53
+ var _a;
54
+ return (_a = instance.value) == null ? void 0 : _a.enterSource();
55
+ },
56
+ openPreview: () => {
57
+ var _a;
58
+ return (_a = instance.value) == null ? void 0 : _a.openPreview();
59
+ }
60
+ });
61
+ onMounted(() => {
62
+ instance.value = new KEditor(host.value, buildOptions());
63
+ instance.value.on("save", (payload) => emit("save", payload));
64
+ instance.value.on("blur", () => emit("blur"));
65
+ instance.value.on("focus", () => emit("focus"));
66
+ host.value.__keditor__ = instance.value;
67
+ });
68
+ onBeforeUnmount(() => {
69
+ var _a;
70
+ host.value.__keditor__ = null;
71
+ (_a = instance.value) == null ? void 0 : _a.destroy();
72
+ instance.value = null;
73
+ });
74
+ watch(
75
+ () => props.modelValue,
76
+ (value) => {
77
+ const editor = instance.value;
78
+ if (!editor || editor.sourceMode) return;
79
+ if (value === editor.getHTML()) return;
80
+ editor.setContent(value || "", { silent: true });
81
+ }
82
+ );
83
+ watch(
84
+ () => props.disabled,
85
+ (value) => {
86
+ var _a;
87
+ return (_a = instance.value) == null ? void 0 : _a.setReadOnly(value);
88
+ }
89
+ );
90
+ return () => h("div", { ref: host, class: "ke-vue-host" });
91
+ }
92
+ };
93
+ const KEditorPlugin = {
94
+ install(app, { name = "KEditor" } = {}) {
95
+ app.component(name, KEditorVue);
96
+ app.config.globalProperties.$keditor = { KEditor, defaults };
97
+ }
98
+ };
99
+ function useKEditor(options = {}) {
100
+ const host = ref(null);
101
+ const instance = shallowRef(null);
102
+ onMounted(() => {
103
+ instance.value = new KEditor(host.value, options);
104
+ });
105
+ onBeforeUnmount(() => {
106
+ var _a;
107
+ return (_a = instance.value) == null ? void 0 : _a.destroy();
108
+ });
109
+ return { host, editor: instance };
110
+ }
111
+ KEditorVue.install = (app, options) => KEditorPlugin.install(app, options);
112
+ export {
113
+ KEditor2 as KEditor,
114
+ KEditorPlugin,
115
+ KEditorVue,
116
+ KEditorVue as default,
117
+ useKEditor
118
+ };
@@ -0,0 +1,122 @@
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("vue"), require("kyle-editor")) : typeof define === "function" && define.amd ? define(["exports", "vue", "kyle-editor"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.KEditorVue = {}, global.Vue, global.KEditor));
3
+ })(this, function(exports2, vue, kyleEditor) {
4
+ "use strict";
5
+ const KEditorVue = {
6
+ name: "KEditor",
7
+ props: {
8
+ modelValue: { type: String, default: "" },
9
+ options: { type: Object, default: () => ({}) },
10
+ disabled: { type: Boolean, default: false },
11
+ height: { type: Number, default: null }
12
+ },
13
+ emits: ["update:modelValue", "ready", "change", "upload", "error", "save", "blur", "focus"],
14
+ setup(props, { emit, expose }) {
15
+ const host = vue.ref(null);
16
+ const instance = vue.shallowRef(null);
17
+ const buildOptions = () => {
18
+ const opts = { ...kyleEditor.defaults, ...props.options, value: props.modelValue || "" };
19
+ if (props.height) opts.height = props.height;
20
+ opts.onChange = (html) => {
21
+ emit("update:modelValue", html);
22
+ emit("change", html);
23
+ };
24
+ opts.onReady = (editor) => emit("ready", editor);
25
+ opts.onError = (error) => emit("error", error);
26
+ opts.onUpload = (payload) => emit("upload", payload);
27
+ return opts;
28
+ };
29
+ expose({
30
+ get editor() {
31
+ return instance.value;
32
+ },
33
+ getHTML: () => {
34
+ var _a;
35
+ return ((_a = instance.value) == null ? void 0 : _a.getHTML()) || "";
36
+ },
37
+ getText: () => {
38
+ var _a;
39
+ return ((_a = instance.value) == null ? void 0 : _a.getText()) || "";
40
+ },
41
+ counts: () => {
42
+ var _a;
43
+ return ((_a = instance.value) == null ? void 0 : _a.counts()) || null;
44
+ },
45
+ focus: () => {
46
+ var _a;
47
+ return (_a = instance.value) == null ? void 0 : _a.focus();
48
+ },
49
+ setContent: (html) => {
50
+ var _a;
51
+ return (_a = instance.value) == null ? void 0 : _a.setContent(html);
52
+ },
53
+ enterSource: () => {
54
+ var _a;
55
+ return (_a = instance.value) == null ? void 0 : _a.enterSource();
56
+ },
57
+ openPreview: () => {
58
+ var _a;
59
+ return (_a = instance.value) == null ? void 0 : _a.openPreview();
60
+ }
61
+ });
62
+ vue.onMounted(() => {
63
+ instance.value = new kyleEditor.KEditor(host.value, buildOptions());
64
+ instance.value.on("save", (payload) => emit("save", payload));
65
+ instance.value.on("blur", () => emit("blur"));
66
+ instance.value.on("focus", () => emit("focus"));
67
+ host.value.__keditor__ = instance.value;
68
+ });
69
+ vue.onBeforeUnmount(() => {
70
+ var _a;
71
+ host.value.__keditor__ = null;
72
+ (_a = instance.value) == null ? void 0 : _a.destroy();
73
+ instance.value = null;
74
+ });
75
+ vue.watch(
76
+ () => props.modelValue,
77
+ (value) => {
78
+ const editor = instance.value;
79
+ if (!editor || editor.sourceMode) return;
80
+ if (value === editor.getHTML()) return;
81
+ editor.setContent(value || "", { silent: true });
82
+ }
83
+ );
84
+ vue.watch(
85
+ () => props.disabled,
86
+ (value) => {
87
+ var _a;
88
+ return (_a = instance.value) == null ? void 0 : _a.setReadOnly(value);
89
+ }
90
+ );
91
+ return () => vue.h("div", { ref: host, class: "ke-vue-host" });
92
+ }
93
+ };
94
+ const KEditorPlugin = {
95
+ install(app, { name = "KEditor" } = {}) {
96
+ app.component(name, KEditorVue);
97
+ app.config.globalProperties.$keditor = { KEditor: kyleEditor.KEditor, defaults: kyleEditor.defaults };
98
+ }
99
+ };
100
+ function useKEditor(options = {}) {
101
+ const host = vue.ref(null);
102
+ const instance = vue.shallowRef(null);
103
+ vue.onMounted(() => {
104
+ instance.value = new kyleEditor.KEditor(host.value, options);
105
+ });
106
+ vue.onBeforeUnmount(() => {
107
+ var _a;
108
+ return (_a = instance.value) == null ? void 0 : _a.destroy();
109
+ });
110
+ return { host, editor: instance };
111
+ }
112
+ KEditorVue.install = (app, options) => KEditorPlugin.install(app, options);
113
+ Object.defineProperty(exports2, "KEditor", {
114
+ enumerable: true,
115
+ get: () => kyleEditor.KEditor
116
+ });
117
+ exports2.KEditorPlugin = KEditorPlugin;
118
+ exports2.KEditorVue = KEditorVue;
119
+ exports2.default = KEditorVue;
120
+ exports2.useKEditor = useKEditor;
121
+ Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
122
+ });