@shenjipo/mention-vue2 1.0.0 → 2.1.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/dist/index.cjs.js +1 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +5 -70
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +307 -106
- package/package.json +36 -37
- package/dist/utils.d.ts +0 -5
- package/dist/utils.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const M=require("@shenjipo/mention-editor"),o=require("vue-demi"),g=require("@floating-ui/dom");function p(n,e,t,l,u,s,r,f){var a=typeof n=="function"?n.options:n;e&&(a.render=e,a.staticRenderFns=t,a._compiled=!0),l&&(a.functional=!0),s&&(a._scopeId="data-v-"+s);var c;if(r?(c=function(i){i=i||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!i&&typeof __VUE_SSR_CONTEXT__<"u"&&(i=__VUE_SSR_CONTEXT__),u&&u.call(this,i),i&&i._registeredComponents&&i._registeredComponents.add(r)},a._ssrRegister=c):u&&(c=f?function(){u.call(this,(a.functional?this.parent:this).$root.$options.shadowRoot)}:u),c)if(a.functional){a._injectStyles=c;var d=a.render;a.render=function(v,m){return c.call(m),d(v,m)}}else{var _=a.beforeCreate;a.beforeCreate=_?[].concat(_,c):[c]}return{exports:n,options:a}}const C={name:"MEditorVue2",props:{modelValue:{type:String,default:""},options:{type:Object,default:()=>({placeholder:"请输入内容,可粘贴图片到此处,按下/唤起快捷指令,"})}},emits:["update:modelValue","fileReject","imageInput"],setup(n,{emit:e,expose:t}){const l=o.ref(null),u=o.ref(null);o.provide("editor",l),o.onMounted(()=>{u.value&&(l.value=new M({element:u.value,placeholder:n.options.placeholder,onChange:r=>{e("update:modelValue",r)},onFileReject:r=>{e("fileReject",r)},onImageInput:r=>{e("imageInput",r)}}))});const s=()=>{l.value.clear(),e("update:modelValue","")};return t({editor:l,clear:s}),{editor:l,editorRef:u,clear:s}}};var S=function(){var e=this,t=e._self._c;return t("div",{staticClass:"mention-editor-wrapper"},[e._t("header"),t("div",{ref:"editorRef",staticClass:"mention-editor"},[e.editor?e._t("default"):e._e()],2),e._t("footer")],2)},I=[],$=p(C,S,I,!1,null,"8f854357",null,null);const y=$.exports;const q={name:"SuggestionMenu",props:{items:{type:Array,required:!0},loadingState:{type:String,default:"idle"},selectedIndex:{type:Number,default:0}},methods:{handleItemClick(n){this.$emit("itemClick",n)}}};var b=function(){var e=this,t=e._self._c;return t("div",{staticClass:"bn-suggestion-menu"},[e.items.length?e._l(e.items,function(l,u){return t("div",{key:l.id,staticClass:"suggestion-menu-item",class:{active:u===e.selectedIndex},on:{mousedown:function(s){return s.preventDefault(),e.handleItemClick(l)}}},[e._v(" "+e._s(l.label)+" ")])}):t("div",{staticClass:"suggestion-menu-item disabled"},[e._v("无数据")])],2)},R=[],k=p(q,b,R,!1,null,"af9205e7",null,null);const w=k.exports;function E(n,e,t,l){const u=o.ref(0),s=r=>r.key==="ArrowUp"?(r.preventDefault(),t.value&&t.value.length&&(u.value=(u.value-1+t.value.length)%t.value.length),!0):r.key==="ArrowDown"?(r.preventDefault(),t.value&&t.value.length&&(u.value=(u.value+1)%t.value.length),!0):r.key==="Enter"&&!r.isComposing?(r.preventDefault(),t.value&&t.value.length&&l&&l(t.value[u.value]),!0):!1;return o.onMounted(()=>{n&&n.domElement&&n.domElement.addEventListener("keydown",s,!0)}),o.onBeforeUnmount(()=>{n&&n.domElement&&n.domElement.removeEventListener("keydown",s,!0)}),o.watch(()=>e,()=>{u.value=0}),u}function x(n,e,t,l=8){const u=o.ref(0);return o.watch([n,e],([s,r])=>{r!=null&&(s&&s.length>0?u.value=r.length:r.length-u.value>l&&t())}),{lastUsefulQueryLength:u}}const F={name:"SuggestionMenuWrapper",components:{SuggestionMenu:w},props:{query:{type:String,required:!0},getItems:{type:Function,required:!0},onItemClick:{type:Function},closeMenu:{type:Function,required:!0},clearQuery:{type:Function,required:!0},insertMention:{type:Function,required:!0}},setup(n){const e=o.ref([]),t=o.ref("idle"),l=o.ref(""),u=o.inject("editor"),s=a=>{n.closeMenu(),n.clearQuery(),n.insertMention(a)},r=E(u.value,n.query,e,s);x(e,l,n.closeMenu);const f=()=>{const a=n.query;l.value=n.query,t.value="loading",n.getItems(n.query).then(c=>{l.value===a&&(e.value=c,t.value="loaded")})};return o.onMounted(f),o.watch(()=>n.query,()=>{f()}),{items:e,loadingState:t,selectedIndex:r,onItemClickInternal:s}}};var Q=function(){var e=this,t=e._self._c;return t("SuggestionMenu",{attrs:{items:e.items,"loading-state":e.loadingState,"selected-index":e.selectedIndex},on:{itemClick:e.onItemClickInternal}})},U=[],V=p(F,Q,U,!1,null,"e4189e8f",null,null);const D=V.exports;function A(n,e,t,l={}){const u=o.ref(null),s=o.ref(null),r=o.ref({});let f=null;o.watch(e,i=>{i&&(u.value={getBoundingClientRect:()=>i},a())},{immediate:!0}),o.watch(n,async i=>{if(!i){d();return}await o.nextTick(),!(!u.value||!s.value)&&(a(),c())});const a=()=>{const i=u.value,v=s.value;!i||!v||g.computePosition(i,v,{placement:l.placement||"bottom-start",middleware:[g.offset(l.offset||8),g.flip(),g.shift({padding:8})]}).then(({x:m,y:h})=>{r.value={position:"absolute",left:`${m}px`,top:`${h}px`}})};function c(){!u.value||!s.value||(f=g.autoUpdate(u.value,s.value,a))}function d(){f&&(f(),f=null)}const _=o.computed(()=>({display:"flex",zIndex:t,...r.value}));return{floatingRef:s,style:_}}const L={name:"SuggestionMenuController",components:{SuggestionMenuWrapper:D},props:{triggerCharacter:{type:String,required:!0},minQueryLength:{type:Number},getItems:{type:Function,required:!0},onItemClick:{type:Function}},setup(n){const e=o.inject("editor"),t=o.ref(null),l=o.computed(()=>{var _;return(((_=t.value)==null?void 0:_.show)&&(!n.minQueryLength||t.value.ignoreQueryLength||!t.value.query.startsWith(" ")&&t.value.query.length>=n.minQueryLength))??!1}),{floatingRef:u,style:s}=A(()=>l.value,()=>{var d;return((d=t.value)==null?void 0:d.referencePos)||null},2e3,{placement:"bottom-start",middleware:[g.offset(10),g.flip({mainAxis:!0,crossAxis:!1}),g.shift(),g.size({apply({availableHeight:d,elements:_}){Object.assign(_.floating.style,{maxHeight:`${d-10}px`})}})],onDismiss(){}});let r=null;return o.onMounted(()=>{r=e.value.suggestionMenus.onUpdate(n.triggerCharacter,d=>{t.value=d})}),o.onBeforeUnmount(()=>{r&&r()}),{state:t,floatingRef:u,style:s,showDom:l,closeMenu:()=>{e.value.suggestionMenus.closeMenu()},clearQuery:()=>{e.value.suggestionMenus.clearQuery()},insertMention:d=>{e.value.suggestionMenus.insertMention(d)}}}};var N=function(){var e=this,t=e._self._c;return e.showDom?t("div",{ref:"floatingRef",style:e.style},[t("SuggestionMenuWrapper",{attrs:{query:e.state.query,getItems:e.getItems,onItemClick:e.onItemClick,closeMenu:e.closeMenu,clearQuery:e.clearQuery,insertMention:e.insertMention}})],1):e._e()},j=[],T=p(L,N,j,!1,null,"f5b73a66",null,null);const W=T.exports;exports.MEditorVue2=y;exports.SuggestionMenuController=W;exports.default=y;
|
package/dist/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.mention-editor-wrapper{border:1px solid #d9d9d9;padding:8px 12px;transition:border-color .2s,box-shadow .2s;border-radius:6px}.mention-editor-wrapper:focus-within{border-color:#409eff;box-shadow:0 0 0 2px #409eff33}.mention-editor-wrapper .mention-editor{min-height:80px}.mention-editor-wrapper .mention-editor .tiptap{outline:none;max-height:200px;overflow:auto}.mention-editor-wrapper .mention-editor .tiptap p{margin:0}.mention-editor-wrapper .mention-editor .tiptap p.is-editor-empty:before{content:attr(data-placeholder);color:#aaa;float:left;height:0;pointer-events:none}.mention-editor-wrapper .mention-editor .tiptap .mention{padding:2px 6px;border-radius:8px;color:#4971f5;background-color:#ecf5ff;display:inline-block;margin-right:4px}
|
|
1
|
+
.mention-editor-wrapper{border:1px solid #d9d9d9;padding:8px 12px;transition:border-color .2s,box-shadow .2s;border-radius:6px}.mention-editor-wrapper:focus-within{border-color:#409eff;box-shadow:0 0 0 2px #409eff33}.mention-editor-wrapper .mention-editor{min-height:80px}.mention-editor-wrapper .mention-editor .tiptap{outline:none;max-height:200px;overflow:auto}.mention-editor-wrapper .mention-editor .tiptap p{margin:0}.mention-editor-wrapper .mention-editor .tiptap p.is-editor-empty:before{content:attr(data-placeholder);color:#aaa;float:left;height:0;pointer-events:none}.mention-editor-wrapper .mention-editor .tiptap .mention{padding:2px 6px;border-radius:8px;color:#4971f5;background-color:#ecf5ff;display:inline-block;margin-right:4px}.mention-editor-wrapper .mention-editor .bn-suggestion-menu{width:180px;background-color:#fff;border-radius:8px;box-shadow:0 2px 12px #00000026;overflow:hidden;font-size:14px;padding:4px}.mention-editor-wrapper .mention-editor .bn-suggestion-menu .suggestion-menu-item{display:flex;align-items:center;padding:8px 12px;cursor:pointer;transition:background-color .2s}.mention-editor-wrapper .mention-editor .bn-suggestion-menu .suggestion-menu-item:hover{background-color:#f1f5f9}.mention-editor-wrapper .mention-editor .bn-suggestion-menu .suggestion-menu-item span{flex:1}.mention-editor-wrapper .mention-editor .bn-suggestion-menu .suggestion-menu-item.active{background-color:#f1f5f9}.mention-editor-wrapper .mention-editor .bn-suggestion-menu .suggestion-menu-item.disabled{background-color:unset;cursor:not-allowed}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,70 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
label: string
|
|
7
|
-
disabled?: boolean
|
|
8
|
-
[key: string]: any
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/** MentionInputVue2 组件类型 */
|
|
12
|
-
declare const MentionInputVue2: Vue & {
|
|
13
|
-
new(): {
|
|
14
|
-
/* ---------------- props ---------------- */
|
|
15
|
-
|
|
16
|
-
/** v-model 绑定值 */
|
|
17
|
-
value: string
|
|
18
|
-
|
|
19
|
-
/** 占位文本 */
|
|
20
|
-
placeholder: string
|
|
21
|
-
|
|
22
|
-
/** suggestion 渲染容器(可选) */
|
|
23
|
-
suggestionDom: HTMLElement | null
|
|
24
|
-
|
|
25
|
-
/** suggestion Vue 组件构造器 */
|
|
26
|
-
suggestionComponent: Vue
|
|
27
|
-
|
|
28
|
-
/* ---------------- data ---------------- */
|
|
29
|
-
|
|
30
|
-
/** 内部 editor 实例(不建议外部直接使用) */
|
|
31
|
-
editor: any
|
|
32
|
-
|
|
33
|
-
/** mention bridge */
|
|
34
|
-
mentionBridge: any
|
|
35
|
-
|
|
36
|
-
/* ---------------- methods ---------------- */
|
|
37
|
-
|
|
38
|
-
/** 手动刷新(当前为空实现,预留) */
|
|
39
|
-
refresh(): void
|
|
40
|
-
|
|
41
|
-
/* ---------------- events ---------------- */
|
|
42
|
-
|
|
43
|
-
/** v-model */
|
|
44
|
-
$emit(event: 'input', value: string): this
|
|
45
|
-
|
|
46
|
-
/** 内容变化 */
|
|
47
|
-
$emit(event: 'change', value: string): this
|
|
48
|
-
|
|
49
|
-
/** mention 命令触发 */
|
|
50
|
-
$emit(event: 'command', item: MentionItem): this
|
|
51
|
-
|
|
52
|
-
/** 图片输入(拖拽 / 粘贴) */
|
|
53
|
-
$emit(
|
|
54
|
-
event: 'onFileChange',
|
|
55
|
-
file: File,
|
|
56
|
-
base64: string,
|
|
57
|
-
width: number,
|
|
58
|
-
height: number
|
|
59
|
-
): this
|
|
60
|
-
|
|
61
|
-
/** 非法文件 */
|
|
62
|
-
$emit(event: 'onFileReject', file: File): this
|
|
63
|
-
|
|
64
|
-
/** Enter 键 */
|
|
65
|
-
$emit(event: 'enter'): this
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export default MentionInputVue2
|
|
70
|
-
export { MentionInputVue2 }
|
|
1
|
+
import { default as MEditorVue2 } from './components/MEditorVue2.vue';
|
|
2
|
+
import { default as SuggestionMenuController } from './components/SuggestionMenu/SuggestionMenuController.vue';
|
|
3
|
+
export { MEditorVue2, SuggestionMenuController, };
|
|
4
|
+
export default MEditorVue2;
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,8BAA8B,CAAA;AACtD,OAAO,wBAAwB,MAAM,0DAA0D,CAAA;AAG/F,OAAO,EACH,WAAW,EACX,wBAAwB,GAC3B,CAAA;AACD,eAAe,WAAW,CAAA;AAE1B,OAAO,qBAAqB,CAAA"}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,135 +1,336 @@
|
|
|
1
|
-
import
|
|
2
|
-
import g,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const t = l([]), e = l(""), o = l(0);
|
|
11
|
-
return {
|
|
12
|
-
query: e,
|
|
13
|
-
setQuery: (s) => {
|
|
14
|
-
e.value = s;
|
|
15
|
-
},
|
|
16
|
-
items: t,
|
|
17
|
-
selectedIndex: o,
|
|
18
|
-
confirm: (s) => {
|
|
19
|
-
o.value = s;
|
|
20
|
-
},
|
|
21
|
-
setOptions: (s) => {
|
|
22
|
-
t.value = [...s];
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
function $(t, e, o, u, r, d, s, c) {
|
|
27
|
-
var n = typeof t == "function" ? t.options : t;
|
|
28
|
-
e && (n.render = e, n.staticRenderFns = o, n._compiled = !0), u && (n.functional = !0), d && (n._scopeId = "data-v-" + d);
|
|
29
|
-
var a;
|
|
30
|
-
if (s ? (a = function(i) {
|
|
31
|
-
i = i || // cached call
|
|
1
|
+
import q from "@shenjipo/mention-editor";
|
|
2
|
+
import { ref as d, provide as b, onMounted as p, onBeforeUnmount as h, watch as g, inject as M, nextTick as k, computed as C } from "vue-demi";
|
|
3
|
+
import { computePosition as x, offset as I, flip as S, shift as $, autoUpdate as E, size as w } from "@floating-ui/dom";
|
|
4
|
+
function y(n, e, t, l, u, o, r, f) {
|
|
5
|
+
var s = typeof n == "function" ? n.options : n;
|
|
6
|
+
e && (s.render = e, s.staticRenderFns = t, s._compiled = !0), l && (s.functional = !0), o && (s._scopeId = "data-v-" + o);
|
|
7
|
+
var i;
|
|
8
|
+
if (r ? (i = function(a) {
|
|
9
|
+
a = a || // cached call
|
|
32
10
|
this.$vnode && this.$vnode.ssrContext || // stateful
|
|
33
|
-
this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext, !
|
|
34
|
-
},
|
|
35
|
-
|
|
11
|
+
this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext, !a && typeof __VUE_SSR_CONTEXT__ < "u" && (a = __VUE_SSR_CONTEXT__), u && u.call(this, a), a && a._registeredComponents && a._registeredComponents.add(r);
|
|
12
|
+
}, s._ssrRegister = i) : u && (i = f ? function() {
|
|
13
|
+
u.call(
|
|
36
14
|
this,
|
|
37
|
-
(
|
|
15
|
+
(s.functional ? this.parent : this).$root.$options.shadowRoot
|
|
38
16
|
);
|
|
39
|
-
} :
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
return
|
|
17
|
+
} : u), i)
|
|
18
|
+
if (s.functional) {
|
|
19
|
+
s._injectStyles = i;
|
|
20
|
+
var c = s.render;
|
|
21
|
+
s.render = function(v, m) {
|
|
22
|
+
return i.call(m), c(v, m);
|
|
45
23
|
};
|
|
46
24
|
} else {
|
|
47
|
-
var
|
|
48
|
-
|
|
25
|
+
var _ = s.beforeCreate;
|
|
26
|
+
s.beforeCreate = _ ? [].concat(_, i) : [i];
|
|
49
27
|
}
|
|
50
28
|
return {
|
|
51
|
-
exports:
|
|
52
|
-
options:
|
|
29
|
+
exports: n,
|
|
30
|
+
options: s
|
|
53
31
|
};
|
|
54
32
|
}
|
|
55
|
-
const
|
|
56
|
-
name: "
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
33
|
+
const F = {
|
|
34
|
+
name: "MEditorVue2",
|
|
35
|
+
props: {
|
|
36
|
+
modelValue: { type: String, default: "" },
|
|
37
|
+
options: {
|
|
38
|
+
type: Object,
|
|
39
|
+
default: () => ({
|
|
40
|
+
placeholder: "请输入内容,可粘贴图片到此处,按下/唤起快捷指令,"
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
emits: ["update:modelValue", "fileReject", "imageInput"],
|
|
45
|
+
setup(n, { emit: e, expose: t }) {
|
|
46
|
+
const l = d(null), u = d(null);
|
|
47
|
+
b("editor", l), p(() => {
|
|
48
|
+
u.value && (l.value = new q({
|
|
49
|
+
element: u.value,
|
|
50
|
+
placeholder: n.options.placeholder,
|
|
51
|
+
onChange: (r) => {
|
|
52
|
+
e("update:modelValue", r);
|
|
53
|
+
},
|
|
54
|
+
onFileReject: (r) => {
|
|
55
|
+
e("fileReject", r);
|
|
56
|
+
},
|
|
57
|
+
onImageInput: (r) => {
|
|
58
|
+
e("imageInput", r);
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
});
|
|
62
|
+
const o = () => {
|
|
63
|
+
l.value.clear(), e("update:modelValue", "");
|
|
64
|
+
};
|
|
65
|
+
return t({ editor: l, clear: o }), {
|
|
66
|
+
editor: l,
|
|
67
|
+
editorRef: u,
|
|
68
|
+
clear: o
|
|
60
69
|
};
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var Q = function() {
|
|
73
|
+
var e = this, t = e._self._c;
|
|
74
|
+
return t("div", { staticClass: "mention-editor-wrapper" }, [e._t("header"), t("div", { ref: "editorRef", staticClass: "mention-editor" }, [e.editor ? e._t("default") : e._e()], 2), e._t("footer")], 2);
|
|
75
|
+
}, U = [], V = /* @__PURE__ */ y(
|
|
76
|
+
F,
|
|
77
|
+
Q,
|
|
78
|
+
U,
|
|
79
|
+
!1,
|
|
80
|
+
null,
|
|
81
|
+
"8f854357",
|
|
82
|
+
null,
|
|
83
|
+
null
|
|
84
|
+
);
|
|
85
|
+
const ne = V.exports;
|
|
86
|
+
const A = {
|
|
87
|
+
name: "SuggestionMenu",
|
|
88
|
+
props: {
|
|
89
|
+
items: { type: Array, required: !0 },
|
|
90
|
+
loadingState: { type: String, default: "idle" },
|
|
91
|
+
selectedIndex: { type: Number, default: 0 }
|
|
92
|
+
},
|
|
93
|
+
methods: {
|
|
94
|
+
handleItemClick(n) {
|
|
95
|
+
this.$emit("itemClick", n);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
var D = function() {
|
|
100
|
+
var e = this, t = e._self._c;
|
|
101
|
+
return t("div", { staticClass: "bn-suggestion-menu" }, [e.items.length ? e._l(e.items, function(l, u) {
|
|
102
|
+
return t("div", { key: l.id, staticClass: "suggestion-menu-item", class: { active: u === e.selectedIndex }, on: { mousedown: function(o) {
|
|
103
|
+
return o.preventDefault(), e.handleItemClick(l);
|
|
104
|
+
} } }, [e._v(" " + e._s(l.label) + " ")]);
|
|
105
|
+
}) : t("div", { staticClass: "suggestion-menu-item disabled" }, [e._v("无数据")])], 2);
|
|
106
|
+
}, L = [], N = /* @__PURE__ */ y(
|
|
107
|
+
A,
|
|
108
|
+
D,
|
|
109
|
+
L,
|
|
110
|
+
!1,
|
|
111
|
+
null,
|
|
112
|
+
"af9205e7",
|
|
113
|
+
null,
|
|
114
|
+
null
|
|
115
|
+
);
|
|
116
|
+
const W = N.exports;
|
|
117
|
+
function T(n, e, t, l) {
|
|
118
|
+
const u = d(0), o = (r) => r.key === "ArrowUp" ? (r.preventDefault(), t.value && t.value.length && (u.value = (u.value - 1 + t.value.length) % t.value.length), !0) : r.key === "ArrowDown" ? (r.preventDefault(), t.value && t.value.length && (u.value = (u.value + 1) % t.value.length), !0) : r.key === "Enter" && !r.isComposing ? (r.preventDefault(), t.value && t.value.length && l && l(t.value[u.value]), !0) : !1;
|
|
119
|
+
return p(() => {
|
|
120
|
+
n && n.domElement && n.domElement.addEventListener("keydown", o, !0);
|
|
121
|
+
}), h(() => {
|
|
122
|
+
n && n.domElement && n.domElement.removeEventListener("keydown", o, !0);
|
|
123
|
+
}), g(
|
|
124
|
+
() => e,
|
|
125
|
+
() => {
|
|
126
|
+
u.value = 0;
|
|
127
|
+
}
|
|
128
|
+
), u;
|
|
129
|
+
}
|
|
130
|
+
function j(n, e, t, l = 8) {
|
|
131
|
+
const u = d(0);
|
|
132
|
+
return g(
|
|
133
|
+
[n, e],
|
|
134
|
+
([o, r]) => {
|
|
135
|
+
r != null && (o && o.length > 0 ? u.value = r.length : r.length - u.value > l && t());
|
|
136
|
+
}
|
|
137
|
+
), {
|
|
138
|
+
lastUsefulQueryLength: u
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
const O = {
|
|
142
|
+
name: "SuggestionMenuWrapper",
|
|
143
|
+
components: {
|
|
144
|
+
SuggestionMenu: W
|
|
61
145
|
},
|
|
62
146
|
props: {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
147
|
+
query: { type: String, required: !0 },
|
|
148
|
+
getItems: { type: Function, required: !0 },
|
|
149
|
+
onItemClick: { type: Function },
|
|
150
|
+
closeMenu: { type: Function, required: !0 },
|
|
151
|
+
clearQuery: { type: Function, required: !0 },
|
|
152
|
+
insertMention: { type: Function, required: !0 }
|
|
153
|
+
},
|
|
154
|
+
setup(n) {
|
|
155
|
+
const e = d([]), t = d("idle"), l = d(""), u = M("editor"), o = (s) => {
|
|
156
|
+
n.closeMenu(), n.clearQuery(), n.insertMention(s);
|
|
157
|
+
}, r = T(
|
|
158
|
+
u.value,
|
|
159
|
+
n.query,
|
|
160
|
+
e,
|
|
161
|
+
o
|
|
162
|
+
);
|
|
163
|
+
j(e, l, n.closeMenu);
|
|
164
|
+
const f = () => {
|
|
165
|
+
const s = n.query;
|
|
166
|
+
l.value = n.query, t.value = "loading", n.getItems(n.query).then((i) => {
|
|
167
|
+
l.value === s && (e.value = i, t.value = "loaded");
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
return p(f), g(
|
|
171
|
+
() => n.query,
|
|
172
|
+
() => {
|
|
173
|
+
f();
|
|
174
|
+
}
|
|
175
|
+
), {
|
|
176
|
+
items: e,
|
|
177
|
+
loadingState: t,
|
|
178
|
+
selectedIndex: r,
|
|
179
|
+
onItemClickInternal: o
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
var P = function() {
|
|
184
|
+
var e = this, t = e._self._c;
|
|
185
|
+
return t("SuggestionMenu", { attrs: { items: e.items, "loading-state": e.loadingState, "selected-index": e.selectedIndex }, on: { itemClick: e.onItemClickInternal } });
|
|
186
|
+
}, z = [], B = /* @__PURE__ */ y(
|
|
187
|
+
O,
|
|
188
|
+
P,
|
|
189
|
+
z,
|
|
190
|
+
!1,
|
|
191
|
+
null,
|
|
192
|
+
"e4189e8f",
|
|
193
|
+
null,
|
|
194
|
+
null
|
|
195
|
+
);
|
|
196
|
+
const K = B.exports;
|
|
197
|
+
function X(n, e, t, l = {}) {
|
|
198
|
+
const u = d(null), o = d(null), r = d({});
|
|
199
|
+
let f = null;
|
|
200
|
+
g(
|
|
201
|
+
e,
|
|
202
|
+
(a) => {
|
|
203
|
+
a && (u.value = {
|
|
204
|
+
getBoundingClientRect: () => a
|
|
205
|
+
}, s());
|
|
74
206
|
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
207
|
+
{ immediate: !0 }
|
|
208
|
+
), g(
|
|
209
|
+
n,
|
|
210
|
+
async (a) => {
|
|
211
|
+
if (!a) {
|
|
212
|
+
c();
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
await k(), !(!u.value || !o.value) && (s(), i());
|
|
79
216
|
}
|
|
217
|
+
);
|
|
218
|
+
const s = () => {
|
|
219
|
+
const a = u.value, v = o.value;
|
|
220
|
+
!a || !v || x(a, v, {
|
|
221
|
+
placement: l.placement || "bottom-start",
|
|
222
|
+
middleware: [
|
|
223
|
+
I(l.offset || 8),
|
|
224
|
+
S(),
|
|
225
|
+
$({ padding: 8 })
|
|
226
|
+
]
|
|
227
|
+
}).then(({ x: m, y: R }) => {
|
|
228
|
+
r.value = {
|
|
229
|
+
position: "absolute",
|
|
230
|
+
left: `${m}px`,
|
|
231
|
+
top: `${R}px`
|
|
232
|
+
};
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
|
+
function i() {
|
|
236
|
+
!u.value || !o.value || (f = E(u.value, o.value, s));
|
|
237
|
+
}
|
|
238
|
+
function c() {
|
|
239
|
+
f && (f(), f = null);
|
|
240
|
+
}
|
|
241
|
+
const _ = C(() => ({
|
|
242
|
+
display: "flex",
|
|
243
|
+
zIndex: t,
|
|
244
|
+
...r.value
|
|
245
|
+
}));
|
|
246
|
+
return {
|
|
247
|
+
floatingRef: o,
|
|
248
|
+
style: _
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
const H = {
|
|
252
|
+
name: "SuggestionMenuController",
|
|
253
|
+
components: {
|
|
254
|
+
SuggestionMenuWrapper: K
|
|
80
255
|
},
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
256
|
+
props: {
|
|
257
|
+
triggerCharacter: { type: String, required: !0 },
|
|
258
|
+
minQueryLength: { type: Number },
|
|
259
|
+
getItems: { type: Function, required: !0 },
|
|
260
|
+
onItemClick: { type: Function }
|
|
86
261
|
},
|
|
87
|
-
|
|
88
|
-
const t =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this.$emit("command", e);
|
|
262
|
+
setup(n) {
|
|
263
|
+
const e = M("editor"), t = d(null), l = C(() => {
|
|
264
|
+
var _;
|
|
265
|
+
return (((_ = t.value) == null ? void 0 : _.show) && (!n.minQueryLength || t.value.ignoreQueryLength || !t.value.query.startsWith(" ") && t.value.query.length >= n.minQueryLength)) ?? !1;
|
|
266
|
+
}), { floatingRef: u, style: o } = X(
|
|
267
|
+
() => l.value,
|
|
268
|
+
() => {
|
|
269
|
+
var c;
|
|
270
|
+
return ((c = t.value) == null ? void 0 : c.referencePos) || null;
|
|
97
271
|
},
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
272
|
+
2e3,
|
|
273
|
+
{
|
|
274
|
+
placement: "bottom-start",
|
|
275
|
+
middleware: [
|
|
276
|
+
I(10),
|
|
277
|
+
S({ mainAxis: !0, crossAxis: !1 }),
|
|
278
|
+
$(),
|
|
279
|
+
w({
|
|
280
|
+
apply({ availableHeight: c, elements: _ }) {
|
|
281
|
+
Object.assign(_.floating.style, {
|
|
282
|
+
maxHeight: `${c - 10}px`
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
})
|
|
286
|
+
],
|
|
287
|
+
onDismiss() {
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
);
|
|
291
|
+
let r = null;
|
|
292
|
+
return p(() => {
|
|
293
|
+
r = e.value.suggestionMenus.onUpdate(
|
|
294
|
+
n.triggerCharacter,
|
|
295
|
+
(c) => {
|
|
296
|
+
t.value = c;
|
|
297
|
+
}
|
|
298
|
+
);
|
|
299
|
+
}), h(() => {
|
|
300
|
+
r && r();
|
|
301
|
+
}), {
|
|
302
|
+
state: t,
|
|
303
|
+
floatingRef: u,
|
|
304
|
+
style: o,
|
|
305
|
+
showDom: l,
|
|
306
|
+
closeMenu: () => {
|
|
307
|
+
e.value.suggestionMenus.closeMenu();
|
|
103
308
|
},
|
|
104
|
-
|
|
105
|
-
|
|
309
|
+
clearQuery: () => {
|
|
310
|
+
e.value.suggestionMenus.clearQuery();
|
|
106
311
|
},
|
|
107
|
-
|
|
108
|
-
|
|
312
|
+
insertMention: (c) => {
|
|
313
|
+
e.value.suggestionMenus.insertMention(c);
|
|
109
314
|
}
|
|
110
|
-
}
|
|
111
|
-
this.$emit("enter");
|
|
112
|
-
});
|
|
113
|
-
},
|
|
114
|
-
methods: {
|
|
115
|
-
refresh() {
|
|
116
|
-
}
|
|
315
|
+
};
|
|
117
316
|
}
|
|
118
317
|
};
|
|
119
|
-
var
|
|
120
|
-
var e = this,
|
|
121
|
-
return
|
|
122
|
-
},
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
318
|
+
var G = function() {
|
|
319
|
+
var e = this, t = e._self._c;
|
|
320
|
+
return e.showDom ? t("div", { ref: "floatingRef", style: e.style }, [t("SuggestionMenuWrapper", { attrs: { query: e.state.query, getItems: e.getItems, onItemClick: e.onItemClick, closeMenu: e.closeMenu, clearQuery: e.clearQuery, insertMention: e.insertMention } })], 1) : e._e();
|
|
321
|
+
}, J = [], Y = /* @__PURE__ */ y(
|
|
322
|
+
H,
|
|
323
|
+
G,
|
|
324
|
+
J,
|
|
126
325
|
!1,
|
|
127
326
|
null,
|
|
128
|
-
|
|
327
|
+
"f5b73a66",
|
|
129
328
|
null,
|
|
130
329
|
null
|
|
131
330
|
);
|
|
132
|
-
const
|
|
331
|
+
const ue = Y.exports;
|
|
133
332
|
export {
|
|
134
|
-
|
|
333
|
+
ne as MEditorVue2,
|
|
334
|
+
ue as SuggestionMenuController,
|
|
335
|
+
ne as default
|
|
135
336
|
};
|
package/package.json
CHANGED
|
@@ -1,39 +1,38 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
2
|
+
"name": "@shenjipo/mention-vue2",
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"main": "dist/index.cjs.js",
|
|
5
|
+
"module": "dist/index.esm.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"style": "dist/index.css",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "vite",
|
|
10
|
+
"build": "vite build",
|
|
11
|
+
"build:watch": "vite build --watch"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@floating-ui/dom": "^1.1.9",
|
|
21
|
+
"@shenjipo/mention-editor": "workspace:*",
|
|
22
|
+
"vue": "^2.7.7",
|
|
23
|
+
"vue-demi": "^0.14.10"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^16.11.45",
|
|
27
|
+
"@vitejs/plugin-vue2": "^1.1.2",
|
|
28
|
+
"@vue/tsconfig": "^0.1.3",
|
|
29
|
+
"cpx": "^1.5.0",
|
|
30
|
+
"npm-run-all": "^4.1.5",
|
|
31
|
+
"sass": "^1.97.0",
|
|
32
|
+
"terser": "^5.14.2",
|
|
33
|
+
"typescript": "^5.0.0",
|
|
34
|
+
"vite": "^4.0.2",
|
|
35
|
+
"vite-plugin-dts": "^4.5.4",
|
|
36
|
+
"vue-tsc": "^0.38.8"
|
|
37
|
+
}
|
|
39
38
|
}
|
package/dist/utils.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { default as Vue, ComponentOptions, VueConstructor } from 'vue';
|
|
2
|
-
type Vue2Component = ComponentOptions<Vue> | VueConstructor<Vue>;
|
|
3
|
-
export declare function renderVueComponentToDom(component: Vue2Component, propsData?: Record<string, any>): Element;
|
|
4
|
-
export {};
|
|
5
|
-
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAE3D,KAAK,aAAa,GACZ,gBAAgB,CAAC,GAAG,CAAC,GACrB,cAAc,CAAC,GAAG,CAAC,CAAA;AAEzB,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,aAAa,EAAE,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,WAOpG"}
|