@v-c/mentions 1.0.0 → 1.1.0-rc.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/dist/DropdownMenu.js +11 -7
- package/dist/KeywordTrigger.js +7 -6
- package/dist/Mentions.js +79 -20
- package/dist/MentionsContext.js +3 -1
- package/dist/Option.js +3 -2
- package/dist/context.js +2 -0
- package/dist/hooks/useEffectState.js +5 -0
- package/dist/index.js +6 -4
- package/dist/util.js +18 -0
- package/package.json +7 -7
- package/dist/DropdownMenu.cjs +0 -124
- package/dist/KeywordTrigger.cjs +0 -130
- package/dist/Mentions.cjs +0 -802
- package/dist/MentionsContext.cjs +0 -19
- package/dist/Option.cjs +0 -7
- package/dist/_virtual/rolldown_runtime.cjs +0 -21
- package/dist/context.cjs +0 -12
- package/dist/hooks/useEffectState.cjs +0 -23
- package/dist/index.cjs +0 -12
- package/dist/util.cjs +0 -65
package/dist/DropdownMenu.js
CHANGED
|
@@ -2,10 +2,15 @@ import { useMentionsContext } from "./MentionsContext.js";
|
|
|
2
2
|
import { computed, createVNode, defineComponent, isVNode, mergeProps, nextTick, onBeforeUnmount, shallowRef, watch } from "vue";
|
|
3
3
|
import Menu, { Item } from "@v-c/menu";
|
|
4
4
|
import { getDOM } from "@v-c/util/dist/Dom/findDOMNode";
|
|
5
|
+
//#region src/DropdownMenu.tsx
|
|
5
6
|
function _isSlot(s) {
|
|
6
7
|
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* We only use Menu to display the candidate.
|
|
11
|
+
* The focus is controlled by textarea to make accessibility easy.
|
|
12
|
+
*/
|
|
13
|
+
var DropdownMenu = /* @__PURE__ */ defineComponent((props) => {
|
|
9
14
|
const mentionsContext = useMentionsContext();
|
|
10
15
|
const menuRef = shallowRef();
|
|
11
16
|
const activeIndex = computed(() => mentionsContext.value.activeIndex);
|
|
@@ -86,7 +91,7 @@ var DropdownMenu_default = /* @__PURE__ */ defineComponent((props) => {
|
|
|
86
91
|
"class": className,
|
|
87
92
|
"style": style
|
|
88
93
|
}, { onMouseenter: () => {
|
|
89
|
-
setActiveIndex(index);
|
|
94
|
+
if (!disabled) setActiveIndex(index);
|
|
90
95
|
} }), _isSlot(label) ? label : { default: () => [label] });
|
|
91
96
|
}), !options.length && createVNode(Item, {
|
|
92
97
|
"disabled": true,
|
|
@@ -102,16 +107,15 @@ var DropdownMenu_default = /* @__PURE__ */ defineComponent((props) => {
|
|
|
102
107
|
},
|
|
103
108
|
options: {
|
|
104
109
|
type: Array,
|
|
105
|
-
required: true
|
|
106
|
-
default: void 0
|
|
110
|
+
required: true
|
|
107
111
|
},
|
|
108
112
|
opened: {
|
|
109
113
|
type: Boolean,
|
|
110
|
-
required: true
|
|
111
|
-
default: void 0
|
|
114
|
+
required: true
|
|
112
115
|
}
|
|
113
116
|
},
|
|
114
117
|
name: "DropdownMenu",
|
|
115
118
|
inheritAttrs: false
|
|
116
119
|
});
|
|
117
|
-
|
|
120
|
+
//#endregion
|
|
121
|
+
export { DropdownMenu as default };
|
package/dist/KeywordTrigger.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import DropdownMenu from "./DropdownMenu.js";
|
|
2
2
|
import { computed, createVNode, defineComponent, shallowRef } from "vue";
|
|
3
3
|
import Trigger from "@v-c/trigger";
|
|
4
|
+
//#region src/KeywordTrigger.tsx
|
|
4
5
|
var BUILT_IN_PLACEMENTS = {
|
|
5
6
|
bottomRight: {
|
|
6
7
|
points: ["tl", "br"],
|
|
@@ -35,7 +36,7 @@ var BUILT_IN_PLACEMENTS = {
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
};
|
|
38
|
-
var
|
|
39
|
+
var KeywordTrigger = /* @__PURE__ */ defineComponent((props, { slots }) => {
|
|
39
40
|
const opened = shallowRef(false);
|
|
40
41
|
const dropdownPlacement = computed(() => {
|
|
41
42
|
if (props.direction === "rtl") return props.placement === "top" ? "topLeft" : "bottomLeft";
|
|
@@ -44,7 +45,7 @@ var KeywordTrigger_default = /* @__PURE__ */ defineComponent((props, { slots })
|
|
|
44
45
|
return () => {
|
|
45
46
|
const { prefixCls, options, visible, transitionName, getPopupContainer, popupClassName, popupStyle } = props;
|
|
46
47
|
const dropdownPrefix = `${prefixCls}-dropdown`;
|
|
47
|
-
const dropdownElement = createVNode(
|
|
48
|
+
const dropdownElement = createVNode(DropdownMenu, {
|
|
48
49
|
"prefixCls": dropdownPrefix,
|
|
49
50
|
"options": options,
|
|
50
51
|
"opened": opened.value
|
|
@@ -73,8 +74,7 @@ var KeywordTrigger_default = /* @__PURE__ */ defineComponent((props, { slots })
|
|
|
73
74
|
},
|
|
74
75
|
options: {
|
|
75
76
|
type: Array,
|
|
76
|
-
required: true
|
|
77
|
-
default: void 0
|
|
77
|
+
required: true
|
|
78
78
|
},
|
|
79
79
|
prefixCls: {
|
|
80
80
|
type: String,
|
|
@@ -120,4 +120,5 @@ var KeywordTrigger_default = /* @__PURE__ */ defineComponent((props, { slots })
|
|
|
120
120
|
name: "KeywordTrigger",
|
|
121
121
|
inheritAttrs: false
|
|
122
122
|
});
|
|
123
|
-
|
|
123
|
+
//#endregion
|
|
124
|
+
export { KeywordTrigger as default };
|
package/dist/Mentions.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MentionsProvider } from "./MentionsContext.js";
|
|
2
|
-
import
|
|
2
|
+
import KeywordTrigger from "./KeywordTrigger.js";
|
|
3
3
|
import { useUnstableContext } from "./context.js";
|
|
4
4
|
import useEffectState from "./hooks/useEffectState.js";
|
|
5
5
|
import { filterOption, getBeforeSelectionText, getLastMeasureIndex, replaceWithMeasure, setInputSelection, validateSearch } from "./util.js";
|
|
@@ -9,6 +9,7 @@ import TextArea from "@v-c/textarea";
|
|
|
9
9
|
import { KeyCode, clsx, omit, useId } from "@v-c/util";
|
|
10
10
|
import { toArray } from "@v-c/util/dist/Children/toArray";
|
|
11
11
|
import { filterEmpty, getAttrStyleAndClass } from "@v-c/util/dist/props-util";
|
|
12
|
+
//#region src/Mentions.tsx
|
|
12
13
|
var omitKeys = [
|
|
13
14
|
"prefixCls",
|
|
14
15
|
"className",
|
|
@@ -45,15 +46,6 @@ var omitKeys = [
|
|
|
45
46
|
"visible",
|
|
46
47
|
"onPopupScroll"
|
|
47
48
|
];
|
|
48
|
-
var defaults = {
|
|
49
|
-
prefix: "@",
|
|
50
|
-
prefixCls: "vc-mentions",
|
|
51
|
-
split: " ",
|
|
52
|
-
notFoundContent: "Not Found",
|
|
53
|
-
validateSearch,
|
|
54
|
-
filterOption,
|
|
55
|
-
rows: 1
|
|
56
|
-
};
|
|
57
49
|
var InternalMentions = /* @__PURE__ */ defineComponent((props, { slots, expose, attrs }) => {
|
|
58
50
|
const mergedPrefix = computed(() => {
|
|
59
51
|
const prefix = props.prefix;
|
|
@@ -128,19 +120,37 @@ var InternalMentions = /* @__PURE__ */ defineComponent((props, { slots, expose,
|
|
|
128
120
|
key: `${key || optionProps.value}-${uniqueKey}`
|
|
129
121
|
}));
|
|
130
122
|
return list.filter((option) => {
|
|
123
|
+
/** Return all result if `filterOption` is false. */
|
|
131
124
|
if (filterOption$1 === false) return true;
|
|
132
125
|
if (typeof filterOption$1 !== "function") return true;
|
|
133
126
|
return filterOption$1(targetMeasureText, option);
|
|
134
127
|
});
|
|
135
128
|
};
|
|
136
129
|
const mergedOptions = computed(() => getOptions(mergedMeasureText.value));
|
|
130
|
+
const getEnabledActiveIndex = (index, offset = 1) => {
|
|
131
|
+
const optionLen = mergedOptions.value.length;
|
|
132
|
+
if (optionLen === 0) return -1;
|
|
133
|
+
for (let i = 0; i < optionLen; i += 1) {
|
|
134
|
+
const current = (index + i * offset + optionLen) % optionLen;
|
|
135
|
+
if (!mergedOptions.value[current]?.disabled) return current;
|
|
136
|
+
}
|
|
137
|
+
return -1;
|
|
138
|
+
};
|
|
139
|
+
watch([mergedMeasuring, mergedOptions], () => {
|
|
140
|
+
if (!mergedMeasuring.value) return;
|
|
141
|
+
const current = mergedOptions.value[activeIndex.value];
|
|
142
|
+
if (!current || current.disabled) {
|
|
143
|
+
const next = getEnabledActiveIndex(0);
|
|
144
|
+
if (next !== activeIndex.value) activeIndex.value = next;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
137
147
|
const onSelectionEffect = useEffectState();
|
|
138
148
|
const startMeasure = (nextMeasureText, nextMeasurePrefix, nextMeasureLocation) => {
|
|
139
149
|
measuring.value = true;
|
|
140
150
|
measureText.value = nextMeasureText;
|
|
141
151
|
measurePrefix.value = nextMeasurePrefix;
|
|
142
152
|
measureLocation.value = nextMeasureLocation;
|
|
143
|
-
activeIndex.value = 0;
|
|
153
|
+
activeIndex.value = getEnabledActiveIndex(0);
|
|
144
154
|
};
|
|
145
155
|
const stopMeasure = (callback) => {
|
|
146
156
|
measuring.value = false;
|
|
@@ -157,6 +167,7 @@ var InternalMentions = /* @__PURE__ */ defineComponent((props, { slots, expose,
|
|
|
157
167
|
triggerChange(nextValue);
|
|
158
168
|
};
|
|
159
169
|
const selectOption = (option) => {
|
|
170
|
+
if (!option || option.disabled) return;
|
|
160
171
|
const { value: mentionValue = "" } = option;
|
|
161
172
|
const textArea = getTextArea();
|
|
162
173
|
const { text, selectionLocation } = replaceWithMeasure(mergedValue.value, {
|
|
@@ -177,9 +188,13 @@ var InternalMentions = /* @__PURE__ */ defineComponent((props, { slots, expose,
|
|
|
177
188
|
props?.onKeydown?.(event);
|
|
178
189
|
if (!mergedMeasuring.value) return;
|
|
179
190
|
if (which === KeyCode.UP || which === KeyCode.DOWN) {
|
|
180
|
-
|
|
191
|
+
if (mergedOptions.value.length === 0) {
|
|
192
|
+
event.preventDefault();
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
181
195
|
const offset = which === KeyCode.UP ? -1 : 1;
|
|
182
|
-
|
|
196
|
+
const nextIndex = getEnabledActiveIndex(activeIndex.value + offset, offset);
|
|
197
|
+
if (nextIndex !== -1) activeIndex.value = nextIndex;
|
|
183
198
|
event.preventDefault();
|
|
184
199
|
} else if (which === KeyCode.ESC) stopMeasure();
|
|
185
200
|
else if (which === KeyCode.ENTER) {
|
|
@@ -189,10 +204,32 @@ var InternalMentions = /* @__PURE__ */ defineComponent((props, { slots, expose,
|
|
|
189
204
|
stopMeasure();
|
|
190
205
|
return;
|
|
191
206
|
}
|
|
192
|
-
|
|
207
|
+
let currentIndex = activeIndex.value;
|
|
208
|
+
let option = mergedOptions.value[currentIndex];
|
|
209
|
+
if (!option || option.disabled) {
|
|
210
|
+
currentIndex = getEnabledActiveIndex(0);
|
|
211
|
+
if (currentIndex === -1) {
|
|
212
|
+
stopMeasure();
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
activeIndex.value = currentIndex;
|
|
216
|
+
option = mergedOptions.value[currentIndex];
|
|
217
|
+
}
|
|
193
218
|
selectOption(option);
|
|
194
219
|
}
|
|
195
220
|
};
|
|
221
|
+
/**
|
|
222
|
+
* When to start measure:
|
|
223
|
+
* 1. When user press `prefix`
|
|
224
|
+
* 2. When measureText !== prevMeasureText
|
|
225
|
+
* - If measure hit
|
|
226
|
+
* - If measuring
|
|
227
|
+
*
|
|
228
|
+
* When to stop measure:
|
|
229
|
+
* 1. Selection is out of range
|
|
230
|
+
* 2. Contains `space`
|
|
231
|
+
* 3. ESC or select one
|
|
232
|
+
*/
|
|
196
233
|
const onInternalKeyUp = (event) => {
|
|
197
234
|
const { key, which } = event;
|
|
198
235
|
const target = event.target;
|
|
@@ -212,6 +249,10 @@ var InternalMentions = /* @__PURE__ */ defineComponent((props, { slots, expose,
|
|
|
212
249
|
if (validateMeasure) {
|
|
213
250
|
if (key === nextMeasurePrefix || key === "Shift" || which === KeyCode.ALT || key === "AltGraph" || mergedMeasuring.value || nextMeasureText !== mergedMeasureText.value && matchOption) startMeasure(nextMeasureText, nextMeasurePrefix, measureIndex);
|
|
214
251
|
} else if (mergedMeasuring.value) stopMeasure();
|
|
252
|
+
/**
|
|
253
|
+
* We will trigger `onSearch` to developer since they may use for async update.
|
|
254
|
+
* If met `space` means user finished searching.
|
|
255
|
+
*/
|
|
215
256
|
const onSearch = props?.onSearch;
|
|
216
257
|
if (onSearch && validateMeasure) onSearch(nextMeasureText, nextMeasurePrefix);
|
|
217
258
|
} else if (mergedMeasuring.value) stopMeasure();
|
|
@@ -279,7 +320,7 @@ var InternalMentions = /* @__PURE__ */ defineComponent((props, { slots, expose,
|
|
|
279
320
|
onFocus: onDropdownFocus,
|
|
280
321
|
onBlur: onDropdownBlur,
|
|
281
322
|
onScroll: onInternalPopupScroll
|
|
282
|
-
} }, { default: () => [createVNode(
|
|
323
|
+
} }, { default: () => [createVNode(KeywordTrigger, {
|
|
283
324
|
"prefixCls": prefixCls,
|
|
284
325
|
"transitionName": props.transitionName,
|
|
285
326
|
"placement": props.placement,
|
|
@@ -303,8 +344,7 @@ var InternalMentions = /* @__PURE__ */ defineComponent((props, { slots, expose,
|
|
|
303
344
|
props: /* @__PURE__ */ mergeDefaults({
|
|
304
345
|
hasWrapper: {
|
|
305
346
|
type: Boolean,
|
|
306
|
-
required: true
|
|
307
|
-
default: void 0
|
|
347
|
+
required: true
|
|
308
348
|
},
|
|
309
349
|
id: {
|
|
310
350
|
type: String,
|
|
@@ -515,12 +555,25 @@ var InternalMentions = /* @__PURE__ */ defineComponent((props, { slots, expose,
|
|
|
515
555
|
type: Function,
|
|
516
556
|
required: false,
|
|
517
557
|
default: void 0
|
|
558
|
+
},
|
|
559
|
+
changeOnComposing: {
|
|
560
|
+
type: Boolean,
|
|
561
|
+
required: false,
|
|
562
|
+
default: void 0
|
|
518
563
|
}
|
|
519
|
-
},
|
|
564
|
+
}, {
|
|
565
|
+
prefix: "@",
|
|
566
|
+
prefixCls: "vc-mentions",
|
|
567
|
+
split: " ",
|
|
568
|
+
notFoundContent: "Not Found",
|
|
569
|
+
validateSearch,
|
|
570
|
+
filterOption,
|
|
571
|
+
rows: 1
|
|
572
|
+
}),
|
|
520
573
|
name: "VMentions",
|
|
521
574
|
inheritAttrs: false
|
|
522
575
|
});
|
|
523
|
-
var
|
|
576
|
+
var Mentions = /* @__PURE__ */ defineComponent((props, { expose, attrs }) => {
|
|
524
577
|
const hasSuffix = computed(() => !!(props.suffix || props.allowClear));
|
|
525
578
|
const holderRef = shallowRef();
|
|
526
579
|
const mentionRef = shallowRef();
|
|
@@ -787,9 +840,15 @@ var Mentions_default = /* @__PURE__ */ defineComponent((props, { expose, attrs }
|
|
|
787
840
|
type: Function,
|
|
788
841
|
required: false,
|
|
789
842
|
default: void 0
|
|
843
|
+
},
|
|
844
|
+
changeOnComposing: {
|
|
845
|
+
type: Boolean,
|
|
846
|
+
required: false,
|
|
847
|
+
default: void 0
|
|
790
848
|
}
|
|
791
849
|
},
|
|
792
850
|
name: "Mentions",
|
|
793
851
|
inheritAttrs: false
|
|
794
852
|
});
|
|
795
|
-
|
|
853
|
+
//#endregion
|
|
854
|
+
export { Mentions as default };
|
package/dist/MentionsContext.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { computed, defineComponent, inject, provide, ref } from "vue";
|
|
2
|
+
//#region src/MentionsContext.ts
|
|
2
3
|
var MentionsContextKey = Symbol("MentionsContext");
|
|
3
4
|
function useMentionsContext() {
|
|
4
5
|
return inject(MentionsContextKey, ref());
|
|
5
6
|
}
|
|
6
|
-
|
|
7
|
+
var MentionsProvider = defineComponent((props, { slots }) => {
|
|
7
8
|
provide(MentionsContextKey, computed(() => props.value));
|
|
8
9
|
return () => {
|
|
9
10
|
return slots?.default?.();
|
|
@@ -13,4 +14,5 @@ const MentionsProvider = defineComponent((props, { slots }) => {
|
|
|
13
14
|
inheritAttrs: false,
|
|
14
15
|
props: ["value"]
|
|
15
16
|
});
|
|
17
|
+
//#endregion
|
|
16
18
|
export { MentionsProvider, useMentionsContext };
|
package/dist/Option.js
CHANGED
package/dist/context.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { inject, provide } from "vue";
|
|
2
|
+
//#region src/context.ts
|
|
2
3
|
var UnstableContextKey = Symbol("UnstableContext");
|
|
3
4
|
function useUnstableContext() {
|
|
4
5
|
return inject(UnstableContextKey, {});
|
|
@@ -6,4 +7,5 @@ function useUnstableContext() {
|
|
|
6
7
|
function useUnstableContextProvider(value) {
|
|
7
8
|
provide(UnstableContextKey, value);
|
|
8
9
|
}
|
|
10
|
+
//#endregion
|
|
9
11
|
export { useUnstableContext, useUnstableContextProvider };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { shallowRef, watch } from "vue";
|
|
2
|
+
//#region src/hooks/useEffectState.ts
|
|
3
|
+
/**
|
|
4
|
+
* Trigger a callback on state change
|
|
5
|
+
*/
|
|
2
6
|
function useEffectState() {
|
|
3
7
|
const effectId = shallowRef({
|
|
4
8
|
id: 0,
|
|
@@ -15,4 +19,5 @@ function useEffectState() {
|
|
|
15
19
|
});
|
|
16
20
|
return update;
|
|
17
21
|
}
|
|
22
|
+
//#endregion
|
|
18
23
|
export { useEffectState as default };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useUnstableContext, useUnstableContextProvider } from "./context.js";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import Mentions from "./Mentions.js";
|
|
3
|
+
import Option from "./Option.js";
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
var src_default = Mentions;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { Option, src_default as default, useUnstableContext, useUnstableContextProvider };
|
package/dist/util.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
//#region src/util.ts
|
|
2
|
+
/**
|
|
3
|
+
* Cut input selection into 2 part and return text before selection start
|
|
4
|
+
*/
|
|
1
5
|
function getBeforeSelectionText(input) {
|
|
2
6
|
const { selectionStart } = input;
|
|
3
7
|
return input.value.slice(0, selectionStart);
|
|
4
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Find the last match prefix index
|
|
11
|
+
*/
|
|
5
12
|
function getLastMeasureIndex(text, prefix) {
|
|
6
13
|
return prefix.reduce((lastMatch, prefixStr) => {
|
|
7
14
|
const lastIndex = text.lastIndexOf(prefixStr);
|
|
@@ -29,6 +36,12 @@ function reduceText(text, targetText, split) {
|
|
|
29
36
|
} else if (i === targetTextLen - 1) restText = restText.slice(targetTextLen);
|
|
30
37
|
return restText;
|
|
31
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Paint targetText into current text:
|
|
41
|
+
* text: little@litest
|
|
42
|
+
* targetText: light
|
|
43
|
+
* => little @light test
|
|
44
|
+
*/
|
|
32
45
|
function replaceWithMeasure(text, measureConfig) {
|
|
33
46
|
const { measureLocation, prefix, targetText, selectionStart, split } = measureConfig;
|
|
34
47
|
let beforeMeasureText = text.slice(0, measureLocation);
|
|
@@ -44,6 +57,10 @@ function replaceWithMeasure(text, measureConfig) {
|
|
|
44
57
|
}
|
|
45
58
|
function setInputSelection(input, location) {
|
|
46
59
|
input.setSelectionRange(location, location);
|
|
60
|
+
/**
|
|
61
|
+
* Reset caret into view.
|
|
62
|
+
* Since this function always called by user control, it's safe to focus element.
|
|
63
|
+
*/
|
|
47
64
|
input.blur();
|
|
48
65
|
input.focus();
|
|
49
66
|
}
|
|
@@ -56,4 +73,5 @@ function filterOption(input, option) {
|
|
|
56
73
|
const lowerCase = (typeof input === "string" ? input : String(input ?? "")).toLowerCase();
|
|
57
74
|
return (option?.value ?? "").toLowerCase().includes(lowerCase);
|
|
58
75
|
}
|
|
76
|
+
//#endregion
|
|
59
77
|
export { filterOption, getBeforeSelectionText, getLastMeasureIndex, replaceWithMeasure, setInputSelection, validateSearch };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@v-c/mentions",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.1.0-rc.1",
|
|
5
5
|
"description": "",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"import": "./dist/index.js",
|
|
13
|
-
"
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
14
|
},
|
|
15
15
|
"./dist/*": "./dist/*",
|
|
16
16
|
"./package.json": "./package.json"
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
"vue": "^3.0.0"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@v-c/input": "^1.0.
|
|
28
|
-
"@v-c/
|
|
29
|
-
"@v-c/
|
|
30
|
-
"@v-c/
|
|
31
|
-
"@v-c/util": "^1.0.
|
|
27
|
+
"@v-c/input": "^1.1.0-rc.1",
|
|
28
|
+
"@v-c/menu": "^1.1.0-rc.1",
|
|
29
|
+
"@v-c/textarea": "^1.1.0-rc.1",
|
|
30
|
+
"@v-c/trigger": "^1.0.14",
|
|
31
|
+
"@v-c/util": "^1.0.19"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "vite build",
|
package/dist/DropdownMenu.cjs
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
6
|
-
const require_MentionsContext = require("./MentionsContext.cjs");
|
|
7
|
-
let vue = require("vue");
|
|
8
|
-
let _v_c_menu = require("@v-c/menu");
|
|
9
|
-
_v_c_menu = require_rolldown_runtime.__toESM(_v_c_menu);
|
|
10
|
-
let _v_c_util_dist_Dom_findDOMNode = require("@v-c/util/dist/Dom/findDOMNode");
|
|
11
|
-
function _isSlot(s) {
|
|
12
|
-
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !(0, vue.isVNode)(s);
|
|
13
|
-
}
|
|
14
|
-
var DropdownMenu = /* @__PURE__ */ (0, vue.defineComponent)((props) => {
|
|
15
|
-
const mentionsContext = require_MentionsContext.useMentionsContext();
|
|
16
|
-
const menuRef = (0, vue.shallowRef)();
|
|
17
|
-
const activeIndex = (0, vue.computed)(() => mentionsContext.value.activeIndex);
|
|
18
|
-
const activeOption = (0, vue.computed)(() => props.options[activeIndex.value] || {});
|
|
19
|
-
const activeOptionKey = (0, vue.computed)(() => activeOption.value?.key);
|
|
20
|
-
let removeListListeners;
|
|
21
|
-
const bindListEvents = (list) => {
|
|
22
|
-
if (removeListListeners) {
|
|
23
|
-
removeListListeners();
|
|
24
|
-
removeListListeners = void 0;
|
|
25
|
-
}
|
|
26
|
-
if (!list) return;
|
|
27
|
-
const handleFocus = (event) => {
|
|
28
|
-
mentionsContext.value.onFocus?.(event);
|
|
29
|
-
};
|
|
30
|
-
const handleBlur = (event) => {
|
|
31
|
-
mentionsContext.value.onBlur?.(event);
|
|
32
|
-
};
|
|
33
|
-
const handleScroll = (event) => {
|
|
34
|
-
mentionsContext.value.onScroll?.(event);
|
|
35
|
-
};
|
|
36
|
-
list.addEventListener("focusin", handleFocus);
|
|
37
|
-
list.addEventListener("focusout", handleBlur);
|
|
38
|
-
list.addEventListener("scroll", handleScroll);
|
|
39
|
-
removeListListeners = () => {
|
|
40
|
-
list.removeEventListener("focusin", handleFocus);
|
|
41
|
-
list.removeEventListener("focusout", handleBlur);
|
|
42
|
-
list.removeEventListener("scroll", handleScroll);
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
(0, vue.watch)(() => menuRef.value?.list, (list, _, onCleanup) => {
|
|
46
|
-
if (list) list = (0, _v_c_util_dist_Dom_findDOMNode.getDOM)(list);
|
|
47
|
-
bindListEvents(list || null);
|
|
48
|
-
onCleanup(() => {
|
|
49
|
-
removeListListeners?.();
|
|
50
|
-
removeListListeners = void 0;
|
|
51
|
-
});
|
|
52
|
-
}, {
|
|
53
|
-
immediate: true,
|
|
54
|
-
flush: "post"
|
|
55
|
-
});
|
|
56
|
-
(0, vue.watch)([
|
|
57
|
-
activeIndex,
|
|
58
|
-
activeOptionKey,
|
|
59
|
-
() => props.opened
|
|
60
|
-
], () => {
|
|
61
|
-
if (!props.opened || activeIndex.value === -1) return;
|
|
62
|
-
(0, vue.nextTick)(() => {
|
|
63
|
-
const key = activeOptionKey.value;
|
|
64
|
-
if (!key) return;
|
|
65
|
-
(menuRef.value?.findItem?.({ key }))?.scrollIntoView({
|
|
66
|
-
block: "nearest",
|
|
67
|
-
inline: "nearest"
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
(0, vue.onBeforeUnmount)(() => {
|
|
72
|
-
removeListListeners?.();
|
|
73
|
-
removeListListeners = void 0;
|
|
74
|
-
});
|
|
75
|
-
return () => {
|
|
76
|
-
const { notFoundContent, setActiveIndex, selectOption } = mentionsContext.value;
|
|
77
|
-
const { prefixCls, options } = props;
|
|
78
|
-
const activeKey = activeOptionKey.value;
|
|
79
|
-
return (0, vue.createVNode)(_v_c_menu.default, {
|
|
80
|
-
"ref": menuRef,
|
|
81
|
-
"prefixCls": `${prefixCls}-menu`,
|
|
82
|
-
"activeKey": activeKey,
|
|
83
|
-
"onSelect": ({ key }) => {
|
|
84
|
-
const option = options.find(({ key: optionKey }) => optionKey === key);
|
|
85
|
-
if (option) selectOption(option);
|
|
86
|
-
}
|
|
87
|
-
}, { default: () => [options.map((option, index) => {
|
|
88
|
-
const { key, disabled, class: className, style, label } = option;
|
|
89
|
-
return (0, vue.createVNode)(_v_c_menu.Item, (0, vue.mergeProps)({
|
|
90
|
-
"key": key,
|
|
91
|
-
"disabled": disabled,
|
|
92
|
-
"class": className,
|
|
93
|
-
"style": style
|
|
94
|
-
}, { onMouseenter: () => {
|
|
95
|
-
setActiveIndex(index);
|
|
96
|
-
} }), _isSlot(label) ? label : { default: () => [label] });
|
|
97
|
-
}), !options.length && (0, vue.createVNode)(_v_c_menu.Item, {
|
|
98
|
-
"disabled": true,
|
|
99
|
-
"key": "notFound"
|
|
100
|
-
}, _isSlot(notFoundContent) ? notFoundContent : { default: () => [notFoundContent] })] });
|
|
101
|
-
};
|
|
102
|
-
}, {
|
|
103
|
-
props: {
|
|
104
|
-
prefixCls: {
|
|
105
|
-
type: String,
|
|
106
|
-
required: false,
|
|
107
|
-
default: void 0
|
|
108
|
-
},
|
|
109
|
-
options: {
|
|
110
|
-
type: Array,
|
|
111
|
-
required: true,
|
|
112
|
-
default: void 0
|
|
113
|
-
},
|
|
114
|
-
opened: {
|
|
115
|
-
type: Boolean,
|
|
116
|
-
required: true,
|
|
117
|
-
default: void 0
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
name: "DropdownMenu",
|
|
121
|
-
inheritAttrs: false
|
|
122
|
-
});
|
|
123
|
-
var DropdownMenu_default = DropdownMenu;
|
|
124
|
-
exports.default = DropdownMenu_default;
|
package/dist/KeywordTrigger.cjs
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
6
|
-
const require_DropdownMenu = require("./DropdownMenu.cjs");
|
|
7
|
-
let vue = require("vue");
|
|
8
|
-
let _v_c_trigger = require("@v-c/trigger");
|
|
9
|
-
_v_c_trigger = require_rolldown_runtime.__toESM(_v_c_trigger);
|
|
10
|
-
var BUILT_IN_PLACEMENTS = {
|
|
11
|
-
bottomRight: {
|
|
12
|
-
points: ["tl", "br"],
|
|
13
|
-
offset: [0, 4],
|
|
14
|
-
overflow: {
|
|
15
|
-
adjustX: 1,
|
|
16
|
-
adjustY: 1
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
bottomLeft: {
|
|
20
|
-
points: ["tr", "bl"],
|
|
21
|
-
offset: [0, 4],
|
|
22
|
-
overflow: {
|
|
23
|
-
adjustX: 1,
|
|
24
|
-
adjustY: 1
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
topRight: {
|
|
28
|
-
points: ["bl", "tr"],
|
|
29
|
-
offset: [0, -4],
|
|
30
|
-
overflow: {
|
|
31
|
-
adjustX: 1,
|
|
32
|
-
adjustY: 1
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
topLeft: {
|
|
36
|
-
points: ["br", "tl"],
|
|
37
|
-
offset: [0, -4],
|
|
38
|
-
overflow: {
|
|
39
|
-
adjustX: 1,
|
|
40
|
-
adjustY: 1
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
var KeywordTrigger = /* @__PURE__ */ (0, vue.defineComponent)((props, { slots }) => {
|
|
45
|
-
const opened = (0, vue.shallowRef)(false);
|
|
46
|
-
const dropdownPlacement = (0, vue.computed)(() => {
|
|
47
|
-
if (props.direction === "rtl") return props.placement === "top" ? "topLeft" : "bottomLeft";
|
|
48
|
-
return props.placement === "top" ? "topRight" : "bottomRight";
|
|
49
|
-
});
|
|
50
|
-
return () => {
|
|
51
|
-
const { prefixCls, options, visible, transitionName, getPopupContainer, popupClassName, popupStyle } = props;
|
|
52
|
-
const dropdownPrefix = `${prefixCls}-dropdown`;
|
|
53
|
-
const dropdownElement = (0, vue.createVNode)(require_DropdownMenu.default, {
|
|
54
|
-
"prefixCls": dropdownPrefix,
|
|
55
|
-
"options": options,
|
|
56
|
-
"opened": opened.value
|
|
57
|
-
}, null);
|
|
58
|
-
return (0, vue.createVNode)(_v_c_trigger.default, {
|
|
59
|
-
"prefixCls": dropdownPrefix,
|
|
60
|
-
"popupVisible": visible,
|
|
61
|
-
"popup": dropdownElement,
|
|
62
|
-
"popupPlacement": dropdownPlacement.value,
|
|
63
|
-
"popupMotion": { name: transitionName },
|
|
64
|
-
"builtinPlacements": BUILT_IN_PLACEMENTS,
|
|
65
|
-
"getPopupContainer": getPopupContainer,
|
|
66
|
-
"popupClassName": popupClassName,
|
|
67
|
-
"popupStyle": popupStyle,
|
|
68
|
-
"afterOpenChange": (nextOpen) => {
|
|
69
|
-
opened.value = nextOpen;
|
|
70
|
-
}
|
|
71
|
-
}, { default: () => [slots?.default?.()] });
|
|
72
|
-
};
|
|
73
|
-
}, {
|
|
74
|
-
props: {
|
|
75
|
-
loading: {
|
|
76
|
-
type: Boolean,
|
|
77
|
-
required: false,
|
|
78
|
-
default: void 0
|
|
79
|
-
},
|
|
80
|
-
options: {
|
|
81
|
-
type: Array,
|
|
82
|
-
required: true,
|
|
83
|
-
default: void 0
|
|
84
|
-
},
|
|
85
|
-
prefixCls: {
|
|
86
|
-
type: String,
|
|
87
|
-
required: false,
|
|
88
|
-
default: void 0
|
|
89
|
-
},
|
|
90
|
-
placement: {
|
|
91
|
-
type: String,
|
|
92
|
-
required: false,
|
|
93
|
-
default: void 0
|
|
94
|
-
},
|
|
95
|
-
direction: {
|
|
96
|
-
type: String,
|
|
97
|
-
required: false,
|
|
98
|
-
default: void 0
|
|
99
|
-
},
|
|
100
|
-
visible: {
|
|
101
|
-
type: Boolean,
|
|
102
|
-
required: false,
|
|
103
|
-
default: void 0
|
|
104
|
-
},
|
|
105
|
-
transitionName: {
|
|
106
|
-
type: String,
|
|
107
|
-
required: false,
|
|
108
|
-
default: void 0
|
|
109
|
-
},
|
|
110
|
-
getPopupContainer: {
|
|
111
|
-
type: Function,
|
|
112
|
-
required: false,
|
|
113
|
-
default: void 0
|
|
114
|
-
},
|
|
115
|
-
popupClassName: {
|
|
116
|
-
type: String,
|
|
117
|
-
required: false,
|
|
118
|
-
default: void 0
|
|
119
|
-
},
|
|
120
|
-
popupStyle: {
|
|
121
|
-
type: Object,
|
|
122
|
-
required: false,
|
|
123
|
-
default: void 0
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
name: "KeywordTrigger",
|
|
127
|
-
inheritAttrs: false
|
|
128
|
-
});
|
|
129
|
-
var KeywordTrigger_default = KeywordTrigger;
|
|
130
|
-
exports.default = KeywordTrigger_default;
|