@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.
@@ -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 Vue from 'vue'
2
-
3
- /** mention-editor 中透出的 item */
4
- export interface MentionItem {
5
- id: string | number
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,mCAAmC,CAAC;AACjE,OAAO,oBAAoB,CAAC;AAE5B,eAAe,gBAAgB,CAAA"}
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 { createMentionEditor as _ } from "@shenjipo/mention-editor";
2
- import g, { ref as l } from "vue";
3
- function v(t, e = {}) {
4
- const o = typeof t == "function" ? t : g.extend(t), u = new o({
5
- propsData: e
6
- });
7
- return u.$mount(), u.$el;
8
- }
9
- const C = () => {
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, !i && typeof __VUE_SSR_CONTEXT__ < "u" && (i = __VUE_SSR_CONTEXT__), r && r.call(this, i), i && i._registeredComponents && i._registeredComponents.add(s);
34
- }, n._ssrRegister = a) : r && (a = c ? function() {
35
- r.call(
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
- (n.functional ? this.parent : this).$root.$options.shadowRoot
15
+ (s.functional ? this.parent : this).$root.$options.shadowRoot
38
16
  );
39
- } : r), a)
40
- if (n.functional) {
41
- n._injectStyles = a;
42
- var h = n.render;
43
- n.render = function(p, m) {
44
- return a.call(m), h(p, m);
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 f = n.beforeCreate;
48
- n.beforeCreate = f ? [].concat(f, a) : [a];
25
+ var _ = s.beforeCreate;
26
+ s.beforeCreate = _ ? [].concat(_, i) : [i];
49
27
  }
50
28
  return {
51
- exports: t,
52
- options: n
29
+ exports: n,
30
+ options: s
53
31
  };
54
32
  }
55
- const R = {
56
- name: "MentionInputVue2",
57
- data() {
58
- return {
59
- flag: !0
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
- value: {
64
- type: String,
65
- default: ""
66
- },
67
- placeholder: {
68
- type: String,
69
- default: "请输入..."
70
- },
71
- suggestionDom: {
72
- type: HTMLElement,
73
- default: null
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
- suggestionComponent: {
76
- type: Function,
77
- // Vue component constructor
78
- required: !0
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
- data() {
82
- return {
83
- editor: null,
84
- mentionBridge: C()
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
- mounted() {
88
- const t = v(
89
- this.suggestionComponent,
90
- { mentionBridge: this.mentionBridge }
91
- );
92
- this.editor = _({
93
- element: this.$refs.editorRef,
94
- content: this.value,
95
- onCommand: (e) => {
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
- suggestionDom: t,
99
- bridge: this.mentionBridge,
100
- placeholder: this.placeholder,
101
- onUpdate: (e) => {
102
- this.$emit("input", e), this.$emit("change", e);
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
- onImageInput: (e, o, u, r) => {
105
- this.$emit("onFileChange", e, o, u, r);
309
+ clearQuery: () => {
310
+ e.value.suggestionMenus.clearQuery();
106
311
  },
107
- onFileReject: (e) => {
108
- this.$emit("onFileReject", e);
312
+ insertMention: (c) => {
313
+ e.value.suggestionMenus.insertMention(c);
109
314
  }
110
- }), this.editor.editor.on("enter", () => {
111
- this.$emit("enter");
112
- });
113
- },
114
- methods: {
115
- refresh() {
116
- }
315
+ };
117
316
  }
118
317
  };
119
- var y = function() {
120
- var e = this, o = e._self._c;
121
- return o("div", { staticClass: "mention-editor-wrapper" }, [e._t("header"), o("div", { ref: "editorRef", staticClass: "mention-editor" }), e._t("footer")], 2);
122
- }, F = [], I = /* @__PURE__ */ $(
123
- R,
124
- y,
125
- F,
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
- null,
327
+ "f5b73a66",
129
328
  null,
130
329
  null
131
330
  );
132
- const B = I.exports;
331
+ const ue = Y.exports;
133
332
  export {
134
- B as default
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
- "name": "@shenjipo/mention-vue2",
3
- "version": "1.0.0",
4
- "type": "module",
5
- "main": "dist/index.esm.js",
6
- "module": "dist/index.esm.js",
7
- "types": "dist/index.d.ts",
8
- "style": "dist/index.css",
9
- "files": [
10
- "dist"
11
- ],
12
- "publishConfig": {
13
- "access": "public"
14
- },
15
- "dependencies": {
16
- "vue": "^2.7.7",
17
- "vue-class-component": "^6.0.0",
18
- "vue-property-decorator": "^7.0.0",
19
- "@shenjipo/mention-editor": "1.0.0"
20
- },
21
- "devDependencies": {
22
- "@types/node": "^16.11.45",
23
- "@vitejs/plugin-vue2": "^1.1.2",
24
- "@vue/tsconfig": "^0.1.3",
25
- "cpx": "^1.5.0",
26
- "npm-run-all": "^4.1.5",
27
- "sass": "^1.97.0",
28
- "terser": "^5.14.2",
29
- "typescript": "^5.0.0",
30
- "vite": "^4.0.2",
31
- "vite-plugin-dts": "^4.5.4",
32
- "vue-tsc": "^0.38.8"
33
- },
34
- "scripts": {
35
- "dev": "vite",
36
- "build": "vite build && cpx src/index.d.ts dist",
37
- "build:watch": "vite build --watch"
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
@@ -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"}