@shenjipo/mention-vue2 2.2.0 → 2.3.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 CHANGED
@@ -1 +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;
1
+ "use strict";var $=Object.defineProperty;var y=Object.getOwnPropertySymbols;var q=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var h=(n,e,t)=>e in n?$(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,M=(n,e)=>{for(var t in e||(e={}))q.call(e,t)&&h(n,t,e[t]);if(y)for(var t of y(e))b.call(e,t)&&h(n,t,e[t]);return n};var C=(n,e,t)=>new Promise((l,u)=>{var a=o=>{try{f(t.next(o))}catch(i){u(i)}},r=o=>{try{f(t.throw(o))}catch(i){u(i)}},f=o=>o.done?l(o.value):Promise.resolve(o.value).then(a,r);f((t=t.apply(n,e)).next())});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const R=require("@shenjipo/mention-editor"),s=require("vue-demi"),g=require("@floating-ui/dom"),k=n=>n&&typeof n=="object"&&"default"in n?n:{default:n},w=k(R);function p(n,e,t,l,u,a,r,f){var o=typeof n=="function"?n.options:n;e&&(o.render=e,o.staticRenderFns=t,o._compiled=!0),l&&(o.functional=!0),a&&(o._scopeId="data-v-"+a);var i;if(r?(i=function(c){c=c||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!c&&typeof __VUE_SSR_CONTEXT__!="undefined"&&(c=__VUE_SSR_CONTEXT__),u&&u.call(this,c),c&&c._registeredComponents&&c._registeredComponents.add(r)},o._ssrRegister=i):u&&(i=f?function(){u.call(this,(o.functional?this.parent:this).$root.$options.shadowRoot)}:u),i)if(o.functional){o._injectStyles=i;var d=o.render;o.render=function(v,m){return i.call(m),d(v,m)}}else{var _=o.beforeCreate;o.beforeCreate=_?[].concat(_,i):[i]}return{exports:n,options:o}}const E={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=s.ref(null),u=s.ref(null);s.provide("editor",l),s.onMounted(()=>{u.value&&(l.value=new w.default({element:u.value,placeholder:n.options.placeholder,onChange:r=>{e("update:modelValue",r)},onFileReject:r=>{e("fileReject",r)},onImageInput:r=>{e("imageInput",r)}}))});const a=()=>{l.value.clear(),e("update:modelValue","")};return t({editor:l,clear:a}),{editor:l,editorRef:u,clear:a}}};var x=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)},F=[],Q=p(E,x,F,!1,null,"8f854357",null,null);const S=Q.exports;const U={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 D=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(a){return a.preventDefault(),e.handleItemClick(l)}}},[e._v(" "+e._s(l.label)+" ")])}):t("div",{staticClass:"suggestion-menu-item disabled"},[e._v("无数据")])],2)},V=[],A=p(U,D,V,!1,null,"af9205e7",null,null);const j=A.exports;function L(n,e,t,l){const u=s.ref(0),a=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 s.onMounted(()=>{n&&n.domElement&&n.domElement.addEventListener("keydown",a,!0)}),s.onBeforeUnmount(()=>{n&&n.domElement&&n.domElement.removeEventListener("keydown",a,!0)}),s.watch(()=>e,()=>{u.value=0}),u}function N(n,e,t,l=8){const u=s.ref(0);return s.watch([n,e],([a,r])=>{r!=null&&(a&&a.length>0?u.value=r.length:r.length-u.value>l&&t())}),{lastUsefulQueryLength:u}}const T={name:"SuggestionMenuWrapper",components:{SuggestionMenu:j},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=s.ref([]),t=s.ref("idle"),l=s.ref(""),u=s.inject("editor"),a=o=>{n.closeMenu(),n.clearQuery(),n.insertMention(o)},r=L(u.value,n.query,e,a);N(e,l,n.closeMenu);const f=()=>{const o=n.query;l.value=n.query,t.value="loading",n.getItems(n.query).then(i=>{l.value===o&&(e.value=i,t.value="loaded")})};return s.onMounted(f),s.watch(()=>n.query,()=>{f()}),{items:e,loadingState:t,selectedIndex:r,onItemClickInternal:a}}};var W=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}})},O=[],P=p(T,W,O,!1,null,"e4189e8f",null,null);const B=P.exports;function z(n,e,t,l={}){const u=s.ref(null),a=s.ref(null),r=s.ref({});let f=null;s.watch(e,c=>{c&&(u.value={getBoundingClientRect:()=>c},o())},{immediate:!0}),s.watch(n,c=>C(this,null,function*(){if(!c){d();return}yield s.nextTick(),!(!u.value||!a.value)&&(o(),i())}));const o=()=>{const c=u.value,v=a.value;!c||!v||g.computePosition(c,v,{placement:l.placement||"bottom-start",middleware:[g.offset(l.offset||8),g.flip(),g.shift({padding:8})]}).then(({x:m,y:I})=>{r.value={position:"absolute",left:`${m}px`,top:`${I}px`}})};function i(){!u.value||!a.value||(f=g.autoUpdate(u.value,a.value,o))}function d(){f&&(f(),f=null)}const _=s.computed(()=>M({display:"flex",zIndex:t},r.value));return{floatingRef:a,style:_}}const K={name:"SuggestionMenuController",components:{SuggestionMenuWrapper:B},props:{triggerCharacter:{type:String,required:!0},minQueryLength:{type:Number},getItems:{type:Function,required:!0},onItemClick:{type:Function}},setup(n){const e=s.inject("editor"),t=s.ref(null),l=s.computed(()=>{var _;const d=((_=t.value)==null?void 0:_.show)&&(!n.minQueryLength||t.value.ignoreQueryLength||!t.value.query.startsWith(" ")&&t.value.query.length>=n.minQueryLength);return d!=null?d:!1}),{floatingRef:u,style:a}=z(()=>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 s.onMounted(()=>{r=e.value.suggestionMenus.onUpdate(n.triggerCharacter,d=>{t.value=d})}),s.onBeforeUnmount(()=>{r&&r()}),{state:t,floatingRef:u,style:a,showDom:l,closeMenu:()=>{e.value.suggestionMenus.closeMenu()},clearQuery:()=>{e.value.suggestionMenus.clearQuery()},insertMention:d=>{e.value.suggestionMenus.insertMention(d)}}}};var X=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()},H=[],G=p(K,X,H,!1,null,"f5b73a66",null,null);const J=G.exports;exports.MEditorVue2=S;exports.SuggestionMenuController=J;exports.default=S;
package/dist/index.esm.js CHANGED
@@ -1,36 +1,63 @@
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
1
+ var E = Object.defineProperty;
2
+ var h = Object.getOwnPropertySymbols;
3
+ var w = Object.prototype.hasOwnProperty, F = Object.prototype.propertyIsEnumerable;
4
+ var M = (n, e, t) => e in n ? E(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, C = (n, e) => {
5
+ for (var t in e || (e = {}))
6
+ w.call(e, t) && M(n, t, e[t]);
7
+ if (h)
8
+ for (var t of h(e))
9
+ F.call(e, t) && M(n, t, e[t]);
10
+ return n;
11
+ };
12
+ var I = (n, e, t) => new Promise((o, u) => {
13
+ var s = (l) => {
14
+ try {
15
+ d(t.next(l));
16
+ } catch (a) {
17
+ u(a);
18
+ }
19
+ }, r = (l) => {
20
+ try {
21
+ d(t.throw(l));
22
+ } catch (a) {
23
+ u(a);
24
+ }
25
+ }, d = (l) => l.done ? o(l.value) : Promise.resolve(l.value).then(s, r);
26
+ d((t = t.apply(n, e)).next());
27
+ });
28
+ import Q from "@shenjipo/mention-editor";
29
+ import { ref as f, provide as U, onMounted as p, onBeforeUnmount as S, watch as g, inject as $, nextTick as V, computed as R } from "vue-demi";
30
+ import { computePosition as A, offset as q, flip as b, shift as k, autoUpdate as D, size as L } from "@floating-ui/dom";
31
+ function y(n, e, t, o, u, s, r, d) {
32
+ var l = typeof n == "function" ? n.options : n;
33
+ e && (l.render = e, l.staticRenderFns = t, l._compiled = !0), o && (l.functional = !0), s && (l._scopeId = "data-v-" + s);
34
+ var a;
35
+ if (r ? (a = function(i) {
36
+ i = i || // cached call
10
37
  this.$vnode && this.$vnode.ssrContext || // stateful
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() {
38
+ this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext, !i && typeof __VUE_SSR_CONTEXT__ != "undefined" && (i = __VUE_SSR_CONTEXT__), u && u.call(this, i), i && i._registeredComponents && i._registeredComponents.add(r);
39
+ }, l._ssrRegister = a) : u && (a = d ? function() {
13
40
  u.call(
14
41
  this,
15
- (s.functional ? this.parent : this).$root.$options.shadowRoot
42
+ (l.functional ? this.parent : this).$root.$options.shadowRoot
16
43
  );
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);
44
+ } : u), a)
45
+ if (l.functional) {
46
+ l._injectStyles = a;
47
+ var c = l.render;
48
+ l.render = function(v, m) {
49
+ return a.call(m), c(v, m);
23
50
  };
24
51
  } else {
25
- var _ = s.beforeCreate;
26
- s.beforeCreate = _ ? [].concat(_, i) : [i];
52
+ var _ = l.beforeCreate;
53
+ l.beforeCreate = _ ? [].concat(_, a) : [a];
27
54
  }
28
55
  return {
29
56
  exports: n,
30
- options: s
57
+ options: l
31
58
  };
32
59
  }
33
- const F = {
60
+ const N = {
34
61
  name: "MEditorVue2",
35
62
  props: {
36
63
  modelValue: { type: String, default: "" },
@@ -43,9 +70,9 @@ const F = {
43
70
  },
44
71
  emits: ["update:modelValue", "fileReject", "imageInput"],
45
72
  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({
73
+ const o = f(null), u = f(null);
74
+ U("editor", o), p(() => {
75
+ u.value && (o.value = new Q({
49
76
  element: u.value,
50
77
  placeholder: n.options.placeholder,
51
78
  onChange: (r) => {
@@ -59,31 +86,31 @@ const F = {
59
86
  }
60
87
  }));
61
88
  });
62
- const o = () => {
63
- l.value.clear(), e("update:modelValue", "");
89
+ const s = () => {
90
+ o.value.clear(), e("update:modelValue", "");
64
91
  };
65
- return t({ editor: l, clear: o }), {
66
- editor: l,
92
+ return t({ editor: o, clear: s }), {
93
+ editor: o,
67
94
  editorRef: u,
68
- clear: o
95
+ clear: s
69
96
  };
70
97
  }
71
98
  };
72
- var Q = function() {
99
+ var W = function() {
73
100
  var e = this, t = e._self._c;
74
101
  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,
102
+ }, T = [], j = /* @__PURE__ */ y(
103
+ N,
104
+ W,
105
+ T,
79
106
  !1,
80
107
  null,
81
108
  "8f854357",
82
109
  null,
83
110
  null
84
111
  );
85
- const ne = V.exports;
86
- const A = {
112
+ const ce = j.exports;
113
+ const O = {
87
114
  name: "SuggestionMenu",
88
115
  props: {
89
116
  items: { type: Array, required: !0 },
@@ -96,30 +123,30 @@ const A = {
96
123
  }
97
124
  }
98
125
  };
99
- var D = function() {
126
+ var P = function() {
100
127
  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) + " ")]);
128
+ return t("div", { staticClass: "bn-suggestion-menu" }, [e.items.length ? e._l(e.items, function(o, u) {
129
+ return t("div", { key: o.id, staticClass: "suggestion-menu-item", class: { active: u === e.selectedIndex }, on: { mousedown: function(s) {
130
+ return s.preventDefault(), e.handleItemClick(o);
131
+ } } }, [e._v(" " + e._s(o.label) + " ")]);
105
132
  }) : t("div", { staticClass: "suggestion-menu-item disabled" }, [e._v("无数据")])], 2);
106
- }, L = [], N = /* @__PURE__ */ y(
107
- A,
108
- D,
109
- L,
133
+ }, z = [], B = /* @__PURE__ */ y(
134
+ O,
135
+ P,
136
+ z,
110
137
  !1,
111
138
  null,
112
139
  "af9205e7",
113
140
  null,
114
141
  null
115
142
  );
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;
143
+ const K = B.exports;
144
+ function X(n, e, t, o) {
145
+ const u = f(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 && o && o(t.value[u.value]), !0) : !1;
119
146
  return p(() => {
120
- n && n.domElement && n.domElement.addEventListener("keydown", o, !0);
121
- }), h(() => {
122
- n && n.domElement && n.domElement.removeEventListener("keydown", o, !0);
147
+ n && n.domElement && n.domElement.addEventListener("keydown", s, !0);
148
+ }), S(() => {
149
+ n && n.domElement && n.domElement.removeEventListener("keydown", s, !0);
123
150
  }), g(
124
151
  () => e,
125
152
  () => {
@@ -127,21 +154,21 @@ function T(n, e, t, l) {
127
154
  }
128
155
  ), u;
129
156
  }
130
- function j(n, e, t, l = 8) {
131
- const u = d(0);
157
+ function H(n, e, t, o = 8) {
158
+ const u = f(0);
132
159
  return g(
133
160
  [n, e],
134
- ([o, r]) => {
135
- r != null && (o && o.length > 0 ? u.value = r.length : r.length - u.value > l && t());
161
+ ([s, r]) => {
162
+ r != null && (s && s.length > 0 ? u.value = r.length : r.length - u.value > o && t());
136
163
  }
137
164
  ), {
138
165
  lastUsefulQueryLength: u
139
166
  };
140
167
  }
141
- const O = {
168
+ const G = {
142
169
  name: "SuggestionMenuWrapper",
143
170
  components: {
144
- SuggestionMenu: W
171
+ SuggestionMenu: K
145
172
  },
146
173
  props: {
147
174
  query: { type: String, required: !0 },
@@ -152,106 +179,105 @@ const O = {
152
179
  insertMention: { type: Function, required: !0 }
153
180
  },
154
181
  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(
182
+ const e = f([]), t = f("idle"), o = f(""), u = $("editor"), s = (l) => {
183
+ n.closeMenu(), n.clearQuery(), n.insertMention(l);
184
+ }, r = X(
158
185
  u.value,
159
186
  n.query,
160
187
  e,
161
- o
188
+ s
162
189
  );
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");
190
+ H(e, o, n.closeMenu);
191
+ const d = () => {
192
+ const l = n.query;
193
+ o.value = n.query, t.value = "loading", n.getItems(n.query).then((a) => {
194
+ o.value === l && (e.value = a, t.value = "loaded");
168
195
  });
169
196
  };
170
- return p(f), g(
197
+ return p(d), g(
171
198
  () => n.query,
172
199
  () => {
173
- f();
200
+ d();
174
201
  }
175
202
  ), {
176
203
  items: e,
177
204
  loadingState: t,
178
205
  selectedIndex: r,
179
- onItemClickInternal: o
206
+ onItemClickInternal: s
180
207
  };
181
208
  }
182
209
  };
183
- var P = function() {
210
+ var J = function() {
184
211
  var e = this, t = e._self._c;
185
212
  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,
213
+ }, Y = [], Z = /* @__PURE__ */ y(
214
+ G,
215
+ J,
216
+ Y,
190
217
  !1,
191
218
  null,
192
219
  "e4189e8f",
193
220
  null,
194
221
  null
195
222
  );
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;
223
+ const ee = Z.exports;
224
+ function te(n, e, t, o = {}) {
225
+ const u = f(null), s = f(null), r = f({});
226
+ let d = null;
200
227
  g(
201
228
  e,
202
- (a) => {
203
- a && (u.value = {
204
- getBoundingClientRect: () => a
205
- }, s());
229
+ (i) => {
230
+ i && (u.value = {
231
+ getBoundingClientRect: () => i
232
+ }, l());
206
233
  },
207
234
  { immediate: !0 }
208
235
  ), g(
209
236
  n,
210
- async (a) => {
211
- if (!a) {
237
+ (i) => I(this, null, function* () {
238
+ if (!i) {
212
239
  c();
213
240
  return;
214
241
  }
215
- await k(), !(!u.value || !o.value) && (s(), i());
216
- }
242
+ yield V(), !(!u.value || !s.value) && (l(), a());
243
+ })
217
244
  );
218
- const s = () => {
219
- const a = u.value, v = o.value;
220
- !a || !v || x(a, v, {
221
- placement: l.placement || "bottom-start",
245
+ const l = () => {
246
+ const i = u.value, v = s.value;
247
+ !i || !v || A(i, v, {
248
+ placement: o.placement || "bottom-start",
222
249
  middleware: [
223
- I(l.offset || 8),
224
- S(),
225
- $({ padding: 8 })
250
+ q(o.offset || 8),
251
+ b(),
252
+ k({ padding: 8 })
226
253
  ]
227
- }).then(({ x: m, y: R }) => {
254
+ }).then(({ x: m, y: x }) => {
228
255
  r.value = {
229
256
  position: "absolute",
230
257
  left: `${m}px`,
231
- top: `${R}px`
258
+ top: `${x}px`
232
259
  };
233
260
  });
234
261
  };
235
- function i() {
236
- !u.value || !o.value || (f = E(u.value, o.value, s));
262
+ function a() {
263
+ !u.value || !s.value || (d = D(u.value, s.value, l));
237
264
  }
238
265
  function c() {
239
- f && (f(), f = null);
266
+ d && (d(), d = null);
240
267
  }
241
- const _ = C(() => ({
268
+ const _ = R(() => C({
242
269
  display: "flex",
243
- zIndex: t,
244
- ...r.value
245
- }));
270
+ zIndex: t
271
+ }, r.value));
246
272
  return {
247
- floatingRef: o,
273
+ floatingRef: s,
248
274
  style: _
249
275
  };
250
276
  }
251
- const H = {
277
+ const ne = {
252
278
  name: "SuggestionMenuController",
253
279
  components: {
254
- SuggestionMenuWrapper: K
280
+ SuggestionMenuWrapper: ee
255
281
  },
256
282
  props: {
257
283
  triggerCharacter: { type: String, required: !0 },
@@ -260,11 +286,12 @@ const H = {
260
286
  onItemClick: { type: Function }
261
287
  },
262
288
  setup(n) {
263
- const e = M("editor"), t = d(null), l = C(() => {
289
+ const e = $("editor"), t = f(null), o = R(() => {
264
290
  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,
291
+ const c = ((_ = t.value) == null ? void 0 : _.show) && (!n.minQueryLength || t.value.ignoreQueryLength || !t.value.query.startsWith(" ") && t.value.query.length >= n.minQueryLength);
292
+ return c != null ? c : !1;
293
+ }), { floatingRef: u, style: s } = te(
294
+ () => o.value,
268
295
  () => {
269
296
  var c;
270
297
  return ((c = t.value) == null ? void 0 : c.referencePos) || null;
@@ -273,10 +300,10 @@ const H = {
273
300
  {
274
301
  placement: "bottom-start",
275
302
  middleware: [
276
- I(10),
277
- S({ mainAxis: !0, crossAxis: !1 }),
278
- $(),
279
- w({
303
+ q(10),
304
+ b({ mainAxis: !0, crossAxis: !1 }),
305
+ k(),
306
+ L({
280
307
  apply({ availableHeight: c, elements: _ }) {
281
308
  Object.assign(_.floating.style, {
282
309
  maxHeight: `${c - 10}px`
@@ -296,13 +323,13 @@ const H = {
296
323
  t.value = c;
297
324
  }
298
325
  );
299
- }), h(() => {
326
+ }), S(() => {
300
327
  r && r();
301
328
  }), {
302
329
  state: t,
303
330
  floatingRef: u,
304
- style: o,
305
- showDom: l,
331
+ style: s,
332
+ showDom: o,
306
333
  closeMenu: () => {
307
334
  e.value.suggestionMenus.closeMenu();
308
335
  },
@@ -315,22 +342,22 @@ const H = {
315
342
  };
316
343
  }
317
344
  };
318
- var G = function() {
345
+ var ue = function() {
319
346
  var e = this, t = e._self._c;
320
347
  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,
348
+ }, re = [], le = /* @__PURE__ */ y(
349
+ ne,
350
+ ue,
351
+ re,
325
352
  !1,
326
353
  null,
327
354
  "f5b73a66",
328
355
  null,
329
356
  null
330
357
  );
331
- const ue = Y.exports;
358
+ const de = le.exports;
332
359
  export {
333
- ne as MEditorVue2,
334
- ue as SuggestionMenuController,
335
- ne as default
360
+ ce as MEditorVue2,
361
+ de as SuggestionMenuController,
362
+ ce as default
336
363
  };
package/package.json CHANGED
@@ -1,10 +1,18 @@
1
1
  {
2
2
  "name": "@shenjipo/mention-vue2",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "style": "dist/index.css",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.esm.js",
11
+ "require": "./dist/index.cjs.js",
12
+ "types": "./dist/index.d.ts"
13
+ },
14
+ "./dist/index.css": "./dist/index.css"
15
+ },
8
16
  "files": [
9
17
  "dist"
10
18
  ],
@@ -15,7 +23,7 @@
15
23
  "@floating-ui/dom": "^1.1.9",
16
24
  "vue": "^2.7.7",
17
25
  "vue-demi": "^0.14.10",
18
- "@shenjipo/mention-editor": "2.2.0"
26
+ "@shenjipo/mention-editor": "2.3.0"
19
27
  },
20
28
  "devDependencies": {
21
29
  "@types/node": "^16.11.45",