@mnykj/wangeditoroptimize-for-vue 1.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/README.md +18 -0
- package/dist/index.esm.js +213 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/src/components/Editor.vue.d.ts +48 -0
- package/dist/src/components/Toolbar.vue.d.ts +32 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/shims-vue.d.ts +6 -0
- package/dist/src/utils/create-info.d.ts +5 -0
- package/dist/src/vite-env.d.ts +1 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @mnykj/wangeditoroptimize-for-vue
|
|
2
|
+
|
|
3
|
+
Vue3 组件封装,配合 [`@mnykj/wangeditoroptimize`](https://www.npmjs.com/package/@mnykj/wangeditoroptimize) 使用。
|
|
4
|
+
|
|
5
|
+
基于官方 `@wangeditor/editor-for-vue` fork,peer 依赖指向本组织编辑器包,避免与官方 `@wangeditor/*` 冲突。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @mnykj/wangeditoroptimize @mnykj/wangeditoroptimize-for-vue --save
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 使用
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Editor, Toolbar } from '@mnykj/wangeditoroptimize-for-vue'
|
|
17
|
+
import '@mnykj/wangeditoroptimize/dist/css/style.css'
|
|
18
|
+
```
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { defineComponent, ref, shallowRef, onMounted, watch, toRaw, openBlock, createElementBlock, watchEffect } from "vue";
|
|
21
|
+
import { createEditor, DomEditor, createToolbar } from "@mnykj/wangeditoroptimize";
|
|
22
|
+
function genErrorInfo(fnName) {
|
|
23
|
+
let info = `\u8BF7\u4F7F\u7528 '@${fnName}' \u4E8B\u4EF6\uFF0C\u4E0D\u8981\u653E\u5728 props \u4E2D`;
|
|
24
|
+
info += `
|
|
25
|
+
Please use '@${fnName}' event instead of props`;
|
|
26
|
+
return info;
|
|
27
|
+
}
|
|
28
|
+
var _export_sfc = (sfc, props) => {
|
|
29
|
+
for (const [key, val] of props) {
|
|
30
|
+
sfc[key] = val;
|
|
31
|
+
}
|
|
32
|
+
return sfc;
|
|
33
|
+
};
|
|
34
|
+
const _sfc_main$1 = defineComponent({
|
|
35
|
+
props: {
|
|
36
|
+
mode: {
|
|
37
|
+
type: String,
|
|
38
|
+
default: "default"
|
|
39
|
+
},
|
|
40
|
+
defaultContent: {
|
|
41
|
+
type: Array,
|
|
42
|
+
default: []
|
|
43
|
+
},
|
|
44
|
+
defaultHtml: {
|
|
45
|
+
type: String,
|
|
46
|
+
default: ""
|
|
47
|
+
},
|
|
48
|
+
defaultConfig: {
|
|
49
|
+
type: Object,
|
|
50
|
+
default: {}
|
|
51
|
+
},
|
|
52
|
+
modelValue: {
|
|
53
|
+
type: String,
|
|
54
|
+
default: ""
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
setup(props, context) {
|
|
58
|
+
const box = ref(null);
|
|
59
|
+
const editorRef = shallowRef(null);
|
|
60
|
+
const curValue = ref("");
|
|
61
|
+
const initEditor = () => {
|
|
62
|
+
if (!box.value)
|
|
63
|
+
return;
|
|
64
|
+
const defaultContent = toRaw(props.defaultContent);
|
|
65
|
+
createEditor({
|
|
66
|
+
selector: box.value,
|
|
67
|
+
mode: props.mode,
|
|
68
|
+
content: defaultContent || [],
|
|
69
|
+
html: props.defaultHtml || props.modelValue || "",
|
|
70
|
+
config: __spreadProps(__spreadValues({}, props.defaultConfig), {
|
|
71
|
+
onCreated(editor) {
|
|
72
|
+
editorRef.value = editor;
|
|
73
|
+
context.emit("onCreated", editor);
|
|
74
|
+
if (props.defaultConfig.onCreated) {
|
|
75
|
+
const info = genErrorInfo("onCreated");
|
|
76
|
+
throw new Error(info);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
onChange(editor) {
|
|
80
|
+
const editorHtml = editor.getHtml();
|
|
81
|
+
curValue.value = editorHtml;
|
|
82
|
+
context.emit("update:modelValue", editorHtml);
|
|
83
|
+
context.emit("onChange", editor);
|
|
84
|
+
if (props.defaultConfig.onChange) {
|
|
85
|
+
const info = genErrorInfo("onChange");
|
|
86
|
+
throw new Error(info);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
onDestroyed(editor) {
|
|
90
|
+
context.emit("onDestroyed", editor);
|
|
91
|
+
if (props.defaultConfig.onDestroyed) {
|
|
92
|
+
const info = genErrorInfo("onDestroyed");
|
|
93
|
+
throw new Error(info);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
onMaxLength(editor) {
|
|
97
|
+
context.emit("onMaxLength", editor);
|
|
98
|
+
if (props.defaultConfig.onMaxLength) {
|
|
99
|
+
const info = genErrorInfo("onMaxLength");
|
|
100
|
+
throw new Error(info);
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
onFocus(editor) {
|
|
104
|
+
context.emit("onFocus", editor);
|
|
105
|
+
if (props.defaultConfig.onFocus) {
|
|
106
|
+
const info = genErrorInfo("onFocus");
|
|
107
|
+
throw new Error(info);
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
onBlur(editor) {
|
|
111
|
+
context.emit("onBlur", editor);
|
|
112
|
+
if (props.defaultConfig.onBlur) {
|
|
113
|
+
const info = genErrorInfo("onBlur");
|
|
114
|
+
throw new Error(info);
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
customAlert(info, type) {
|
|
118
|
+
context.emit("customAlert", info, type);
|
|
119
|
+
if (props.defaultConfig.customAlert) {
|
|
120
|
+
const info2 = genErrorInfo("customAlert");
|
|
121
|
+
throw new Error(info2);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
customPaste: (editor, event) => {
|
|
125
|
+
if (props.defaultConfig.customPaste) {
|
|
126
|
+
const info = genErrorInfo("customPaste");
|
|
127
|
+
throw new Error(info);
|
|
128
|
+
}
|
|
129
|
+
let res;
|
|
130
|
+
context.emit("customPaste", editor, event, (val) => {
|
|
131
|
+
res = val;
|
|
132
|
+
});
|
|
133
|
+
return res;
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
function setHtml(newHtml) {
|
|
139
|
+
const editor = editorRef.value;
|
|
140
|
+
if (editor == null)
|
|
141
|
+
return;
|
|
142
|
+
editor.setHtml(newHtml);
|
|
143
|
+
}
|
|
144
|
+
onMounted(() => {
|
|
145
|
+
initEditor();
|
|
146
|
+
});
|
|
147
|
+
watch(() => props.modelValue, (newVal) => {
|
|
148
|
+
if (newVal === curValue.value)
|
|
149
|
+
return;
|
|
150
|
+
setHtml(newVal);
|
|
151
|
+
});
|
|
152
|
+
return {
|
|
153
|
+
box
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
const _hoisted_1$1 = {
|
|
158
|
+
ref: "box",
|
|
159
|
+
style: { "height": "100%" }
|
|
160
|
+
};
|
|
161
|
+
function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
|
|
162
|
+
return openBlock(), createElementBlock("div", _hoisted_1$1, null, 512);
|
|
163
|
+
}
|
|
164
|
+
var Editor = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
|
|
165
|
+
const _sfc_main = defineComponent({
|
|
166
|
+
props: {
|
|
167
|
+
editor: {
|
|
168
|
+
type: Object
|
|
169
|
+
},
|
|
170
|
+
mode: {
|
|
171
|
+
type: String,
|
|
172
|
+
default: "default"
|
|
173
|
+
},
|
|
174
|
+
defaultConfig: {
|
|
175
|
+
type: Object,
|
|
176
|
+
default: {}
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
setup(props) {
|
|
180
|
+
const selector = ref(null);
|
|
181
|
+
const create = (editor) => {
|
|
182
|
+
if (!selector.value)
|
|
183
|
+
return;
|
|
184
|
+
if (editor == null) {
|
|
185
|
+
throw new Error("Not found instance of Editor when create <Toolbar/> component");
|
|
186
|
+
}
|
|
187
|
+
if (DomEditor.getToolbar(editor))
|
|
188
|
+
return;
|
|
189
|
+
createToolbar({
|
|
190
|
+
editor,
|
|
191
|
+
selector: selector.value || "<div></div>",
|
|
192
|
+
mode: props.mode,
|
|
193
|
+
config: props.defaultConfig
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
watchEffect(() => {
|
|
197
|
+
const { editor } = props;
|
|
198
|
+
if (editor == null)
|
|
199
|
+
return;
|
|
200
|
+
create(editor);
|
|
201
|
+
});
|
|
202
|
+
return {
|
|
203
|
+
selector
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
const _hoisted_1 = { ref: "selector" };
|
|
208
|
+
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
209
|
+
return openBlock(), createElementBlock("div", _hoisted_1, null, 512);
|
|
210
|
+
}
|
|
211
|
+
var Toolbar = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
|
|
212
|
+
export { Editor, Toolbar };
|
|
213
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/utils/create-info.ts","../plugin-vue:export-helper","../src/components/Editor.vue","../src/components/Toolbar.vue"],"sourcesContent":["/**\n * @description 错误提示信息\n * @author liuqh\n */\nexport function genErrorInfo(fnName: string): string {\n let info = `请使用 '@${fnName}' 事件,不要放在 props 中`\n info += `\\nPlease use '@${fnName}' event instead of props`\n return info\n}","\nexport default (sfc, props) => {\n for (const [key, val] of props) {\n sfc[key] = val\n }\n return sfc\n}\n","<template>\n <div ref=\"box\" style=\"height: 100%\"></div>\n</template>\n\n<script lang=\"ts\">\nimport { onMounted, defineComponent, ref, PropType, toRaw, watch, shallowRef } from 'vue'\nimport { createEditor, IEditorConfig, SlateDescendant, IDomEditor } from '@mnykj/wangeditoroptimize'\nimport { genErrorInfo } from '../utils/create-info'\n\nexport default defineComponent({\n props: {\n /** 编辑器模式 */\n mode: {\n type: String,\n default: 'default',\n },\n /** 编辑器默认内容 */\n defaultContent: {\n type: Array as PropType<SlateDescendant[]>,\n default: [],\n },\n defaultHtml: {\n type: String,\n default: '',\n },\n /** 编辑器默认配置 */\n defaultConfig: {\n type: Object as PropType<Partial<IEditorConfig>>,\n default: {},\n },\n /* 自定义 v-model */\n modelValue: {\n type: String,\n default: '',\n },\n },\n setup(props, context) {\n const box = ref(null) // 编辑器容器\n\n const editorRef = shallowRef<null | IDomEditor>(null) // editor 实例,必须用 shallowRef\n\n const curValue = ref('') // 记录 editor 当前 html 内容\n\n /**\n * 初始化编辑器\n */\n const initEditor = () => {\n if (!box.value) return\n // 获取原始数据,解除响应式特性\n const defaultContent = toRaw(props.defaultContent)\n\n createEditor({\n selector: box.value! as Element,\n mode: props.mode,\n content: defaultContent || [],\n html: props.defaultHtml || props.modelValue || '',\n config: {\n ...props.defaultConfig,\n onCreated(editor) {\n editorRef.value = editor // 记录 editor 实例\n\n context.emit('onCreated', editor)\n\n if (props.defaultConfig.onCreated) {\n const info = genErrorInfo('onCreated')\n throw new Error(info)\n }\n },\n onChange(editor) {\n const editorHtml = editor.getHtml()\n curValue.value = editorHtml // 记录当前内容\n context.emit('update:modelValue', editorHtml) // 触发 v-model 值变化\n\n context.emit('onChange', editor)\n if (props.defaultConfig.onChange) {\n const info = genErrorInfo('onChange')\n throw new Error(info)\n }\n },\n onDestroyed(editor) {\n context.emit('onDestroyed', editor)\n if (props.defaultConfig.onDestroyed) {\n const info = genErrorInfo('onDestroyed')\n throw new Error(info)\n }\n },\n onMaxLength(editor) {\n context.emit('onMaxLength', editor)\n if (props.defaultConfig.onMaxLength) {\n const info = genErrorInfo('onMaxLength')\n throw new Error(info)\n }\n },\n onFocus(editor) {\n context.emit('onFocus', editor)\n if (props.defaultConfig.onFocus) {\n const info = genErrorInfo('onFocus')\n throw new Error(info)\n }\n },\n onBlur(editor) {\n context.emit('onBlur', editor)\n if (props.defaultConfig.onBlur) {\n const info = genErrorInfo('onBlur')\n throw new Error(info)\n }\n },\n customAlert(info, type) {\n context.emit('customAlert', info, type)\n // @ts-ignore\n if (props.defaultConfig.customAlert) {\n const info = genErrorInfo('customAlert')\n throw new Error(info)\n }\n },\n customPaste: (editor, event): any => {\n if (props.defaultConfig.customPaste) {\n const info = genErrorInfo('customPaste')\n throw new Error(info)\n }\n let res\n context.emit('customPaste', editor, event, (val: boolean) => {\n res = val\n })\n return res\n },\n },\n })\n }\n\n /**\n * 设置 HTML\n * @param newHtml new html\n */\n function setHtml(newHtml: string) {\n const editor = editorRef.value\n if (editor == null) return\n editor.setHtml(newHtml)\n }\n\n /**\n * 元素挂在后初始化编辑器\n */\n onMounted(() => {\n initEditor()\n })\n\n // 监听 v-model 值变化\n watch(\n () => props.modelValue,\n newVal => {\n if (newVal === curValue.value) return // 和当前内容一样,则忽略\n\n // 重新设置 HTML\n setHtml(newVal)\n }\n )\n\n return {\n box,\n }\n },\n})\n</script>\n","<template>\n <div ref=\"selector\"></div>\n</template>\n<script lang=\"ts\">\nimport { defineComponent, ref, watchEffect, PropType } from 'vue'\nimport { createToolbar, IToolbarConfig, IDomEditor, DomEditor } from '@mnykj/wangeditoroptimize'\n\nexport default defineComponent({\n props: {\n // editor 实例\n editor: {\n type: Object as PropType<IDomEditor>\n },\n /** 编辑器模式 */\n mode: {\n type: String,\n default: 'default',\n },\n /** 编辑器默认配置 */\n defaultConfig: {\n type: Object as PropType<Partial<IToolbarConfig>>,\n default: {},\n },\n },\n setup(props) {\n // toolbar 容器\n const selector = ref(null)\n\n /**\n * 初始化 toolbar\n */\n const create = (editor: IDomEditor) => {\n if (!selector.value) return\n if (editor == null) {\n throw new Error('Not found instance of Editor when create <Toolbar/> component')\n }\n if (DomEditor.getToolbar(editor)) return // 不重复创建\n\n createToolbar({\n editor,\n selector: (selector.value! as Element) || '<div></div>',\n mode: props.mode,\n config: props.defaultConfig,\n })\n }\n\n watchEffect( () => {\n const { editor } = props\n if (editor == null) return\n create(editor) // 初始化 toolbar\n })\n\n return {\n selector,\n }\n },\n})\n</script>\n"],"names":["_sfc_main","_hoisted_1"],"mappings":";;;;;;;;;;;;;;;;;;;;;sBAI6B,QAAwB;MAC/C,OAAO,wBAAS;UACZ;AAAA,eAAkB;SACnB;AAAA;ACNT,kBAAe,CAAC,KAAK,UAAU;AAC7B,aAAW,CAAC,KAAK,QAAQ,OAAO;AAC9B,QAAI,OAAO;AAAA;AAEb,SAAO;AAAA;ACIT,MAAKA,cAAa,gBAAa;AAAA,EAC7B,OAAO;AAAA,IAEL,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,SAAS;AAAA;AAAA,IAGX,gBAA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AA;;2BApDJ,yCAA0B;;;;;"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var M=Object.defineProperty,H=Object.defineProperties;var P=Object.getOwnPropertyDescriptors;var C=Object.getOwnPropertySymbols;var S=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable;var E=(o,e,f)=>e in o?M(o,e,{enumerable:!0,configurable:!0,writable:!0,value:f}):o[e]=f,w=(o,e)=>{for(var f in e||(e={}))S.call(e,f)&&E(o,f,e[f]);if(C)for(var f of C(e))V.call(e,f)&&E(o,f,e[f]);return o},_=(o,e)=>H(o,P(e));(function(o,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("vue"),require("@mnykj/wangeditoroptimize")):typeof define=="function"&&define.amd?define(["exports","vue","@mnykj/wangeditoroptimize"],e):(o=typeof globalThis!="undefined"?globalThis:o||self,e(o.WangEditorForVue={},o.Vue,o.editor))})(this,function(o,e,f){"use strict";function a(t){let n=`\u8BF7\u4F7F\u7528 '@${t}' \u4E8B\u4EF6\uFF0C\u4E0D\u8981\u653E\u5728 props \u4E2D`;return n+=`
|
|
2
|
+
Please use '@${t}' event instead of props`,n}var h=(t,n)=>{for(const[l,i]of n)t[l]=i;return t};const y=e.defineComponent({props:{mode:{type:String,default:"default"},defaultContent:{type:Array,default:[]},defaultHtml:{type:String,default:""},defaultConfig:{type:Object,default:{}},modelValue:{type:String,default:""}},setup(t,n){const l=e.ref(null),i=e.shallowRef(null),s=e.ref(""),m=()=>{if(!l.value)return;const d=e.toRaw(t.defaultContent);f.createEditor({selector:l.value,mode:t.mode,content:d||[],html:t.defaultHtml||t.modelValue||"",config:_(w({},t.defaultConfig),{onCreated(r){if(i.value=r,n.emit("onCreated",r),t.defaultConfig.onCreated){const u=a("onCreated");throw new Error(u)}},onChange(r){const u=r.getHtml();if(s.value=u,n.emit("update:modelValue",u),n.emit("onChange",r),t.defaultConfig.onChange){const c=a("onChange");throw new Error(c)}},onDestroyed(r){if(n.emit("onDestroyed",r),t.defaultConfig.onDestroyed){const u=a("onDestroyed");throw new Error(u)}},onMaxLength(r){if(n.emit("onMaxLength",r),t.defaultConfig.onMaxLength){const u=a("onMaxLength");throw new Error(u)}},onFocus(r){if(n.emit("onFocus",r),t.defaultConfig.onFocus){const u=a("onFocus");throw new Error(u)}},onBlur(r){if(n.emit("onBlur",r),t.defaultConfig.onBlur){const u=a("onBlur");throw new Error(u)}},customAlert(r,u){if(n.emit("customAlert",r,u),t.defaultConfig.customAlert){const c=a("customAlert");throw new Error(c)}},customPaste:(r,u)=>{if(t.defaultConfig.customPaste){const g=a("customPaste");throw new Error(g)}let c;return n.emit("customPaste",r,u,g=>{c=g}),c}})})};function D(d){const r=i.value;r!=null&&r.setHtml(d)}return e.onMounted(()=>{m()}),e.watch(()=>t.modelValue,d=>{d!==s.value&&D(d)}),{box:l}}}),b={ref:"box",style:{height:"100%"}};function F(t,n,l,i,s,m){return e.openBlock(),e.createElementBlock("div",b,null,512)}var $=h(y,[["render",F]]);const B=e.defineComponent({props:{editor:{type:Object},mode:{type:String,default:"default"},defaultConfig:{type:Object,default:{}}},setup(t){const n=e.ref(null),l=i=>{if(!!n.value){if(i==null)throw new Error("Not found instance of Editor when create <Toolbar/> component");f.DomEditor.getToolbar(i)||f.createToolbar({editor:i,selector:n.value||"<div></div>",mode:t.mode,config:t.defaultConfig})}};return e.watchEffect(()=>{const{editor:i}=t;i!=null&&l(i)}),{selector:n}}}),p={ref:"selector"};function T(t,n,l,i,s,m){return e.openBlock(),e.createElementBlock("div",p,null,512)}var v=h(B,[["render",T]]);o.Editor=$,o.Toolbar=v,Object.defineProperty(o,"__esModule",{value:!0}),o[Symbol.toStringTag]="Module"});
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/utils/create-info.ts","../plugin-vue:export-helper","../src/components/Editor.vue","../src/components/Toolbar.vue"],"sourcesContent":["/**\n * @description 错误提示信息\n * @author liuqh\n */\nexport function genErrorInfo(fnName: string): string {\n let info = `请使用 '@${fnName}' 事件,不要放在 props 中`\n info += `\\nPlease use '@${fnName}' event instead of props`\n return info\n}","\nexport default (sfc, props) => {\n for (const [key, val] of props) {\n sfc[key] = val\n }\n return sfc\n}\n","<template>\n <div ref=\"box\" style=\"height: 100%\"></div>\n</template>\n\n<script lang=\"ts\">\nimport { onMounted, defineComponent, ref, PropType, toRaw, watch, shallowRef } from 'vue'\nimport { createEditor, IEditorConfig, SlateDescendant, IDomEditor } from '@mnykj/wangeditoroptimize'\nimport { genErrorInfo } from '../utils/create-info'\n\nexport default defineComponent({\n props: {\n /** 编辑器模式 */\n mode: {\n type: String,\n default: 'default',\n },\n /** 编辑器默认内容 */\n defaultContent: {\n type: Array as PropType<SlateDescendant[]>,\n default: [],\n },\n defaultHtml: {\n type: String,\n default: '',\n },\n /** 编辑器默认配置 */\n defaultConfig: {\n type: Object as PropType<Partial<IEditorConfig>>,\n default: {},\n },\n /* 自定义 v-model */\n modelValue: {\n type: String,\n default: '',\n },\n },\n setup(props, context) {\n const box = ref(null) // 编辑器容器\n\n const editorRef = shallowRef<null | IDomEditor>(null) // editor 实例,必须用 shallowRef\n\n const curValue = ref('') // 记录 editor 当前 html 内容\n\n /**\n * 初始化编辑器\n */\n const initEditor = () => {\n if (!box.value) return\n // 获取原始数据,解除响应式特性\n const defaultContent = toRaw(props.defaultContent)\n\n createEditor({\n selector: box.value! as Element,\n mode: props.mode,\n content: defaultContent || [],\n html: props.defaultHtml || props.modelValue || '',\n config: {\n ...props.defaultConfig,\n onCreated(editor) {\n editorRef.value = editor // 记录 editor 实例\n\n context.emit('onCreated', editor)\n\n if (props.defaultConfig.onCreated) {\n const info = genErrorInfo('onCreated')\n throw new Error(info)\n }\n },\n onChange(editor) {\n const editorHtml = editor.getHtml()\n curValue.value = editorHtml // 记录当前内容\n context.emit('update:modelValue', editorHtml) // 触发 v-model 值变化\n\n context.emit('onChange', editor)\n if (props.defaultConfig.onChange) {\n const info = genErrorInfo('onChange')\n throw new Error(info)\n }\n },\n onDestroyed(editor) {\n context.emit('onDestroyed', editor)\n if (props.defaultConfig.onDestroyed) {\n const info = genErrorInfo('onDestroyed')\n throw new Error(info)\n }\n },\n onMaxLength(editor) {\n context.emit('onMaxLength', editor)\n if (props.defaultConfig.onMaxLength) {\n const info = genErrorInfo('onMaxLength')\n throw new Error(info)\n }\n },\n onFocus(editor) {\n context.emit('onFocus', editor)\n if (props.defaultConfig.onFocus) {\n const info = genErrorInfo('onFocus')\n throw new Error(info)\n }\n },\n onBlur(editor) {\n context.emit('onBlur', editor)\n if (props.defaultConfig.onBlur) {\n const info = genErrorInfo('onBlur')\n throw new Error(info)\n }\n },\n customAlert(info, type) {\n context.emit('customAlert', info, type)\n // @ts-ignore\n if (props.defaultConfig.customAlert) {\n const info = genErrorInfo('customAlert')\n throw new Error(info)\n }\n },\n customPaste: (editor, event): any => {\n if (props.defaultConfig.customPaste) {\n const info = genErrorInfo('customPaste')\n throw new Error(info)\n }\n let res\n context.emit('customPaste', editor, event, (val: boolean) => {\n res = val\n })\n return res\n },\n },\n })\n }\n\n /**\n * 设置 HTML\n * @param newHtml new html\n */\n function setHtml(newHtml: string) {\n const editor = editorRef.value\n if (editor == null) return\n editor.setHtml(newHtml)\n }\n\n /**\n * 元素挂在后初始化编辑器\n */\n onMounted(() => {\n initEditor()\n })\n\n // 监听 v-model 值变化\n watch(\n () => props.modelValue,\n newVal => {\n if (newVal === curValue.value) return // 和当前内容一样,则忽略\n\n // 重新设置 HTML\n setHtml(newVal)\n }\n )\n\n return {\n box,\n }\n },\n})\n</script>\n","<template>\n <div ref=\"selector\"></div>\n</template>\n<script lang=\"ts\">\nimport { defineComponent, ref, watchEffect, PropType } from 'vue'\nimport { createToolbar, IToolbarConfig, IDomEditor, DomEditor } from '@mnykj/wangeditoroptimize'\n\nexport default defineComponent({\n props: {\n // editor 实例\n editor: {\n type: Object as PropType<IDomEditor>\n },\n /** 编辑器模式 */\n mode: {\n type: String,\n default: 'default',\n },\n /** 编辑器默认配置 */\n defaultConfig: {\n type: Object as PropType<Partial<IToolbarConfig>>,\n default: {},\n },\n },\n setup(props) {\n // toolbar 容器\n const selector = ref(null)\n\n /**\n * 初始化 toolbar\n */\n const create = (editor: IDomEditor) => {\n if (!selector.value) return\n if (editor == null) {\n throw new Error('Not found instance of Editor when create <Toolbar/> component')\n }\n if (DomEditor.getToolbar(editor)) return // 不重复创建\n\n createToolbar({\n editor,\n selector: (selector.value! as Element) || '<div></div>',\n mode: props.mode,\n config: props.defaultConfig,\n })\n }\n\n watchEffect( () => {\n const { editor } = props\n if (editor == null) return\n create(editor) // 初始化 toolbar\n })\n\n return {\n selector,\n }\n },\n})\n</script>\n"],"names":["_sfc_main","defineComponent","ref","shallowRef","toRaw","_hoisted_1","editor","DomEditor"],"mappings":"6wBAI6B,EAAwB,IAC/C,GAAO,wBAAS,uEACZ;AAAA,eAAkB,4BACnB,QCNM,CAAC,EAAK,IAAU,CAC7B,SAAW,CAAC,EAAK,IAAQ,GACvB,EAAI,GAAO,EAEb,MAAO,ICIT,KAAKA,GAAaC,kBAAa,CAC7B,MAAO,CAEL,KAAM,CACJ,KAAM,OACN,QAAS,WAGX,eAAgB,CACd,KAAM,MACN,QAAS,IAEX,YAAa,CACX,KAAM,OACN,QAAS,IAGX,cAAe,CACb,KAAM,OACN,QAAS,IAGX,WAAY,CACV,KAAM,OACN,QAAS,KAGb,MAAM,EAAO,EAAS,MACd,GAAMC,MAAI,MAEV,EAAYC,aAA8B,MAE1C,EAAWD,MAAI,IAKf,EAAa,IAAM,IACnB,CAAC,EAAI,kBAEH,GAAiBE,QAAM,EAAM,+BAEtB,CACX,SAAU,EAAI,MACd,KAAM,EAAM,KACZ,QAAS,GAAkB,GAC3B,KAAM,EAAM,aAAe,EAAM,YAAc,GAC/C,OAAQ,OACH,EAAM,eADH,CAEN,UAAU,EAAQ,MACN,MAAQ,IAEV,KAAK,YAAa,GAEtB,EA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EAAS,AAACI,GAAuB,IACjC,EAAC,EAAS,UACVA,GAAU,UACN,IAAI,OAAM,iEAEdC,YAAU,WAAWD,oBAEX,QACZA,EACA,SAAW,EAAS,OAAsB,cAC1C,KAAM,EAAM,KACZ,OAAQ,EAAM,uCAIL,IAAM,MACX,CAAE,UAAW,EACf,GAAU,QACP,KAGF,CACL,+CApDJ,UAA0B"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { PropType } from 'vue';
|
|
2
|
+
import { IEditorConfig, SlateDescendant } from '@mnykj/wangeditoroptimize';
|
|
3
|
+
declare const _default: import("vue").DefineComponent<{
|
|
4
|
+
/** 编辑器模式 */
|
|
5
|
+
mode: {
|
|
6
|
+
type: StringConstructor;
|
|
7
|
+
default: string;
|
|
8
|
+
};
|
|
9
|
+
/** 编辑器默认内容 */
|
|
10
|
+
defaultContent: {
|
|
11
|
+
type: PropType<SlateDescendant[]>;
|
|
12
|
+
default: never[];
|
|
13
|
+
};
|
|
14
|
+
defaultHtml: {
|
|
15
|
+
type: StringConstructor;
|
|
16
|
+
default: string;
|
|
17
|
+
};
|
|
18
|
+
/** 编辑器默认配置 */
|
|
19
|
+
defaultConfig: {
|
|
20
|
+
type: PropType<Partial<IEditorConfig>>;
|
|
21
|
+
default: {};
|
|
22
|
+
};
|
|
23
|
+
modelValue: {
|
|
24
|
+
type: StringConstructor;
|
|
25
|
+
default: string;
|
|
26
|
+
};
|
|
27
|
+
}, {
|
|
28
|
+
box: import("vue").Ref<null>;
|
|
29
|
+
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{
|
|
30
|
+
mode?: unknown;
|
|
31
|
+
defaultContent?: unknown;
|
|
32
|
+
defaultHtml?: unknown;
|
|
33
|
+
defaultConfig?: unknown;
|
|
34
|
+
modelValue?: unknown;
|
|
35
|
+
} & {
|
|
36
|
+
mode: string;
|
|
37
|
+
defaultContent: SlateDescendant[];
|
|
38
|
+
defaultHtml: string;
|
|
39
|
+
defaultConfig: Partial<IEditorConfig>;
|
|
40
|
+
modelValue: string;
|
|
41
|
+
} & {}>, {
|
|
42
|
+
mode: string;
|
|
43
|
+
defaultContent: SlateDescendant[];
|
|
44
|
+
defaultHtml: string;
|
|
45
|
+
defaultConfig: Partial<IEditorConfig>;
|
|
46
|
+
modelValue: string;
|
|
47
|
+
}>;
|
|
48
|
+
export default _default;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PropType } from 'vue';
|
|
2
|
+
import { IToolbarConfig, IDomEditor } from '@mnykj/wangeditoroptimize';
|
|
3
|
+
declare const _default: import("vue").DefineComponent<{
|
|
4
|
+
editor: {
|
|
5
|
+
type: PropType<IDomEditor>;
|
|
6
|
+
};
|
|
7
|
+
/** 编辑器模式 */
|
|
8
|
+
mode: {
|
|
9
|
+
type: StringConstructor;
|
|
10
|
+
default: string;
|
|
11
|
+
};
|
|
12
|
+
/** 编辑器默认配置 */
|
|
13
|
+
defaultConfig: {
|
|
14
|
+
type: PropType<Partial<IToolbarConfig>>;
|
|
15
|
+
default: {};
|
|
16
|
+
};
|
|
17
|
+
}, {
|
|
18
|
+
selector: import("vue").Ref<null>;
|
|
19
|
+
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<{
|
|
20
|
+
editor?: unknown;
|
|
21
|
+
mode?: unknown;
|
|
22
|
+
defaultConfig?: unknown;
|
|
23
|
+
} & {
|
|
24
|
+
mode: string;
|
|
25
|
+
defaultConfig: Partial<IToolbarConfig>;
|
|
26
|
+
} & {
|
|
27
|
+
editor?: IDomEditor | undefined;
|
|
28
|
+
}>, {
|
|
29
|
+
mode: string;
|
|
30
|
+
defaultConfig: Partial<IToolbarConfig>;
|
|
31
|
+
}>;
|
|
32
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mnykj/wangeditoroptimize-for-vue",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "wangEditorOptimize Vue3 wrapper (fork of @wangeditor/editor-for-vue for @mnykj/wangeditoroptimize)",
|
|
5
|
+
"author": "mnykj",
|
|
6
|
+
"homepage": "https://www.npmjs.com/org/mnykj",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.esm.js",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"types": "dist/src/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"keywords": [
|
|
15
|
+
"wangEditor",
|
|
16
|
+
"wangeditoroptimize",
|
|
17
|
+
"富文本编辑器",
|
|
18
|
+
"vue3",
|
|
19
|
+
"mnykj"
|
|
20
|
+
],
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": "./dist/index.esm.js",
|
|
24
|
+
"require": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public",
|
|
29
|
+
"registry": "https://registry.npmjs.org/"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/wangeditor-team/wangEditor-for-vue3.git"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@mnykj/wangeditoroptimize": "^1.0.0",
|
|
37
|
+
"vue": "^3.0.5"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "node -e \"console.log('prebuilt dist; no build step')\""
|
|
42
|
+
}
|
|
43
|
+
}
|