@v-c/mentions 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/DropdownMenu.cjs +124 -0
- package/dist/DropdownMenu.d.ts +12 -0
- package/dist/DropdownMenu.js +117 -0
- package/dist/KeywordTrigger.cjs +130 -0
- package/dist/KeywordTrigger.d.ts +16 -0
- package/dist/KeywordTrigger.js +123 -0
- package/dist/Mentions.cjs +802 -0
- package/dist/Mentions.d.ts +58 -0
- package/dist/Mentions.js +795 -0
- package/dist/MentionsContext.cjs +19 -0
- package/dist/MentionsContext.d.ts +18 -0
- package/dist/MentionsContext.js +16 -0
- package/dist/Option.cjs +7 -0
- package/dist/Option.d.ts +10 -0
- package/dist/Option.js +3 -0
- package/dist/_virtual/rolldown_runtime.cjs +21 -0
- package/dist/context.cjs +12 -0
- package/dist/context.d.ts +7 -0
- package/dist/context.js +9 -0
- package/dist/hooks/useEffectState.cjs +23 -0
- package/dist/hooks/useEffectState.d.ts +5 -0
- package/dist/hooks/useEffectState.js +18 -0
- package/dist/index.cjs +12 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/util.cjs +65 -0
- package/dist/util.d.ts +37 -0
- package/dist/util.js +59 -0
- package/package.json +40 -0
package/dist/Mentions.js
ADDED
|
@@ -0,0 +1,795 @@
|
|
|
1
|
+
import { MentionsProvider } from "./MentionsContext.js";
|
|
2
|
+
import KeywordTrigger_default from "./KeywordTrigger.js";
|
|
3
|
+
import { useUnstableContext } from "./context.js";
|
|
4
|
+
import useEffectState from "./hooks/useEffectState.js";
|
|
5
|
+
import { filterOption, getBeforeSelectionText, getLastMeasureIndex, replaceWithMeasure, setInputSelection, validateSearch } from "./util.js";
|
|
6
|
+
import { Fragment, computed, createVNode, defineComponent, mergeDefaults, mergeProps, shallowRef, watch } from "vue";
|
|
7
|
+
import { BaseInput } from "@v-c/input";
|
|
8
|
+
import TextArea from "@v-c/textarea";
|
|
9
|
+
import { KeyCode, clsx, omit, useId } from "@v-c/util";
|
|
10
|
+
import { toArray } from "@v-c/util/dist/Children/toArray";
|
|
11
|
+
import { filterEmpty, getAttrStyleAndClass } from "@v-c/util/dist/props-util";
|
|
12
|
+
var omitKeys = [
|
|
13
|
+
"prefixCls",
|
|
14
|
+
"className",
|
|
15
|
+
"style",
|
|
16
|
+
"classNames",
|
|
17
|
+
"styles",
|
|
18
|
+
"prefix",
|
|
19
|
+
"split",
|
|
20
|
+
"notFoundContent",
|
|
21
|
+
"value",
|
|
22
|
+
"defaultValue",
|
|
23
|
+
"children",
|
|
24
|
+
"options",
|
|
25
|
+
"allowClear",
|
|
26
|
+
"suffix",
|
|
27
|
+
"hasWrapper",
|
|
28
|
+
"silent",
|
|
29
|
+
"validateSearch",
|
|
30
|
+
"filterOption",
|
|
31
|
+
"onChange",
|
|
32
|
+
"onKeydown",
|
|
33
|
+
"onKeyup",
|
|
34
|
+
"onPressEnter",
|
|
35
|
+
"onSearch",
|
|
36
|
+
"onSelect",
|
|
37
|
+
"onFocus",
|
|
38
|
+
"onBlur",
|
|
39
|
+
"transitionName",
|
|
40
|
+
"placement",
|
|
41
|
+
"direction",
|
|
42
|
+
"getPopupContainer",
|
|
43
|
+
"popupClassName",
|
|
44
|
+
"rows",
|
|
45
|
+
"visible",
|
|
46
|
+
"onPopupScroll"
|
|
47
|
+
];
|
|
48
|
+
var defaults = {
|
|
49
|
+
prefix: "@",
|
|
50
|
+
prefixCls: "vc-mentions",
|
|
51
|
+
split: " ",
|
|
52
|
+
notFoundContent: "Not Found",
|
|
53
|
+
validateSearch,
|
|
54
|
+
filterOption,
|
|
55
|
+
rows: 1
|
|
56
|
+
};
|
|
57
|
+
var InternalMentions = /* @__PURE__ */ defineComponent((props, { slots, expose, attrs }) => {
|
|
58
|
+
const mergedPrefix = computed(() => {
|
|
59
|
+
const prefix = props.prefix;
|
|
60
|
+
return Array.isArray(prefix) ? prefix : [prefix];
|
|
61
|
+
});
|
|
62
|
+
const containerRef = shallowRef();
|
|
63
|
+
const textareaRef = shallowRef();
|
|
64
|
+
const measureRef = shallowRef();
|
|
65
|
+
const getTextArea = () => textareaRef.value?.resizableTextArea?.textArea;
|
|
66
|
+
expose({
|
|
67
|
+
focus: () => textareaRef.value?.focus?.(),
|
|
68
|
+
blur: () => textareaRef.value?.blur?.(),
|
|
69
|
+
textarea: computed(() => textareaRef.value?.resizableTextArea?.textArea),
|
|
70
|
+
nativeElement: containerRef
|
|
71
|
+
});
|
|
72
|
+
const measuring = shallowRef(false);
|
|
73
|
+
const measureText = shallowRef("");
|
|
74
|
+
const measurePrefix = shallowRef("");
|
|
75
|
+
const measureLocation = shallowRef(0);
|
|
76
|
+
const activeIndex = shallowRef(0);
|
|
77
|
+
const isFocus = shallowRef(false);
|
|
78
|
+
const setActiveIndex = (index) => {
|
|
79
|
+
activeIndex.value = index;
|
|
80
|
+
};
|
|
81
|
+
const uniqueKey = useId(props.id);
|
|
82
|
+
const mergedValue = shallowRef(props.value ?? props?.defaultValue ?? "");
|
|
83
|
+
watch(() => props?.value, () => {
|
|
84
|
+
mergedValue.value = props.value ?? "";
|
|
85
|
+
});
|
|
86
|
+
const { open } = useUnstableContext();
|
|
87
|
+
watch(measuring, () => {
|
|
88
|
+
if (measuring.value && measureRef.value) measureRef.value.scrollTop = getTextArea()?.scrollTop;
|
|
89
|
+
}, { immediate: true });
|
|
90
|
+
const mergedMeasuringInfo = computed(() => {
|
|
91
|
+
if (open?.value) for (let i = 0; i < mergedPrefix.value.length; i += 1) {
|
|
92
|
+
const curPrefix = mergedPrefix.value[i];
|
|
93
|
+
const index = mergedValue.value.lastIndexOf(curPrefix);
|
|
94
|
+
if (index >= 0) return [
|
|
95
|
+
true,
|
|
96
|
+
"",
|
|
97
|
+
curPrefix,
|
|
98
|
+
index
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
return [
|
|
102
|
+
measuring.value,
|
|
103
|
+
measureText.value,
|
|
104
|
+
measurePrefix.value,
|
|
105
|
+
measureLocation.value
|
|
106
|
+
];
|
|
107
|
+
});
|
|
108
|
+
const mergedMeasuring = computed(() => mergedMeasuringInfo.value[0]);
|
|
109
|
+
const mergedMeasureText = computed(() => mergedMeasuringInfo.value[1]);
|
|
110
|
+
const mergedMeasurePrefix = computed(() => mergedMeasuringInfo.value[2]);
|
|
111
|
+
const mergedMeasureLocation = computed(() => mergedMeasuringInfo.value[3]);
|
|
112
|
+
const children = computed(() => {
|
|
113
|
+
const _child = slots?.default ? slots?.default?.() : [];
|
|
114
|
+
if (_child) return filterEmpty(_child).filter(Boolean);
|
|
115
|
+
return _child;
|
|
116
|
+
});
|
|
117
|
+
const getOptions = (targetMeasureText) => {
|
|
118
|
+
let list;
|
|
119
|
+
const options = props?.options ?? [];
|
|
120
|
+
const filterOption$1 = props?.filterOption ?? filterOption;
|
|
121
|
+
if (options && options.length > 0) list = options.map((item) => ({
|
|
122
|
+
...item,
|
|
123
|
+
key: `${item?.key ?? item.value}-${uniqueKey}`
|
|
124
|
+
}));
|
|
125
|
+
else list = toArray(children.value).map(({ props: optionProps, key }) => ({
|
|
126
|
+
...optionProps,
|
|
127
|
+
label: optionProps.children?.default?.(),
|
|
128
|
+
key: `${key || optionProps.value}-${uniqueKey}`
|
|
129
|
+
}));
|
|
130
|
+
return list.filter((option) => {
|
|
131
|
+
if (filterOption$1 === false) return true;
|
|
132
|
+
if (typeof filterOption$1 !== "function") return true;
|
|
133
|
+
return filterOption$1(targetMeasureText, option);
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
const mergedOptions = computed(() => getOptions(mergedMeasureText.value));
|
|
137
|
+
const onSelectionEffect = useEffectState();
|
|
138
|
+
const startMeasure = (nextMeasureText, nextMeasurePrefix, nextMeasureLocation) => {
|
|
139
|
+
measuring.value = true;
|
|
140
|
+
measureText.value = nextMeasureText;
|
|
141
|
+
measurePrefix.value = nextMeasurePrefix;
|
|
142
|
+
measureLocation.value = nextMeasureLocation;
|
|
143
|
+
activeIndex.value = 0;
|
|
144
|
+
};
|
|
145
|
+
const stopMeasure = (callback) => {
|
|
146
|
+
measuring.value = false;
|
|
147
|
+
measureLocation.value = 0;
|
|
148
|
+
measureText.value = "";
|
|
149
|
+
onSelectionEffect(callback);
|
|
150
|
+
};
|
|
151
|
+
const triggerChange = (nextValue) => {
|
|
152
|
+
mergedValue.value = nextValue;
|
|
153
|
+
props?.onChange?.(nextValue);
|
|
154
|
+
};
|
|
155
|
+
const onInternalChange = (e) => {
|
|
156
|
+
const nextValue = e?.target?.value;
|
|
157
|
+
triggerChange(nextValue);
|
|
158
|
+
};
|
|
159
|
+
const selectOption = (option) => {
|
|
160
|
+
const { value: mentionValue = "" } = option;
|
|
161
|
+
const textArea = getTextArea();
|
|
162
|
+
const { text, selectionLocation } = replaceWithMeasure(mergedValue.value, {
|
|
163
|
+
measureLocation: mergedMeasureLocation.value,
|
|
164
|
+
targetText: mentionValue,
|
|
165
|
+
prefix: mergedMeasurePrefix.value,
|
|
166
|
+
selectionStart: textArea?.selectionStart,
|
|
167
|
+
split: props.split
|
|
168
|
+
});
|
|
169
|
+
triggerChange(text);
|
|
170
|
+
stopMeasure(() => {
|
|
171
|
+
setInputSelection(textArea, selectionLocation);
|
|
172
|
+
});
|
|
173
|
+
props?.onSelect?.(option, mergedMeasurePrefix.value);
|
|
174
|
+
};
|
|
175
|
+
const onInternalKeyDown = (event) => {
|
|
176
|
+
const { which } = event;
|
|
177
|
+
props?.onKeydown?.(event);
|
|
178
|
+
if (!mergedMeasuring.value) return;
|
|
179
|
+
if (which === KeyCode.UP || which === KeyCode.DOWN) {
|
|
180
|
+
const optionLen = mergedOptions.value.length;
|
|
181
|
+
const offset = which === KeyCode.UP ? -1 : 1;
|
|
182
|
+
activeIndex.value = (activeIndex.value + offset + optionLen) % optionLen;
|
|
183
|
+
event.preventDefault();
|
|
184
|
+
} else if (which === KeyCode.ESC) stopMeasure();
|
|
185
|
+
else if (which === KeyCode.ENTER) {
|
|
186
|
+
event.preventDefault();
|
|
187
|
+
if (props?.silent) return;
|
|
188
|
+
if (!mergedOptions.value.length) {
|
|
189
|
+
stopMeasure();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const option = mergedOptions.value[activeIndex.value];
|
|
193
|
+
selectOption(option);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
const onInternalKeyUp = (event) => {
|
|
197
|
+
const { key, which } = event;
|
|
198
|
+
const target = event.target;
|
|
199
|
+
const selectionStartText = getBeforeSelectionText(target);
|
|
200
|
+
const { location: measureIndex, prefix: nextMeasurePrefix } = getLastMeasureIndex(selectionStartText, mergedPrefix.value);
|
|
201
|
+
props?.onKeyup?.(event);
|
|
202
|
+
if ([
|
|
203
|
+
KeyCode.ESC,
|
|
204
|
+
KeyCode.UP,
|
|
205
|
+
KeyCode.DOWN,
|
|
206
|
+
KeyCode.ENTER
|
|
207
|
+
].includes(which)) return;
|
|
208
|
+
if (measureIndex !== -1) {
|
|
209
|
+
const nextMeasureText = selectionStartText.slice(measureIndex + nextMeasurePrefix.length);
|
|
210
|
+
const validateMeasure = (typeof props.validateSearch === "function" ? props.validateSearch : validateSearch)(nextMeasureText, props.split);
|
|
211
|
+
const matchOption = !!getOptions(nextMeasureText).length;
|
|
212
|
+
if (validateMeasure) {
|
|
213
|
+
if (key === nextMeasurePrefix || key === "Shift" || which === KeyCode.ALT || key === "AltGraph" || mergedMeasuring.value || nextMeasureText !== mergedMeasureText.value && matchOption) startMeasure(nextMeasureText, nextMeasurePrefix, measureIndex);
|
|
214
|
+
} else if (mergedMeasuring.value) stopMeasure();
|
|
215
|
+
const onSearch = props?.onSearch;
|
|
216
|
+
if (onSearch && validateMeasure) onSearch(nextMeasureText, nextMeasurePrefix);
|
|
217
|
+
} else if (mergedMeasuring.value) stopMeasure();
|
|
218
|
+
};
|
|
219
|
+
const onInternalPressEnter = (event) => {
|
|
220
|
+
const onPressEnter = props?.onPressEnter;
|
|
221
|
+
if (!mergedMeasuring.value && onPressEnter) onPressEnter(event);
|
|
222
|
+
};
|
|
223
|
+
const focusRef = shallowRef();
|
|
224
|
+
const onInternalFocus = (event) => {
|
|
225
|
+
window.clearTimeout(focusRef.value);
|
|
226
|
+
const onFocus = props?.onFocus;
|
|
227
|
+
if (!isFocus.value && event && onFocus) onFocus(event);
|
|
228
|
+
isFocus.value = true;
|
|
229
|
+
};
|
|
230
|
+
const onInternalBlur = (event) => {
|
|
231
|
+
focusRef.value = window.setTimeout(() => {
|
|
232
|
+
isFocus.value = false;
|
|
233
|
+
stopMeasure();
|
|
234
|
+
props?.onBlur?.(event);
|
|
235
|
+
}, 0);
|
|
236
|
+
};
|
|
237
|
+
const onDropdownFocus = () => {
|
|
238
|
+
onInternalFocus();
|
|
239
|
+
};
|
|
240
|
+
const onDropdownBlur = () => {
|
|
241
|
+
onInternalBlur();
|
|
242
|
+
};
|
|
243
|
+
const onInternalPopupScroll = (event) => {
|
|
244
|
+
props?.onPopupScroll?.(event);
|
|
245
|
+
};
|
|
246
|
+
return () => {
|
|
247
|
+
const { classNames: mentionClassNames, styles, rows = 1, prefixCls, notFoundContent } = props;
|
|
248
|
+
const restProps = omit(props, omitKeys);
|
|
249
|
+
const { className, restAttrs, style } = getAttrStyleAndClass(attrs);
|
|
250
|
+
const resizeStyle = styles?.textarea?.resize ?? style?.resize;
|
|
251
|
+
const mergedTextareaStyle = { ...styles?.textarea };
|
|
252
|
+
if (resizeStyle !== void 0) mergedTextareaStyle.resize = resizeStyle;
|
|
253
|
+
const mergedStyles = {
|
|
254
|
+
...styles,
|
|
255
|
+
textarea: mergedTextareaStyle
|
|
256
|
+
};
|
|
257
|
+
const mentionNode = createVNode(Fragment, null, [createVNode(TextArea, mergeProps({
|
|
258
|
+
"classNames": { textarea: mentionClassNames?.textarea },
|
|
259
|
+
"styles": mergedStyles,
|
|
260
|
+
"ref": textareaRef,
|
|
261
|
+
"value": mergedValue.value
|
|
262
|
+
}, restAttrs, restProps, { rows }, {
|
|
263
|
+
"onChange": onInternalChange,
|
|
264
|
+
"onKeydown": onInternalKeyDown,
|
|
265
|
+
"onKeyup": onInternalKeyUp,
|
|
266
|
+
"onPressEnter": onInternalPressEnter,
|
|
267
|
+
"onFocus": onInternalFocus,
|
|
268
|
+
"onBlur": onInternalBlur
|
|
269
|
+
}), null), mergedMeasuring.value && createVNode("div", {
|
|
270
|
+
"ref": measureRef,
|
|
271
|
+
"class": `${prefixCls}-measure`
|
|
272
|
+
}, [
|
|
273
|
+
mergedValue.value.slice(0, mergedMeasureLocation.value),
|
|
274
|
+
createVNode(MentionsProvider, { "value": {
|
|
275
|
+
notFoundContent,
|
|
276
|
+
activeIndex: activeIndex.value,
|
|
277
|
+
setActiveIndex,
|
|
278
|
+
selectOption,
|
|
279
|
+
onFocus: onDropdownFocus,
|
|
280
|
+
onBlur: onDropdownBlur,
|
|
281
|
+
onScroll: onInternalPopupScroll
|
|
282
|
+
} }, { default: () => [createVNode(KeywordTrigger_default, {
|
|
283
|
+
"prefixCls": prefixCls,
|
|
284
|
+
"transitionName": props.transitionName,
|
|
285
|
+
"placement": props.placement,
|
|
286
|
+
"direction": props.direction,
|
|
287
|
+
"options": mergedOptions.value,
|
|
288
|
+
"visible": true,
|
|
289
|
+
"getPopupContainer": props.getPopupContainer,
|
|
290
|
+
"popupClassName": clsx(props.popupClassName, mentionClassNames?.popup),
|
|
291
|
+
"popupStyle": styles?.popup
|
|
292
|
+
}, { default: () => [createVNode("span", null, [mergedMeasurePrefix.value])] })] }),
|
|
293
|
+
mergedValue.value.slice(mergedMeasureLocation.value + mergedMeasurePrefix.value.length)
|
|
294
|
+
])]);
|
|
295
|
+
if (!props.hasWrapper) return createVNode("div", {
|
|
296
|
+
"class": clsx(prefixCls, props.className, className),
|
|
297
|
+
"style": style,
|
|
298
|
+
"ref": containerRef
|
|
299
|
+
}, [mentionNode]);
|
|
300
|
+
return mentionNode;
|
|
301
|
+
};
|
|
302
|
+
}, {
|
|
303
|
+
props: /* @__PURE__ */ mergeDefaults({
|
|
304
|
+
hasWrapper: {
|
|
305
|
+
type: Boolean,
|
|
306
|
+
required: true,
|
|
307
|
+
default: void 0
|
|
308
|
+
},
|
|
309
|
+
id: {
|
|
310
|
+
type: String,
|
|
311
|
+
required: false,
|
|
312
|
+
default: void 0
|
|
313
|
+
},
|
|
314
|
+
autoFocus: {
|
|
315
|
+
type: Boolean,
|
|
316
|
+
required: false,
|
|
317
|
+
default: void 0
|
|
318
|
+
},
|
|
319
|
+
className: {
|
|
320
|
+
type: String,
|
|
321
|
+
required: false,
|
|
322
|
+
default: void 0
|
|
323
|
+
},
|
|
324
|
+
defaultValue: {
|
|
325
|
+
type: String,
|
|
326
|
+
required: false,
|
|
327
|
+
default: void 0
|
|
328
|
+
},
|
|
329
|
+
notFoundContent: {
|
|
330
|
+
type: [
|
|
331
|
+
Object,
|
|
332
|
+
Function,
|
|
333
|
+
String,
|
|
334
|
+
Number,
|
|
335
|
+
null,
|
|
336
|
+
Boolean,
|
|
337
|
+
Array
|
|
338
|
+
],
|
|
339
|
+
required: false,
|
|
340
|
+
default: void 0
|
|
341
|
+
},
|
|
342
|
+
split: {
|
|
343
|
+
type: String,
|
|
344
|
+
required: false,
|
|
345
|
+
default: void 0
|
|
346
|
+
},
|
|
347
|
+
transitionName: {
|
|
348
|
+
type: String,
|
|
349
|
+
required: false,
|
|
350
|
+
default: void 0
|
|
351
|
+
},
|
|
352
|
+
placement: {
|
|
353
|
+
type: String,
|
|
354
|
+
required: false,
|
|
355
|
+
default: void 0
|
|
356
|
+
},
|
|
357
|
+
direction: {
|
|
358
|
+
type: String,
|
|
359
|
+
required: false,
|
|
360
|
+
default: void 0
|
|
361
|
+
},
|
|
362
|
+
prefix: {
|
|
363
|
+
type: [String, Array],
|
|
364
|
+
required: false,
|
|
365
|
+
default: void 0
|
|
366
|
+
},
|
|
367
|
+
prefixCls: {
|
|
368
|
+
type: String,
|
|
369
|
+
required: false,
|
|
370
|
+
default: void 0
|
|
371
|
+
},
|
|
372
|
+
value: {
|
|
373
|
+
type: String,
|
|
374
|
+
required: false,
|
|
375
|
+
default: void 0
|
|
376
|
+
},
|
|
377
|
+
silent: {
|
|
378
|
+
type: Boolean,
|
|
379
|
+
required: false,
|
|
380
|
+
default: void 0
|
|
381
|
+
},
|
|
382
|
+
filterOption: {
|
|
383
|
+
type: Boolean,
|
|
384
|
+
required: false,
|
|
385
|
+
skipCheck: true,
|
|
386
|
+
default: void 0
|
|
387
|
+
},
|
|
388
|
+
validateSearch: {
|
|
389
|
+
required: false,
|
|
390
|
+
default: void 0
|
|
391
|
+
},
|
|
392
|
+
onChange: {
|
|
393
|
+
type: Function,
|
|
394
|
+
required: false,
|
|
395
|
+
default: void 0
|
|
396
|
+
},
|
|
397
|
+
onSelect: {
|
|
398
|
+
type: Function,
|
|
399
|
+
required: false,
|
|
400
|
+
default: void 0
|
|
401
|
+
},
|
|
402
|
+
onSearch: {
|
|
403
|
+
type: Function,
|
|
404
|
+
required: false,
|
|
405
|
+
default: void 0
|
|
406
|
+
},
|
|
407
|
+
onFocus: {
|
|
408
|
+
type: Function,
|
|
409
|
+
required: false,
|
|
410
|
+
default: void 0
|
|
411
|
+
},
|
|
412
|
+
onBlur: {
|
|
413
|
+
type: Function,
|
|
414
|
+
required: false,
|
|
415
|
+
default: void 0
|
|
416
|
+
},
|
|
417
|
+
getPopupContainer: {
|
|
418
|
+
type: Function,
|
|
419
|
+
required: false,
|
|
420
|
+
default: void 0
|
|
421
|
+
},
|
|
422
|
+
popupClassName: {
|
|
423
|
+
type: String,
|
|
424
|
+
required: false,
|
|
425
|
+
default: void 0
|
|
426
|
+
},
|
|
427
|
+
options: {
|
|
428
|
+
type: Array,
|
|
429
|
+
required: false,
|
|
430
|
+
default: void 0
|
|
431
|
+
},
|
|
432
|
+
classNames: {
|
|
433
|
+
type: Object,
|
|
434
|
+
required: false,
|
|
435
|
+
default: void 0
|
|
436
|
+
},
|
|
437
|
+
styles: {
|
|
438
|
+
type: Object,
|
|
439
|
+
required: false,
|
|
440
|
+
default: void 0
|
|
441
|
+
},
|
|
442
|
+
onPopupScroll: {
|
|
443
|
+
type: Function,
|
|
444
|
+
required: false,
|
|
445
|
+
default: void 0
|
|
446
|
+
},
|
|
447
|
+
rows: {
|
|
448
|
+
required: false,
|
|
449
|
+
default: void 0
|
|
450
|
+
},
|
|
451
|
+
disabled: {
|
|
452
|
+
type: Boolean,
|
|
453
|
+
required: false,
|
|
454
|
+
default: void 0
|
|
455
|
+
},
|
|
456
|
+
autoSize: {
|
|
457
|
+
type: [Boolean, Object],
|
|
458
|
+
required: false,
|
|
459
|
+
default: void 0
|
|
460
|
+
},
|
|
461
|
+
onPressEnter: {
|
|
462
|
+
type: Function,
|
|
463
|
+
required: false,
|
|
464
|
+
default: void 0
|
|
465
|
+
},
|
|
466
|
+
onResize: {
|
|
467
|
+
type: Function,
|
|
468
|
+
required: false,
|
|
469
|
+
default: void 0
|
|
470
|
+
},
|
|
471
|
+
allowClear: {
|
|
472
|
+
type: [Boolean, Object],
|
|
473
|
+
required: false,
|
|
474
|
+
default: void 0
|
|
475
|
+
},
|
|
476
|
+
suffix: {
|
|
477
|
+
required: false,
|
|
478
|
+
default: void 0
|
|
479
|
+
},
|
|
480
|
+
count: {
|
|
481
|
+
required: false,
|
|
482
|
+
default: void 0
|
|
483
|
+
},
|
|
484
|
+
onClear: {
|
|
485
|
+
type: Function,
|
|
486
|
+
required: false,
|
|
487
|
+
default: void 0
|
|
488
|
+
},
|
|
489
|
+
maxLength: {
|
|
490
|
+
type: Number,
|
|
491
|
+
required: false,
|
|
492
|
+
default: void 0
|
|
493
|
+
},
|
|
494
|
+
hidden: {
|
|
495
|
+
type: Boolean,
|
|
496
|
+
required: false,
|
|
497
|
+
default: void 0
|
|
498
|
+
},
|
|
499
|
+
readOnly: {
|
|
500
|
+
type: Boolean,
|
|
501
|
+
required: false,
|
|
502
|
+
default: void 0
|
|
503
|
+
},
|
|
504
|
+
placeholder: {
|
|
505
|
+
type: String,
|
|
506
|
+
required: false,
|
|
507
|
+
default: void 0
|
|
508
|
+
},
|
|
509
|
+
onKeydown: {
|
|
510
|
+
type: Function,
|
|
511
|
+
required: false,
|
|
512
|
+
default: void 0
|
|
513
|
+
},
|
|
514
|
+
onKeyup: {
|
|
515
|
+
type: Function,
|
|
516
|
+
required: false,
|
|
517
|
+
default: void 0
|
|
518
|
+
}
|
|
519
|
+
}, defaults),
|
|
520
|
+
name: "VMentions",
|
|
521
|
+
inheritAttrs: false
|
|
522
|
+
});
|
|
523
|
+
var Mentions_default = /* @__PURE__ */ defineComponent((props, { expose, attrs }) => {
|
|
524
|
+
const hasSuffix = computed(() => !!(props.suffix || props.allowClear));
|
|
525
|
+
const holderRef = shallowRef();
|
|
526
|
+
const mentionRef = shallowRef();
|
|
527
|
+
const mergedValue = shallowRef(props?.value ?? props?.defaultValue ?? "");
|
|
528
|
+
watch(() => props.value, () => {
|
|
529
|
+
mergedValue.value = props.value ?? "";
|
|
530
|
+
});
|
|
531
|
+
const setMergedValue = (value) => {
|
|
532
|
+
mergedValue.value = value;
|
|
533
|
+
};
|
|
534
|
+
const triggerChange = (nextValue) => {
|
|
535
|
+
setMergedValue(nextValue);
|
|
536
|
+
props?.onChange?.(nextValue);
|
|
537
|
+
};
|
|
538
|
+
const handleReset = () => {
|
|
539
|
+
triggerChange("");
|
|
540
|
+
};
|
|
541
|
+
expose({
|
|
542
|
+
focus: () => mentionRef.value?.focus?.(),
|
|
543
|
+
blur: () => mentionRef.value?.blur?.(),
|
|
544
|
+
textarea: computed(() => mentionRef.value?.textarea || null),
|
|
545
|
+
nativeElement: computed(() => holderRef.value?.nativeElement || mentionRef.value?.nativeElement)
|
|
546
|
+
});
|
|
547
|
+
return () => {
|
|
548
|
+
const { suffix, prefixCls = "vc-mentions", allowClear, classNames: mentionsClassNames, styles, className: propsClassName, disabled, onClear, id, value: _value, defaultValue: _defaultValue, onChange: _onChange, ...rest } = props;
|
|
549
|
+
const { className, style } = getAttrStyleAndClass(attrs);
|
|
550
|
+
const internalClassName = clsx(mentionsClassNames?.mentions, propsClassName);
|
|
551
|
+
const internalProps = {
|
|
552
|
+
...attrs,
|
|
553
|
+
...rest,
|
|
554
|
+
id,
|
|
555
|
+
value: mergedValue.value,
|
|
556
|
+
prefixCls,
|
|
557
|
+
className: internalClassName,
|
|
558
|
+
classNames: mentionsClassNames,
|
|
559
|
+
styles,
|
|
560
|
+
disabled,
|
|
561
|
+
hasWrapper: hasSuffix.value,
|
|
562
|
+
onChange: triggerChange
|
|
563
|
+
};
|
|
564
|
+
return createVNode(BaseInput, {
|
|
565
|
+
"ref": holderRef,
|
|
566
|
+
"suffix": suffix,
|
|
567
|
+
"prefixCls": prefixCls,
|
|
568
|
+
"value": mergedValue.value,
|
|
569
|
+
"allowClear": allowClear,
|
|
570
|
+
"handleReset": handleReset,
|
|
571
|
+
"class": clsx(prefixCls, propsClassName, className, { [`${prefixCls}-has-suffix`]: hasSuffix.value }),
|
|
572
|
+
"style": style,
|
|
573
|
+
"classNames": mentionsClassNames,
|
|
574
|
+
"styles": styles,
|
|
575
|
+
"disabled": disabled,
|
|
576
|
+
"onClear": onClear
|
|
577
|
+
}, { default: () => [createVNode(InternalMentions, mergeProps({ "ref": mentionRef }, internalProps), null)] });
|
|
578
|
+
};
|
|
579
|
+
}, {
|
|
580
|
+
props: {
|
|
581
|
+
id: {
|
|
582
|
+
type: String,
|
|
583
|
+
required: false,
|
|
584
|
+
default: void 0
|
|
585
|
+
},
|
|
586
|
+
autoFocus: {
|
|
587
|
+
type: Boolean,
|
|
588
|
+
required: false,
|
|
589
|
+
default: void 0
|
|
590
|
+
},
|
|
591
|
+
className: {
|
|
592
|
+
type: String,
|
|
593
|
+
required: false,
|
|
594
|
+
default: void 0
|
|
595
|
+
},
|
|
596
|
+
defaultValue: {
|
|
597
|
+
type: String,
|
|
598
|
+
required: false,
|
|
599
|
+
default: void 0
|
|
600
|
+
},
|
|
601
|
+
notFoundContent: {
|
|
602
|
+
type: [
|
|
603
|
+
Object,
|
|
604
|
+
Function,
|
|
605
|
+
String,
|
|
606
|
+
Number,
|
|
607
|
+
null,
|
|
608
|
+
Boolean,
|
|
609
|
+
Array
|
|
610
|
+
],
|
|
611
|
+
required: false,
|
|
612
|
+
default: void 0
|
|
613
|
+
},
|
|
614
|
+
split: {
|
|
615
|
+
type: String,
|
|
616
|
+
required: false,
|
|
617
|
+
default: void 0
|
|
618
|
+
},
|
|
619
|
+
transitionName: {
|
|
620
|
+
type: String,
|
|
621
|
+
required: false,
|
|
622
|
+
default: void 0
|
|
623
|
+
},
|
|
624
|
+
placement: {
|
|
625
|
+
type: String,
|
|
626
|
+
required: false,
|
|
627
|
+
default: void 0
|
|
628
|
+
},
|
|
629
|
+
direction: {
|
|
630
|
+
type: String,
|
|
631
|
+
required: false,
|
|
632
|
+
default: void 0
|
|
633
|
+
},
|
|
634
|
+
prefix: {
|
|
635
|
+
type: [String, Array],
|
|
636
|
+
required: false,
|
|
637
|
+
default: void 0
|
|
638
|
+
},
|
|
639
|
+
prefixCls: {
|
|
640
|
+
type: String,
|
|
641
|
+
required: false,
|
|
642
|
+
default: void 0
|
|
643
|
+
},
|
|
644
|
+
value: {
|
|
645
|
+
type: String,
|
|
646
|
+
required: false,
|
|
647
|
+
default: void 0
|
|
648
|
+
},
|
|
649
|
+
silent: {
|
|
650
|
+
type: Boolean,
|
|
651
|
+
required: false,
|
|
652
|
+
default: void 0
|
|
653
|
+
},
|
|
654
|
+
filterOption: {
|
|
655
|
+
type: Boolean,
|
|
656
|
+
required: false,
|
|
657
|
+
skipCheck: true,
|
|
658
|
+
default: void 0
|
|
659
|
+
},
|
|
660
|
+
validateSearch: {
|
|
661
|
+
required: false,
|
|
662
|
+
default: void 0
|
|
663
|
+
},
|
|
664
|
+
onChange: {
|
|
665
|
+
type: Function,
|
|
666
|
+
required: false,
|
|
667
|
+
default: void 0
|
|
668
|
+
},
|
|
669
|
+
onSelect: {
|
|
670
|
+
type: Function,
|
|
671
|
+
required: false,
|
|
672
|
+
default: void 0
|
|
673
|
+
},
|
|
674
|
+
onSearch: {
|
|
675
|
+
type: Function,
|
|
676
|
+
required: false,
|
|
677
|
+
default: void 0
|
|
678
|
+
},
|
|
679
|
+
onFocus: {
|
|
680
|
+
type: Function,
|
|
681
|
+
required: false,
|
|
682
|
+
default: void 0
|
|
683
|
+
},
|
|
684
|
+
onBlur: {
|
|
685
|
+
type: Function,
|
|
686
|
+
required: false,
|
|
687
|
+
default: void 0
|
|
688
|
+
},
|
|
689
|
+
getPopupContainer: {
|
|
690
|
+
type: Function,
|
|
691
|
+
required: false,
|
|
692
|
+
default: void 0
|
|
693
|
+
},
|
|
694
|
+
popupClassName: {
|
|
695
|
+
type: String,
|
|
696
|
+
required: false,
|
|
697
|
+
default: void 0
|
|
698
|
+
},
|
|
699
|
+
options: {
|
|
700
|
+
type: Array,
|
|
701
|
+
required: false,
|
|
702
|
+
default: void 0
|
|
703
|
+
},
|
|
704
|
+
classNames: {
|
|
705
|
+
type: Object,
|
|
706
|
+
required: false,
|
|
707
|
+
default: void 0
|
|
708
|
+
},
|
|
709
|
+
styles: {
|
|
710
|
+
type: Object,
|
|
711
|
+
required: false,
|
|
712
|
+
default: void 0
|
|
713
|
+
},
|
|
714
|
+
onPopupScroll: {
|
|
715
|
+
type: Function,
|
|
716
|
+
required: false,
|
|
717
|
+
default: void 0
|
|
718
|
+
},
|
|
719
|
+
rows: {
|
|
720
|
+
required: false,
|
|
721
|
+
default: void 0
|
|
722
|
+
},
|
|
723
|
+
disabled: {
|
|
724
|
+
type: Boolean,
|
|
725
|
+
required: false,
|
|
726
|
+
default: void 0
|
|
727
|
+
},
|
|
728
|
+
autoSize: {
|
|
729
|
+
type: [Boolean, Object],
|
|
730
|
+
required: false,
|
|
731
|
+
default: void 0
|
|
732
|
+
},
|
|
733
|
+
onPressEnter: {
|
|
734
|
+
type: Function,
|
|
735
|
+
required: false,
|
|
736
|
+
default: void 0
|
|
737
|
+
},
|
|
738
|
+
onResize: {
|
|
739
|
+
type: Function,
|
|
740
|
+
required: false,
|
|
741
|
+
default: void 0
|
|
742
|
+
},
|
|
743
|
+
allowClear: {
|
|
744
|
+
type: [Boolean, Object],
|
|
745
|
+
required: false,
|
|
746
|
+
default: void 0
|
|
747
|
+
},
|
|
748
|
+
suffix: {
|
|
749
|
+
required: false,
|
|
750
|
+
default: void 0
|
|
751
|
+
},
|
|
752
|
+
count: {
|
|
753
|
+
required: false,
|
|
754
|
+
default: void 0
|
|
755
|
+
},
|
|
756
|
+
onClear: {
|
|
757
|
+
type: Function,
|
|
758
|
+
required: false,
|
|
759
|
+
default: void 0
|
|
760
|
+
},
|
|
761
|
+
maxLength: {
|
|
762
|
+
type: Number,
|
|
763
|
+
required: false,
|
|
764
|
+
default: void 0
|
|
765
|
+
},
|
|
766
|
+
hidden: {
|
|
767
|
+
type: Boolean,
|
|
768
|
+
required: false,
|
|
769
|
+
default: void 0
|
|
770
|
+
},
|
|
771
|
+
readOnly: {
|
|
772
|
+
type: Boolean,
|
|
773
|
+
required: false,
|
|
774
|
+
default: void 0
|
|
775
|
+
},
|
|
776
|
+
placeholder: {
|
|
777
|
+
type: String,
|
|
778
|
+
required: false,
|
|
779
|
+
default: void 0
|
|
780
|
+
},
|
|
781
|
+
onKeydown: {
|
|
782
|
+
type: Function,
|
|
783
|
+
required: false,
|
|
784
|
+
default: void 0
|
|
785
|
+
},
|
|
786
|
+
onKeyup: {
|
|
787
|
+
type: Function,
|
|
788
|
+
required: false,
|
|
789
|
+
default: void 0
|
|
790
|
+
}
|
|
791
|
+
},
|
|
792
|
+
name: "Mentions",
|
|
793
|
+
inheritAttrs: false
|
|
794
|
+
});
|
|
795
|
+
export { Mentions_default as default };
|