vue-devui 1.3.4-alpha.4 → 1.4.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/editable-select/index.es.js +1242 -567
- package/editable-select/index.umd.js +1 -1
- package/editable-select/style.css +1 -1
- package/modal/index.es.js +10 -5
- package/modal/index.umd.js +1 -1
- package/nuxt/components/SELECT_KEY.js +3 -0
- package/package.json +1 -1
- package/search/index.es.js +1 -0
- package/search/index.umd.js +1 -1
- package/style.css +1 -1
- package/tabs/index.es.js +7 -5
- package/tabs/index.umd.js +1 -1
- package/types/editable-select/__tests__/{editable-select.spec.d.ts → basic-editable-select.spec.d.ts} +0 -0
- package/types/editable-select/__tests__/clearable-editable-select.spec.d.ts +1 -0
- package/types/editable-select/__tests__/custom-template-select.spec.d.ts +1 -0
- package/types/editable-select/__tests__/disabled-editable-select.spec.d.ts +1 -0
- package/types/editable-select/__tests__/event-editable-select.spec.d.ts +1 -0
- package/types/editable-select/__tests__/search-filter-select.spec.d.ts +1 -0
- package/types/editable-select/src/components/dropdown/dropdown-types.d.ts +15 -0
- package/types/editable-select/src/components/dropdown/dropdown.d.ts +2 -0
- package/types/editable-select/src/components/option/option-types.d.ts +18 -0
- package/types/editable-select/src/components/option/option.d.ts +37 -0
- package/types/editable-select/src/composables/use-input-event.d.ts +14 -0
- package/types/editable-select/src/composables/use-input-render.d.ts +12 -0
- package/types/editable-select/src/composables/use-keyboard-select.d.ts +6 -6
- package/types/editable-select/src/composables/use-lazy-load.d.ts +3 -2
- package/types/editable-select/src/composables/use-option.d.ts +7 -0
- package/types/editable-select/src/composables/use-select.d.ts +24 -4
- package/types/editable-select/src/editable-select-types.d.ts +53 -18
- package/types/editable-select/src/editable-select.d.ts +130 -1
- package/types/form/__tests__/form-item-input.spec.d.ts +1 -0
- package/types/select/src/select.d.ts +1 -1
- package/vue-devui.es.js +908 -423
- package/vue-devui.umd.js +14 -14
- package/types/editable-select/src/composables/use-cache-filtered-options.d.ts +0 -7
- package/types/editable-select/src/composables/use-filter-options.d.ts +0 -7
- package/types/editable-select/src/composables/use-input.d.ts +0 -6
- package/types/editable-select/src/utils/index.d.ts +0 -9
- package/types/form/__tests__/form-item.spec.d.ts +0 -0
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
2
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
3
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
4
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -16,109 +14,594 @@ var __spreadValues = (a, b) => {
|
|
|
16
14
|
}
|
|
17
15
|
return a;
|
|
18
16
|
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
17
|
var __publicField = (obj, key, value) => {
|
|
21
18
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
19
|
return value;
|
|
23
20
|
};
|
|
24
|
-
import { defineComponent,
|
|
21
|
+
import { defineComponent, toRefs, computed, createVNode, resolveDynamicComponent, mergeProps, watch, onUnmounted, Transition, ref, unref, nextTick, withModifiers, inject, h, render, withDirectives, resolveDirective, renderSlot, useSlots, reactive, getCurrentInstance, onMounted, provide, toRef, vShow, Teleport, isVNode } from "vue";
|
|
22
|
+
import { onClickOutside } from "@vueuse/core";
|
|
25
23
|
import { offset, autoPlacement, arrow, shift, computePosition } from "@floating-ui/dom";
|
|
26
24
|
const editableSelectProps = {
|
|
27
25
|
modelValue: {
|
|
26
|
+
type: [String, Number]
|
|
27
|
+
},
|
|
28
|
+
appendToBody: {
|
|
29
|
+
type: Boolean,
|
|
30
|
+
default: false
|
|
31
|
+
},
|
|
32
|
+
position: {
|
|
33
|
+
type: Array,
|
|
34
|
+
default: ["bottom"]
|
|
35
|
+
},
|
|
36
|
+
options: {
|
|
37
|
+
type: Array,
|
|
38
|
+
default: () => []
|
|
39
|
+
},
|
|
40
|
+
width: {
|
|
41
|
+
type: Number
|
|
42
|
+
},
|
|
43
|
+
maxHeight: {
|
|
44
|
+
type: Number
|
|
45
|
+
},
|
|
46
|
+
size: {
|
|
47
|
+
type: String
|
|
48
|
+
},
|
|
49
|
+
placeholder: {
|
|
50
|
+
type: String,
|
|
51
|
+
default: "Select"
|
|
52
|
+
},
|
|
53
|
+
loading: {
|
|
54
|
+
type: Boolean,
|
|
55
|
+
default: false
|
|
56
|
+
},
|
|
57
|
+
allowClear: {
|
|
58
|
+
type: Boolean,
|
|
59
|
+
default: false
|
|
60
|
+
},
|
|
61
|
+
disabled: {
|
|
62
|
+
type: Boolean,
|
|
63
|
+
default: false
|
|
64
|
+
},
|
|
65
|
+
disabledKey: {
|
|
28
66
|
type: String,
|
|
29
67
|
default: ""
|
|
30
68
|
},
|
|
69
|
+
remote: {
|
|
70
|
+
type: Boolean,
|
|
71
|
+
default: false
|
|
72
|
+
},
|
|
73
|
+
filterMethod: {
|
|
74
|
+
type: Function
|
|
75
|
+
},
|
|
76
|
+
remoteMethod: {
|
|
77
|
+
type: Function
|
|
78
|
+
},
|
|
79
|
+
enableLazyLoad: {
|
|
80
|
+
type: Boolean,
|
|
81
|
+
default: false
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const SELECT_KEY = Symbol("EditableSelect");
|
|
85
|
+
const DEFAULT_PREFIX = "icon";
|
|
86
|
+
const iconProps = {
|
|
87
|
+
name: {
|
|
88
|
+
type: String,
|
|
89
|
+
default: "",
|
|
90
|
+
required: true
|
|
91
|
+
},
|
|
92
|
+
size: {
|
|
93
|
+
type: [Number, String],
|
|
94
|
+
default: "inherit"
|
|
95
|
+
},
|
|
96
|
+
color: {
|
|
97
|
+
type: String,
|
|
98
|
+
default: "inherit"
|
|
99
|
+
},
|
|
100
|
+
component: {
|
|
101
|
+
type: Object,
|
|
102
|
+
default: null
|
|
103
|
+
},
|
|
104
|
+
classPrefix: {
|
|
105
|
+
type: String,
|
|
106
|
+
default: DEFAULT_PREFIX
|
|
107
|
+
},
|
|
108
|
+
operable: {
|
|
109
|
+
type: Boolean,
|
|
110
|
+
default: false
|
|
111
|
+
},
|
|
112
|
+
disabled: {
|
|
113
|
+
type: Boolean,
|
|
114
|
+
default: false
|
|
115
|
+
},
|
|
116
|
+
rotate: {
|
|
117
|
+
type: [Number, String]
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const svgIconProps = {
|
|
121
|
+
name: {
|
|
122
|
+
type: String,
|
|
123
|
+
default: "",
|
|
124
|
+
required: true
|
|
125
|
+
},
|
|
126
|
+
color: {
|
|
127
|
+
type: String,
|
|
128
|
+
default: "inherit"
|
|
129
|
+
},
|
|
130
|
+
size: {
|
|
131
|
+
type: [Number, String],
|
|
132
|
+
default: "inherit"
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
function createBem(namespace, element, modifier) {
|
|
136
|
+
let cls = namespace;
|
|
137
|
+
if (element) {
|
|
138
|
+
cls += `__${element}`;
|
|
139
|
+
}
|
|
140
|
+
if (modifier) {
|
|
141
|
+
cls += `--${modifier}`;
|
|
142
|
+
}
|
|
143
|
+
return cls;
|
|
144
|
+
}
|
|
145
|
+
function useNamespace(block, needDot = false) {
|
|
146
|
+
const namespace = needDot ? `.devui-${block}` : `devui-${block}`;
|
|
147
|
+
const b = () => createBem(namespace);
|
|
148
|
+
const e = (element) => element ? createBem(namespace, element) : "";
|
|
149
|
+
const m = (modifier) => modifier ? createBem(namespace, "", modifier) : "";
|
|
150
|
+
const em = (element, modifier) => element && modifier ? createBem(namespace, element, modifier) : "";
|
|
151
|
+
return {
|
|
152
|
+
b,
|
|
153
|
+
e,
|
|
154
|
+
m,
|
|
155
|
+
em
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
var icon = "";
|
|
159
|
+
var svgIcon = defineComponent({
|
|
160
|
+
name: "DSvgIcon",
|
|
161
|
+
props: svgIconProps,
|
|
162
|
+
setup(props) {
|
|
163
|
+
const {
|
|
164
|
+
name,
|
|
165
|
+
color,
|
|
166
|
+
size
|
|
167
|
+
} = toRefs(props);
|
|
168
|
+
const ns = useNamespace("svg-icon");
|
|
169
|
+
const iconName = computed(() => `#icon-${name.value}`);
|
|
170
|
+
const iconSize = computed(() => {
|
|
171
|
+
return typeof size.value === "number" ? `${size.value}px` : size.value;
|
|
172
|
+
});
|
|
173
|
+
const styles = {
|
|
174
|
+
width: iconSize.value,
|
|
175
|
+
height: iconSize.value
|
|
176
|
+
};
|
|
177
|
+
return () => {
|
|
178
|
+
return createVNode("svg", {
|
|
179
|
+
"class": ns.b(),
|
|
180
|
+
"style": styles
|
|
181
|
+
}, [createVNode("use", {
|
|
182
|
+
"xlink:href": iconName.value,
|
|
183
|
+
"fill": color.value
|
|
184
|
+
}, null)]);
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
function isUrl(value) {
|
|
189
|
+
return /^((http|https):)?\/\//.test(value);
|
|
190
|
+
}
|
|
191
|
+
function useIconDom(props, ctx) {
|
|
192
|
+
const {
|
|
193
|
+
component,
|
|
194
|
+
name,
|
|
195
|
+
size,
|
|
196
|
+
color,
|
|
197
|
+
classPrefix,
|
|
198
|
+
rotate
|
|
199
|
+
} = toRefs(props);
|
|
200
|
+
const ns = useNamespace("icon");
|
|
201
|
+
const iconSize = computed(() => {
|
|
202
|
+
return typeof size.value === "number" ? `${size.value}px` : size.value;
|
|
203
|
+
});
|
|
204
|
+
const IconComponent = component.value ? resolveDynamicComponent(component.value) : resolveDynamicComponent(svgIcon);
|
|
205
|
+
const imgIconDom = () => {
|
|
206
|
+
return createVNode("img", mergeProps({
|
|
207
|
+
"src": name.value,
|
|
208
|
+
"alt": name.value.split("/")[name.value.split("/").length - 1],
|
|
209
|
+
"class": [(rotate == null ? void 0 : rotate.value) === "infinite" && ns.m("spin")],
|
|
210
|
+
"style": {
|
|
211
|
+
width: iconSize.value || "",
|
|
212
|
+
transform: `rotate(${rotate == null ? void 0 : rotate.value}deg)`,
|
|
213
|
+
verticalAlign: "middle"
|
|
214
|
+
}
|
|
215
|
+
}, ctx.attrs), null);
|
|
216
|
+
};
|
|
217
|
+
const svgIconDom = () => {
|
|
218
|
+
return createVNode(IconComponent, mergeProps({
|
|
219
|
+
"name": name.value,
|
|
220
|
+
"color": color.value,
|
|
221
|
+
"size": iconSize.value,
|
|
222
|
+
"class": [(rotate == null ? void 0 : rotate.value) === "infinite" && ns.m("spin")],
|
|
223
|
+
"style": {
|
|
224
|
+
transform: `rotate(${rotate == null ? void 0 : rotate.value}deg)`
|
|
225
|
+
}
|
|
226
|
+
}, ctx.attrs), null);
|
|
227
|
+
};
|
|
228
|
+
const fontIconDom = () => {
|
|
229
|
+
const fontIconClass = /^icon-/.test(name.value) ? name.value : `${classPrefix.value}-${name.value}`;
|
|
230
|
+
return createVNode("i", mergeProps({
|
|
231
|
+
"class": [classPrefix.value, fontIconClass, (rotate == null ? void 0 : rotate.value) === "infinite" && ns.m("spin")],
|
|
232
|
+
"style": {
|
|
233
|
+
fontSize: iconSize.value,
|
|
234
|
+
color: color.value,
|
|
235
|
+
transform: `rotate(${rotate == null ? void 0 : rotate.value}deg)`
|
|
236
|
+
}
|
|
237
|
+
}, ctx.attrs), null);
|
|
238
|
+
};
|
|
239
|
+
const iconDom = () => {
|
|
240
|
+
return component.value ? svgIconDom() : isUrl(name.value) ? imgIconDom() : fontIconDom();
|
|
241
|
+
};
|
|
242
|
+
return {
|
|
243
|
+
iconDom
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
var Icon = defineComponent({
|
|
247
|
+
name: "DIcon",
|
|
248
|
+
props: iconProps,
|
|
249
|
+
emits: ["click"],
|
|
250
|
+
setup(props, ctx) {
|
|
251
|
+
const {
|
|
252
|
+
disabled,
|
|
253
|
+
operable
|
|
254
|
+
} = toRefs(props);
|
|
255
|
+
const {
|
|
256
|
+
iconDom
|
|
257
|
+
} = useIconDom(props, ctx);
|
|
258
|
+
const ns = useNamespace("icon");
|
|
259
|
+
const wrapClassed = computed(() => ({
|
|
260
|
+
[ns.e("container")]: true,
|
|
261
|
+
[ns.m("disabled")]: disabled.value,
|
|
262
|
+
[ns.m("operable")]: operable.value,
|
|
263
|
+
[ns.m("no-slots")]: !Object.keys(ctx.slots).length
|
|
264
|
+
}));
|
|
265
|
+
const onClick = (e) => {
|
|
266
|
+
if (disabled.value) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
ctx.emit("click", e);
|
|
270
|
+
};
|
|
271
|
+
return () => {
|
|
272
|
+
var _a, _b, _c, _d;
|
|
273
|
+
return createVNode("div", {
|
|
274
|
+
"class": wrapClassed.value,
|
|
275
|
+
"onClick": onClick
|
|
276
|
+
}, [(_b = (_a = ctx.slots).prefix) == null ? void 0 : _b.call(_a), iconDom(), (_d = (_c = ctx.slots).suffix) == null ? void 0 : _d.call(_c)]);
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
const fixedOverlayProps = {
|
|
281
|
+
modelValue: {
|
|
282
|
+
type: Boolean,
|
|
283
|
+
default: false
|
|
284
|
+
},
|
|
285
|
+
lockScroll: {
|
|
286
|
+
type: Boolean,
|
|
287
|
+
default: true
|
|
288
|
+
},
|
|
289
|
+
closeOnClickOverlay: {
|
|
290
|
+
type: Boolean,
|
|
291
|
+
default: true
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
function lockScroll() {
|
|
295
|
+
if (document.documentElement.scrollHeight > document.documentElement.clientHeight) {
|
|
296
|
+
const scrollTop = document.documentElement.scrollTop;
|
|
297
|
+
const style = document.documentElement.getAttribute("style");
|
|
298
|
+
document.documentElement.style.position = "fixed";
|
|
299
|
+
document.documentElement.style.top = `-${scrollTop}px`;
|
|
300
|
+
document.documentElement.style.width = document.documentElement.style.width || "100%";
|
|
301
|
+
document.documentElement.style.overflowY = "scroll";
|
|
302
|
+
return () => {
|
|
303
|
+
if (style) {
|
|
304
|
+
document.documentElement.setAttribute("style", style);
|
|
305
|
+
} else {
|
|
306
|
+
document.documentElement.removeAttribute("style");
|
|
307
|
+
}
|
|
308
|
+
document.documentElement.scrollTop = scrollTop;
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
function useFixedOverlay(props, ctx) {
|
|
314
|
+
let lockScrollCb;
|
|
315
|
+
const onClick = (event) => {
|
|
316
|
+
event.preventDefault();
|
|
317
|
+
ctx.emit("click", event);
|
|
318
|
+
if (props.closeOnClickOverlay) {
|
|
319
|
+
ctx.emit("update:modelValue", false);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
const removeBodyAdditions = () => {
|
|
323
|
+
lockScrollCb == null ? void 0 : lockScrollCb();
|
|
324
|
+
};
|
|
325
|
+
watch(() => props.modelValue, (val) => {
|
|
326
|
+
if (val) {
|
|
327
|
+
props.lockScroll && (lockScrollCb = lockScroll());
|
|
328
|
+
} else {
|
|
329
|
+
removeBodyAdditions();
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
onUnmounted(removeBodyAdditions);
|
|
333
|
+
return { onClick };
|
|
334
|
+
}
|
|
335
|
+
var fixedOverlay = "";
|
|
336
|
+
defineComponent({
|
|
337
|
+
name: "DFixedOverlay",
|
|
338
|
+
inheritAttrs: false,
|
|
339
|
+
props: fixedOverlayProps,
|
|
340
|
+
emits: ["update:modelValue", "click"],
|
|
341
|
+
setup(props, ctx) {
|
|
342
|
+
const {
|
|
343
|
+
modelValue
|
|
344
|
+
} = toRefs(props);
|
|
345
|
+
const ns = useNamespace("fixed-overlay");
|
|
346
|
+
const {
|
|
347
|
+
onClick
|
|
348
|
+
} = useFixedOverlay(props, ctx);
|
|
349
|
+
return () => createVNode(Transition, {
|
|
350
|
+
"name": ns.m("fade")
|
|
351
|
+
}, {
|
|
352
|
+
default: () => {
|
|
353
|
+
var _a, _b;
|
|
354
|
+
return [modelValue.value && createVNode("div", mergeProps({
|
|
355
|
+
"class": ns.b()
|
|
356
|
+
}, ctx.attrs, {
|
|
357
|
+
"onClick": onClick
|
|
358
|
+
}), [(_b = (_a = ctx.slots).default) == null ? void 0 : _b.call(_a)])];
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
const flexibleOverlayProps = {
|
|
364
|
+
modelValue: {
|
|
365
|
+
type: Boolean,
|
|
366
|
+
default: false
|
|
367
|
+
},
|
|
368
|
+
origin: {
|
|
369
|
+
type: Object,
|
|
370
|
+
require: true
|
|
371
|
+
},
|
|
372
|
+
position: {
|
|
373
|
+
type: Array,
|
|
374
|
+
default: ["bottom"]
|
|
375
|
+
},
|
|
376
|
+
offset: {
|
|
377
|
+
type: [Number, Object],
|
|
378
|
+
default: 8
|
|
379
|
+
},
|
|
380
|
+
shiftOffset: {
|
|
381
|
+
type: Number
|
|
382
|
+
},
|
|
383
|
+
align: {
|
|
384
|
+
type: String,
|
|
385
|
+
default: null
|
|
386
|
+
},
|
|
387
|
+
showArrow: {
|
|
388
|
+
type: Boolean,
|
|
389
|
+
default: false
|
|
390
|
+
},
|
|
391
|
+
isArrowCenter: {
|
|
392
|
+
type: Boolean,
|
|
393
|
+
default: true
|
|
394
|
+
},
|
|
395
|
+
clickEventBubble: {
|
|
396
|
+
type: Boolean,
|
|
397
|
+
default: false
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
function getScrollParent(element) {
|
|
401
|
+
const overflowRegex = /(auto|scroll|hidden)/;
|
|
402
|
+
for (let parent = element; parent = parent.parentElement; parent.parentElement !== document.body) {
|
|
403
|
+
const style = window.getComputedStyle(parent);
|
|
404
|
+
if (overflowRegex.test(style.overflow + style.overflowX + style.overflowY)) {
|
|
405
|
+
return parent;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return window;
|
|
409
|
+
}
|
|
410
|
+
function adjustArrowPosition(isArrowCenter, point, placement, originRect) {
|
|
411
|
+
let { x, y } = point;
|
|
412
|
+
if (!isArrowCenter) {
|
|
413
|
+
const { width, height } = originRect;
|
|
414
|
+
if (x && placement.includes("start")) {
|
|
415
|
+
x = 12;
|
|
416
|
+
}
|
|
417
|
+
if (x && placement.includes("end")) {
|
|
418
|
+
x = Math.round(width - 24);
|
|
419
|
+
}
|
|
420
|
+
if (y && placement.includes("start")) {
|
|
421
|
+
y = 10;
|
|
422
|
+
}
|
|
423
|
+
if (y && placement.includes("end")) {
|
|
424
|
+
y = height - 14;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return { x, y };
|
|
428
|
+
}
|
|
429
|
+
function useOverlay(props, emit) {
|
|
430
|
+
const overlayRef = ref();
|
|
431
|
+
const arrowRef = ref();
|
|
432
|
+
let originParent = null;
|
|
433
|
+
const updateArrowPosition = (arrowEl, placement, point, overlayEl) => {
|
|
434
|
+
const { x, y } = adjustArrowPosition(props.isArrowCenter, point, placement, overlayEl.getBoundingClientRect());
|
|
435
|
+
const staticSide = {
|
|
436
|
+
top: "bottom",
|
|
437
|
+
right: "left",
|
|
438
|
+
bottom: "top",
|
|
439
|
+
left: "right"
|
|
440
|
+
}[placement.split("-")[0]];
|
|
441
|
+
Object.assign(arrowEl.style, {
|
|
442
|
+
left: x ? `${x}px` : "",
|
|
443
|
+
top: y ? `${y}px` : "",
|
|
444
|
+
right: "",
|
|
445
|
+
bottom: "",
|
|
446
|
+
[staticSide]: "-4px"
|
|
447
|
+
});
|
|
448
|
+
};
|
|
449
|
+
const updatePosition = async () => {
|
|
450
|
+
const hostEl = props.origin;
|
|
451
|
+
const overlayEl = unref(overlayRef.value);
|
|
452
|
+
const arrowEl = unref(arrowRef.value);
|
|
453
|
+
const middleware = [
|
|
454
|
+
offset(props.offset),
|
|
455
|
+
autoPlacement({
|
|
456
|
+
alignment: props.align,
|
|
457
|
+
allowedPlacements: props.position
|
|
458
|
+
})
|
|
459
|
+
];
|
|
460
|
+
props.showArrow && middleware.push(arrow({ element: arrowEl }));
|
|
461
|
+
props.shiftOffset !== void 0 && middleware.push(shift());
|
|
462
|
+
const { x, y, placement, middlewareData } = await computePosition(hostEl, overlayEl, {
|
|
463
|
+
strategy: "fixed",
|
|
464
|
+
middleware
|
|
465
|
+
});
|
|
466
|
+
let applyX = x;
|
|
467
|
+
let applyY = y;
|
|
468
|
+
if (props.shiftOffset !== void 0) {
|
|
469
|
+
const { x: shiftX, y: shiftY } = middlewareData.shift;
|
|
470
|
+
shiftX < 0 && (applyX -= props.shiftOffset);
|
|
471
|
+
shiftX > 0 && (applyX += props.shiftOffset);
|
|
472
|
+
shiftY < 0 && (applyY -= props.shiftOffset);
|
|
473
|
+
shiftY > 0 && (applyY += props.shiftOffset);
|
|
474
|
+
}
|
|
475
|
+
emit("positionChange", placement);
|
|
476
|
+
Object.assign(overlayEl.style, { top: `${applyY}px`, left: `${applyX}px` });
|
|
477
|
+
props.showArrow && updateArrowPosition(arrowEl, placement, middlewareData.arrow, overlayEl);
|
|
478
|
+
};
|
|
479
|
+
watch(() => props.modelValue, () => {
|
|
480
|
+
if (props.modelValue && props.origin) {
|
|
481
|
+
originParent = getScrollParent(props.origin);
|
|
482
|
+
nextTick(updatePosition);
|
|
483
|
+
originParent == null ? void 0 : originParent.addEventListener("scroll", updatePosition);
|
|
484
|
+
originParent !== window && window.addEventListener("scroll", updatePosition);
|
|
485
|
+
window.addEventListener("resize", updatePosition);
|
|
486
|
+
} else {
|
|
487
|
+
originParent == null ? void 0 : originParent.removeEventListener("scroll", updatePosition);
|
|
488
|
+
originParent !== window && window.removeEventListener("scroll", updatePosition);
|
|
489
|
+
window.removeEventListener("resize", updatePosition);
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
onUnmounted(() => {
|
|
493
|
+
originParent == null ? void 0 : originParent.removeEventListener("scroll", updatePosition);
|
|
494
|
+
originParent !== window && window.removeEventListener("scroll", updatePosition);
|
|
495
|
+
window.removeEventListener("resize", updatePosition);
|
|
496
|
+
});
|
|
497
|
+
return { arrowRef, overlayRef, updatePosition };
|
|
498
|
+
}
|
|
499
|
+
var flexibleOverlay = "";
|
|
500
|
+
const FlexibleOverlay = defineComponent({
|
|
501
|
+
name: "DFlexibleOverlay",
|
|
502
|
+
inheritAttrs: false,
|
|
503
|
+
props: flexibleOverlayProps,
|
|
504
|
+
emits: ["update:modelValue", "positionChange"],
|
|
505
|
+
setup(props, {
|
|
506
|
+
slots,
|
|
507
|
+
attrs,
|
|
508
|
+
emit,
|
|
509
|
+
expose
|
|
510
|
+
}) {
|
|
511
|
+
const ns = useNamespace("flexible-overlay");
|
|
512
|
+
const {
|
|
513
|
+
clickEventBubble
|
|
514
|
+
} = toRefs(props);
|
|
515
|
+
const {
|
|
516
|
+
arrowRef,
|
|
517
|
+
overlayRef,
|
|
518
|
+
updatePosition
|
|
519
|
+
} = useOverlay(props, emit);
|
|
520
|
+
expose({
|
|
521
|
+
updatePosition
|
|
522
|
+
});
|
|
523
|
+
return () => {
|
|
524
|
+
var _a;
|
|
525
|
+
return props.modelValue && createVNode("div", mergeProps({
|
|
526
|
+
"ref": overlayRef,
|
|
527
|
+
"class": ns.b()
|
|
528
|
+
}, attrs, {
|
|
529
|
+
"onClick": withModifiers(() => ({}), [clickEventBubble.value ? "" : "stop"]),
|
|
530
|
+
"onPointerup": withModifiers(() => ({}), ["stop"])
|
|
531
|
+
}), [(_a = slots.default) == null ? void 0 : _a.call(slots), props.showArrow && createVNode("div", {
|
|
532
|
+
"ref": arrowRef,
|
|
533
|
+
"class": ns.e("arrow")
|
|
534
|
+
}, null)]);
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
const dropdownProps = {
|
|
31
539
|
options: {
|
|
32
540
|
type: Array,
|
|
33
541
|
default: () => []
|
|
34
542
|
},
|
|
35
|
-
allowClear: {
|
|
36
|
-
type: Boolean,
|
|
37
|
-
default: false
|
|
38
|
-
},
|
|
39
|
-
disabled: {
|
|
40
|
-
type: Boolean
|
|
41
|
-
},
|
|
42
|
-
disabledKey: {
|
|
43
|
-
type: String,
|
|
44
|
-
default: ""
|
|
45
|
-
},
|
|
46
|
-
placeholder: {
|
|
47
|
-
type: String,
|
|
48
|
-
default: "Search"
|
|
49
|
-
},
|
|
50
543
|
width: {
|
|
51
544
|
type: Number
|
|
52
545
|
},
|
|
53
546
|
maxHeight: {
|
|
54
547
|
type: Number
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
const editableSelectOptionProps = {
|
|
551
|
+
label: {
|
|
552
|
+
type: String
|
|
55
553
|
},
|
|
56
|
-
|
|
57
|
-
type:
|
|
554
|
+
value: {
|
|
555
|
+
type: [String, Number]
|
|
58
556
|
},
|
|
59
|
-
|
|
557
|
+
disabled: {
|
|
60
558
|
type: Boolean,
|
|
61
559
|
default: false
|
|
62
560
|
},
|
|
63
|
-
|
|
64
|
-
type:
|
|
561
|
+
hovering: {
|
|
562
|
+
type: Boolean,
|
|
563
|
+
default: false
|
|
65
564
|
}
|
|
66
565
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
566
|
+
function useOption(props) {
|
|
567
|
+
const ns = useNamespace("editable-select");
|
|
568
|
+
const select = inject(SELECT_KEY);
|
|
569
|
+
const { disabled, hovering } = toRefs(props);
|
|
570
|
+
const isSelected = computed(() => {
|
|
571
|
+
var _a;
|
|
572
|
+
return ((_a = select == null ? void 0 : select.modelValue) == null ? void 0 : _a.value) === props.value;
|
|
573
|
+
});
|
|
574
|
+
const optionClasses = computed(() => ({
|
|
575
|
+
[ns.e("item")]: true,
|
|
576
|
+
[ns.em("item", "selected")]: isSelected.value,
|
|
577
|
+
[ns.em("item", "disabled")]: disabled.value,
|
|
578
|
+
[ns.em("item", "hover")]: hovering.value,
|
|
579
|
+
[ns.em("item", "no-data-tip")]: !(props.label || props.value)
|
|
580
|
+
}));
|
|
581
|
+
return { optionClasses };
|
|
78
582
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
for (const [id, node] of nodeList) {
|
|
92
|
-
node[ctx].documentHandler(e, startClick);
|
|
583
|
+
var Option = defineComponent({
|
|
584
|
+
name: "DEditableSelectOption",
|
|
585
|
+
props: editableSelectOptionProps,
|
|
586
|
+
emits: ["select"],
|
|
587
|
+
setup(props, ctx) {
|
|
588
|
+
const {
|
|
589
|
+
optionClasses
|
|
590
|
+
} = useOption(props);
|
|
591
|
+
const currentLabel = computed(() => props.label || props.value);
|
|
592
|
+
const handleClick = () => {
|
|
593
|
+
if (!props.disabled) {
|
|
594
|
+
ctx.emit("select");
|
|
93
595
|
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
return function(mouseup, mousedown) {
|
|
97
|
-
if (!vnode || !binding.instance || !mouseup.target || !mousedown.target || el.contains(mouseup.target) || el.contains(mousedown.target) || el === mouseup.target) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
el[ctx].bindingFn && el[ctx].bindingFn();
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
const clickoutsideDirective = {
|
|
104
|
-
beforeMount: function(el, binding, vnode) {
|
|
105
|
-
nid++;
|
|
106
|
-
nodeList.set(nid, el);
|
|
107
|
-
el[ctx] = {
|
|
108
|
-
nid,
|
|
109
|
-
documentHandler: createDocumentHandler(el, binding, vnode),
|
|
110
|
-
bindingFn: binding.value
|
|
111
596
|
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
nodeList.delete(el[ctx].nid);
|
|
119
|
-
delete el[ctx];
|
|
597
|
+
return () => {
|
|
598
|
+
return createVNode("li", {
|
|
599
|
+
"class": optionClasses.value,
|
|
600
|
+
"onClick": handleClick
|
|
601
|
+
}, [ctx.slots.default ? ctx.slots.default() : currentLabel.value]);
|
|
602
|
+
};
|
|
120
603
|
}
|
|
121
|
-
};
|
|
604
|
+
});
|
|
122
605
|
class View {
|
|
123
606
|
constructor() {
|
|
124
607
|
__publicField(this, "top", "50%");
|
|
@@ -149,29 +632,6 @@ class LoadingOptions {
|
|
|
149
632
|
__publicField(this, "zIndex");
|
|
150
633
|
}
|
|
151
634
|
}
|
|
152
|
-
function createBem(namespace, element, modifier) {
|
|
153
|
-
let cls = namespace;
|
|
154
|
-
if (element) {
|
|
155
|
-
cls += `__${element}`;
|
|
156
|
-
}
|
|
157
|
-
if (modifier) {
|
|
158
|
-
cls += `--${modifier}`;
|
|
159
|
-
}
|
|
160
|
-
return cls;
|
|
161
|
-
}
|
|
162
|
-
function useNamespace(block, needDot = false) {
|
|
163
|
-
const namespace = needDot ? `.devui-${block}` : `devui-${block}`;
|
|
164
|
-
const b = () => createBem(namespace);
|
|
165
|
-
const e = (element) => element ? createBem(namespace, element) : "";
|
|
166
|
-
const m = (modifier) => modifier ? createBem(namespace, "", modifier) : "";
|
|
167
|
-
const em = (element, modifier) => element && modifier ? createBem(namespace, element, modifier) : "";
|
|
168
|
-
return {
|
|
169
|
-
b,
|
|
170
|
-
e,
|
|
171
|
-
m,
|
|
172
|
-
em
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
635
|
var loading = "";
|
|
176
636
|
var Loading = defineComponent({
|
|
177
637
|
name: "Loading",
|
|
@@ -337,353 +797,281 @@ const LoadingDirective = {
|
|
|
337
797
|
handleProps(el, vnode.props);
|
|
338
798
|
removeAttribute(el);
|
|
339
799
|
!isEmpty(binding.value) && toggleLoading(el, binding);
|
|
340
|
-
},
|
|
341
|
-
updated: function(el, binding, vnode) {
|
|
342
|
-
if (!isEmpty(binding.value) && cacheInstance.has(el) || isEmpty(binding.value) && !cacheInstance.has(el)) {
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
!cacheInstance.has(el) && handleProps(el, vnode.props);
|
|
346
|
-
removeAttribute(el);
|
|
347
|
-
toggleLoading(el, binding);
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
function className(classStr, classOpt) {
|
|
351
|
-
let classname = classStr;
|
|
352
|
-
if (typeof classOpt === "object") {
|
|
353
|
-
Object.keys(classOpt).forEach((key) => {
|
|
354
|
-
classOpt[key] && (classname += ` ${key}`);
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
return classname;
|
|
358
|
-
}
|
|
359
|
-
var editableSelect = "";
|
|
360
|
-
function useSelect(props) {
|
|
361
|
-
const normalizeOptions = computed(() => {
|
|
362
|
-
return props.options.map((option) => {
|
|
363
|
-
let res;
|
|
364
|
-
if (option !== "null" && typeof option === "object") {
|
|
365
|
-
res = __spreadProps(__spreadValues({}, option), {
|
|
366
|
-
label: option.label || "",
|
|
367
|
-
value: option.value !== void 0 ? option.value : option.label || ""
|
|
368
|
-
});
|
|
369
|
-
} else {
|
|
370
|
-
res = {
|
|
371
|
-
label: String(option),
|
|
372
|
-
value: option
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
return res;
|
|
376
|
-
});
|
|
377
|
-
});
|
|
378
|
-
return { normalizeOptions };
|
|
379
|
-
}
|
|
380
|
-
function useFilterOptions(enableLazyLoad, normalizeOptions, inputValue, searchFn) {
|
|
381
|
-
const filteredOptions = computed(() => {
|
|
382
|
-
if (!inputValue.value || enableLazyLoad) {
|
|
383
|
-
return normalizeOptions.value;
|
|
384
|
-
}
|
|
385
|
-
return normalizeOptions.value.filter((option) => {
|
|
386
|
-
return searchFn(option, inputValue.value);
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
return { filteredOptions };
|
|
390
|
-
}
|
|
391
|
-
function useInput(inputValue, ctx2) {
|
|
392
|
-
const onInputChange = (value) => {
|
|
393
|
-
ctx2.emit("search", value);
|
|
394
|
-
};
|
|
395
|
-
const handleInput = (event) => {
|
|
396
|
-
const value = event.target.value;
|
|
397
|
-
inputValue.value = value;
|
|
398
|
-
onInputChange(value);
|
|
399
|
-
};
|
|
400
|
-
return {
|
|
401
|
-
handleInput
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
|
-
function useLazyLoad(dropdownRef, enableLazyLoad, ctx2) {
|
|
405
|
-
const loadMore = () => {
|
|
406
|
-
const dropdownVal = dropdownRef.value;
|
|
407
|
-
if (!enableLazyLoad) {
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
if (dropdownVal.clientHeight + dropdownVal.scrollTop >= dropdownVal.scrollHeight - 12) {
|
|
411
|
-
ctx2.emit("loadMore");
|
|
412
|
-
}
|
|
413
|
-
};
|
|
414
|
-
return { loadMore };
|
|
415
|
-
}
|
|
416
|
-
function useKeyboardSelect(dropdownRef, hoverIndex, filteredOptions, disabledKey, visible, loading2, handleClick, toggleMenu, closeMenu) {
|
|
417
|
-
const handleEscape = () => {
|
|
418
|
-
closeMenu();
|
|
419
|
-
};
|
|
420
|
-
const handleEnter = () => {
|
|
421
|
-
handleClick(filteredOptions.value[hoverIndex.value], hoverIndex.value);
|
|
422
|
-
};
|
|
423
|
-
const scrollToItem = (index2) => {
|
|
424
|
-
const ul = dropdownRef.value;
|
|
425
|
-
const li = ul.children[index2];
|
|
426
|
-
nextTick(() => {
|
|
427
|
-
if (li.scrollIntoViewIfNeeded) {
|
|
428
|
-
li.scrollIntoViewIfNeeded(false);
|
|
429
|
-
} else {
|
|
430
|
-
const containerInfo = ul.getBoundingClientRect();
|
|
431
|
-
const elementInfo = li.getBoundingClientRect();
|
|
432
|
-
if (elementInfo.bottom > containerInfo.bottom || elementInfo.top < containerInfo.top) {
|
|
433
|
-
li.scrollIntoView(false);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
};
|
|
438
|
-
const updateIndex = (index2) => {
|
|
439
|
-
hoverIndex.value = index2;
|
|
440
|
-
};
|
|
441
|
-
const handleKeyboardNavigation = (direction, index2 = hoverIndex.value) => {
|
|
442
|
-
const len = filteredOptions.value.length;
|
|
443
|
-
if (len === 0) {
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
if (!["ArrowUp", "ArrowDown"].includes(direction)) {
|
|
447
|
-
return;
|
|
448
|
-
}
|
|
449
|
-
if (direction === "ArrowUp") {
|
|
450
|
-
index2 -= 1;
|
|
451
|
-
if (index2 === -1) {
|
|
452
|
-
index2 = len - 1;
|
|
453
|
-
}
|
|
454
|
-
} else if (direction === "ArrowDown") {
|
|
455
|
-
index2 += 1;
|
|
456
|
-
if (index2 === len) {
|
|
457
|
-
index2 = 0;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
const option = filteredOptions.value[index2];
|
|
461
|
-
if (option[disabledKey]) {
|
|
462
|
-
return handleKeyboardNavigation(direction, index2);
|
|
463
|
-
}
|
|
464
|
-
updateIndex(index2);
|
|
465
|
-
scrollToItem(index2);
|
|
466
|
-
};
|
|
467
|
-
const handleKeydown = (event) => {
|
|
468
|
-
const keyCode = event.key || event.code;
|
|
469
|
-
if (loading2.value) {
|
|
470
|
-
return;
|
|
471
|
-
}
|
|
472
|
-
if (!visible.value) {
|
|
473
|
-
return toggleMenu();
|
|
474
|
-
}
|
|
475
|
-
switch (keyCode) {
|
|
476
|
-
case "Escape":
|
|
477
|
-
handleEscape();
|
|
478
|
-
break;
|
|
479
|
-
case "Enter":
|
|
480
|
-
handleEnter();
|
|
481
|
-
break;
|
|
482
|
-
default:
|
|
483
|
-
handleKeyboardNavigation(keyCode);
|
|
484
|
-
}
|
|
485
|
-
};
|
|
486
|
-
return {
|
|
487
|
-
handleKeydown
|
|
488
|
-
};
|
|
489
|
-
}
|
|
490
|
-
const flexibleOverlayProps = {
|
|
491
|
-
modelValue: {
|
|
492
|
-
type: Boolean,
|
|
493
|
-
default: false
|
|
494
|
-
},
|
|
495
|
-
origin: {
|
|
496
|
-
type: Object,
|
|
497
|
-
require: true
|
|
498
|
-
},
|
|
499
|
-
position: {
|
|
500
|
-
type: Array,
|
|
501
|
-
default: ["bottom"]
|
|
502
|
-
},
|
|
503
|
-
offset: {
|
|
504
|
-
type: [Number, Object],
|
|
505
|
-
default: 8
|
|
506
|
-
},
|
|
507
|
-
shiftOffset: {
|
|
508
|
-
type: Number
|
|
509
|
-
},
|
|
510
|
-
align: {
|
|
511
|
-
type: String,
|
|
512
|
-
default: null
|
|
513
|
-
},
|
|
514
|
-
showArrow: {
|
|
515
|
-
type: Boolean,
|
|
516
|
-
default: false
|
|
517
|
-
},
|
|
518
|
-
isArrowCenter: {
|
|
519
|
-
type: Boolean,
|
|
520
|
-
default: true
|
|
521
|
-
},
|
|
522
|
-
clickEventBubble: {
|
|
523
|
-
type: Boolean,
|
|
524
|
-
default: false
|
|
525
|
-
}
|
|
526
|
-
};
|
|
527
|
-
function getScrollParent(element) {
|
|
528
|
-
const overflowRegex = /(auto|scroll|hidden)/;
|
|
529
|
-
for (let parent = element; parent = parent.parentElement; parent.parentElement !== document.body) {
|
|
530
|
-
const style = window.getComputedStyle(parent);
|
|
531
|
-
if (overflowRegex.test(style.overflow + style.overflowX + style.overflowY)) {
|
|
532
|
-
return parent;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
return window;
|
|
536
|
-
}
|
|
537
|
-
function adjustArrowPosition(isArrowCenter, point, placement, originRect) {
|
|
538
|
-
let { x, y } = point;
|
|
539
|
-
if (!isArrowCenter) {
|
|
540
|
-
const { width, height } = originRect;
|
|
541
|
-
if (x && placement.includes("start")) {
|
|
542
|
-
x = 12;
|
|
543
|
-
}
|
|
544
|
-
if (x && placement.includes("end")) {
|
|
545
|
-
x = Math.round(width - 24);
|
|
546
|
-
}
|
|
547
|
-
if (y && placement.includes("start")) {
|
|
548
|
-
y = 10;
|
|
549
|
-
}
|
|
550
|
-
if (y && placement.includes("end")) {
|
|
551
|
-
y = height - 14;
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
return { x, y };
|
|
555
|
-
}
|
|
556
|
-
function useOverlay(props, emit) {
|
|
557
|
-
const overlayRef = ref();
|
|
558
|
-
const arrowRef = ref();
|
|
559
|
-
let originParent = null;
|
|
560
|
-
const updateArrowPosition = (arrowEl, placement, point, overlayEl) => {
|
|
561
|
-
const { x, y } = adjustArrowPosition(props.isArrowCenter, point, placement, overlayEl.getBoundingClientRect());
|
|
562
|
-
const staticSide = {
|
|
563
|
-
top: "bottom",
|
|
564
|
-
right: "left",
|
|
565
|
-
bottom: "top",
|
|
566
|
-
left: "right"
|
|
567
|
-
}[placement.split("-")[0]];
|
|
568
|
-
Object.assign(arrowEl.style, {
|
|
569
|
-
left: x ? `${x}px` : "",
|
|
570
|
-
top: y ? `${y}px` : "",
|
|
571
|
-
right: "",
|
|
572
|
-
bottom: "",
|
|
573
|
-
[staticSide]: "-4px"
|
|
574
|
-
});
|
|
575
|
-
};
|
|
576
|
-
const updatePosition = async () => {
|
|
577
|
-
const hostEl = props.origin;
|
|
578
|
-
const overlayEl = unref(overlayRef.value);
|
|
579
|
-
const arrowEl = unref(arrowRef.value);
|
|
580
|
-
const middleware = [
|
|
581
|
-
offset(props.offset),
|
|
582
|
-
autoPlacement({
|
|
583
|
-
alignment: props.align,
|
|
584
|
-
allowedPlacements: props.position
|
|
585
|
-
})
|
|
586
|
-
];
|
|
587
|
-
props.showArrow && middleware.push(arrow({ element: arrowEl }));
|
|
588
|
-
props.shiftOffset !== void 0 && middleware.push(shift());
|
|
589
|
-
const { x, y, placement, middlewareData } = await computePosition(hostEl, overlayEl, {
|
|
590
|
-
strategy: "fixed",
|
|
591
|
-
middleware
|
|
592
|
-
});
|
|
593
|
-
let applyX = x;
|
|
594
|
-
let applyY = y;
|
|
595
|
-
if (props.shiftOffset !== void 0) {
|
|
596
|
-
const { x: shiftX, y: shiftY } = middlewareData.shift;
|
|
597
|
-
shiftX < 0 && (applyX -= props.shiftOffset);
|
|
598
|
-
shiftX > 0 && (applyX += props.shiftOffset);
|
|
599
|
-
shiftY < 0 && (applyY -= props.shiftOffset);
|
|
600
|
-
shiftY > 0 && (applyY += props.shiftOffset);
|
|
800
|
+
},
|
|
801
|
+
updated: function(el, binding, vnode) {
|
|
802
|
+
if (!isEmpty(binding.value) && cacheInstance.has(el) || isEmpty(binding.value) && !cacheInstance.has(el)) {
|
|
803
|
+
return;
|
|
601
804
|
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
805
|
+
!cacheInstance.has(el) && handleProps(el, vnode.props);
|
|
806
|
+
removeAttribute(el);
|
|
807
|
+
toggleLoading(el, binding);
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
811
|
+
var freeGlobal$1 = freeGlobal;
|
|
812
|
+
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
813
|
+
var root = freeGlobal$1 || freeSelf || Function("return this")();
|
|
814
|
+
var root$1 = root;
|
|
815
|
+
var Symbol$1 = root$1.Symbol;
|
|
816
|
+
var Symbol$2 = Symbol$1;
|
|
817
|
+
var objectProto$1 = Object.prototype;
|
|
818
|
+
var hasOwnProperty = objectProto$1.hasOwnProperty;
|
|
819
|
+
var nativeObjectToString$1 = objectProto$1.toString;
|
|
820
|
+
var symToStringTag$1 = Symbol$2 ? Symbol$2.toStringTag : void 0;
|
|
821
|
+
function getRawTag(value) {
|
|
822
|
+
var isOwn = hasOwnProperty.call(value, symToStringTag$1), tag = value[symToStringTag$1];
|
|
823
|
+
try {
|
|
824
|
+
value[symToStringTag$1] = void 0;
|
|
825
|
+
var unmasked = true;
|
|
826
|
+
} catch (e) {
|
|
827
|
+
}
|
|
828
|
+
var result = nativeObjectToString$1.call(value);
|
|
829
|
+
if (unmasked) {
|
|
830
|
+
if (isOwn) {
|
|
831
|
+
value[symToStringTag$1] = tag;
|
|
613
832
|
} else {
|
|
614
|
-
|
|
615
|
-
originParent !== window && window.removeEventListener("scroll", updatePosition);
|
|
616
|
-
window.removeEventListener("resize", updatePosition);
|
|
833
|
+
delete value[symToStringTag$1];
|
|
617
834
|
}
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
originParent == null ? void 0 : originParent.removeEventListener("scroll", updatePosition);
|
|
621
|
-
originParent !== window && window.removeEventListener("scroll", updatePosition);
|
|
622
|
-
window.removeEventListener("resize", updatePosition);
|
|
623
|
-
});
|
|
624
|
-
return { arrowRef, overlayRef, updatePosition };
|
|
835
|
+
}
|
|
836
|
+
return result;
|
|
625
837
|
}
|
|
626
|
-
var
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
838
|
+
var objectProto = Object.prototype;
|
|
839
|
+
var nativeObjectToString = objectProto.toString;
|
|
840
|
+
function objectToString(value) {
|
|
841
|
+
return nativeObjectToString.call(value);
|
|
842
|
+
}
|
|
843
|
+
var nullTag = "[object Null]", undefinedTag = "[object Undefined]";
|
|
844
|
+
var symToStringTag = Symbol$2 ? Symbol$2.toStringTag : void 0;
|
|
845
|
+
function baseGetTag(value) {
|
|
846
|
+
if (value == null) {
|
|
847
|
+
return value === void 0 ? undefinedTag : nullTag;
|
|
848
|
+
}
|
|
849
|
+
return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
|
|
850
|
+
}
|
|
851
|
+
function isObjectLike(value) {
|
|
852
|
+
return value != null && typeof value == "object";
|
|
853
|
+
}
|
|
854
|
+
var symbolTag = "[object Symbol]";
|
|
855
|
+
function isSymbol(value) {
|
|
856
|
+
return typeof value == "symbol" || isObjectLike(value) && baseGetTag(value) == symbolTag;
|
|
857
|
+
}
|
|
858
|
+
var reWhitespace = /\s/;
|
|
859
|
+
function trimmedEndIndex(string) {
|
|
860
|
+
var index2 = string.length;
|
|
861
|
+
while (index2-- && reWhitespace.test(string.charAt(index2))) {
|
|
862
|
+
}
|
|
863
|
+
return index2;
|
|
864
|
+
}
|
|
865
|
+
var reTrimStart = /^\s+/;
|
|
866
|
+
function baseTrim(string) {
|
|
867
|
+
return string ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, "") : string;
|
|
868
|
+
}
|
|
869
|
+
function isObject(value) {
|
|
870
|
+
var type = typeof value;
|
|
871
|
+
return value != null && (type == "object" || type == "function");
|
|
872
|
+
}
|
|
873
|
+
var NAN = 0 / 0;
|
|
874
|
+
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
|
|
875
|
+
var reIsBinary = /^0b[01]+$/i;
|
|
876
|
+
var reIsOctal = /^0o[0-7]+$/i;
|
|
877
|
+
var freeParseInt = parseInt;
|
|
878
|
+
function toNumber(value) {
|
|
879
|
+
if (typeof value == "number") {
|
|
880
|
+
return value;
|
|
881
|
+
}
|
|
882
|
+
if (isSymbol(value)) {
|
|
883
|
+
return NAN;
|
|
884
|
+
}
|
|
885
|
+
if (isObject(value)) {
|
|
886
|
+
var other = typeof value.valueOf == "function" ? value.valueOf() : value;
|
|
887
|
+
value = isObject(other) ? other + "" : other;
|
|
888
|
+
}
|
|
889
|
+
if (typeof value != "string") {
|
|
890
|
+
return value === 0 ? value : +value;
|
|
891
|
+
}
|
|
892
|
+
value = baseTrim(value);
|
|
893
|
+
var isBinary = reIsBinary.test(value);
|
|
894
|
+
return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
|
|
895
|
+
}
|
|
896
|
+
var asyncTag = "[object AsyncFunction]", funcTag = "[object Function]", genTag = "[object GeneratorFunction]", proxyTag = "[object Proxy]";
|
|
897
|
+
function isFunction(value) {
|
|
898
|
+
if (!isObject(value)) {
|
|
899
|
+
return false;
|
|
900
|
+
}
|
|
901
|
+
var tag = baseGetTag(value);
|
|
902
|
+
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
|
903
|
+
}
|
|
904
|
+
var now = function() {
|
|
905
|
+
return root$1.Date.now();
|
|
906
|
+
};
|
|
907
|
+
var now$1 = now;
|
|
908
|
+
var FUNC_ERROR_TEXT = "Expected a function";
|
|
909
|
+
var nativeMax = Math.max, nativeMin = Math.min;
|
|
910
|
+
function debounce(func, wait, options) {
|
|
911
|
+
var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
|
|
912
|
+
if (typeof func != "function") {
|
|
913
|
+
throw new TypeError(FUNC_ERROR_TEXT);
|
|
914
|
+
}
|
|
915
|
+
wait = toNumber(wait) || 0;
|
|
916
|
+
if (isObject(options)) {
|
|
917
|
+
leading = !!options.leading;
|
|
918
|
+
maxing = "maxWait" in options;
|
|
919
|
+
maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
|
|
920
|
+
trailing = "trailing" in options ? !!options.trailing : trailing;
|
|
921
|
+
}
|
|
922
|
+
function invokeFunc(time) {
|
|
923
|
+
var args = lastArgs, thisArg = lastThis;
|
|
924
|
+
lastArgs = lastThis = void 0;
|
|
925
|
+
lastInvokeTime = time;
|
|
926
|
+
result = func.apply(thisArg, args);
|
|
927
|
+
return result;
|
|
928
|
+
}
|
|
929
|
+
function leadingEdge(time) {
|
|
930
|
+
lastInvokeTime = time;
|
|
931
|
+
timerId = setTimeout(timerExpired, wait);
|
|
932
|
+
return leading ? invokeFunc(time) : result;
|
|
933
|
+
}
|
|
934
|
+
function remainingWait(time) {
|
|
935
|
+
var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
|
|
936
|
+
return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
|
|
937
|
+
}
|
|
938
|
+
function shouldInvoke(time) {
|
|
939
|
+
var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime;
|
|
940
|
+
return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
|
|
941
|
+
}
|
|
942
|
+
function timerExpired() {
|
|
943
|
+
var time = now$1();
|
|
944
|
+
if (shouldInvoke(time)) {
|
|
945
|
+
return trailingEdge(time);
|
|
946
|
+
}
|
|
947
|
+
timerId = setTimeout(timerExpired, remainingWait(time));
|
|
948
|
+
}
|
|
949
|
+
function trailingEdge(time) {
|
|
950
|
+
timerId = void 0;
|
|
951
|
+
if (trailing && lastArgs) {
|
|
952
|
+
return invokeFunc(time);
|
|
953
|
+
}
|
|
954
|
+
lastArgs = lastThis = void 0;
|
|
955
|
+
return result;
|
|
956
|
+
}
|
|
957
|
+
function cancel() {
|
|
958
|
+
if (timerId !== void 0) {
|
|
959
|
+
clearTimeout(timerId);
|
|
960
|
+
}
|
|
961
|
+
lastInvokeTime = 0;
|
|
962
|
+
lastArgs = lastCallTime = lastThis = timerId = void 0;
|
|
963
|
+
}
|
|
964
|
+
function flush() {
|
|
965
|
+
return timerId === void 0 ? result : trailingEdge(now$1());
|
|
966
|
+
}
|
|
967
|
+
function debounced() {
|
|
968
|
+
var time = now$1(), isInvoking = shouldInvoke(time);
|
|
969
|
+
lastArgs = arguments;
|
|
970
|
+
lastThis = this;
|
|
971
|
+
lastCallTime = time;
|
|
972
|
+
if (isInvoking) {
|
|
973
|
+
if (timerId === void 0) {
|
|
974
|
+
return leadingEdge(lastCallTime);
|
|
975
|
+
}
|
|
976
|
+
if (maxing) {
|
|
977
|
+
clearTimeout(timerId);
|
|
978
|
+
timerId = setTimeout(timerExpired, wait);
|
|
979
|
+
return invokeFunc(lastCallTime);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
if (timerId === void 0) {
|
|
983
|
+
timerId = setTimeout(timerExpired, wait);
|
|
984
|
+
}
|
|
985
|
+
return result;
|
|
986
|
+
}
|
|
987
|
+
debounced.cancel = cancel;
|
|
988
|
+
debounced.flush = flush;
|
|
989
|
+
return debounced;
|
|
990
|
+
}
|
|
991
|
+
function isNil(value) {
|
|
992
|
+
return value == null;
|
|
993
|
+
}
|
|
994
|
+
var Dropdown = defineComponent({
|
|
995
|
+
name: "DEditableSelectDropdown",
|
|
996
|
+
directives: {
|
|
997
|
+
Loading: LoadingDirective
|
|
998
|
+
},
|
|
999
|
+
props: dropdownProps,
|
|
632
1000
|
setup(props, {
|
|
633
|
-
slots
|
|
634
|
-
attrs,
|
|
635
|
-
emit,
|
|
636
|
-
expose
|
|
1001
|
+
slots
|
|
637
1002
|
}) {
|
|
638
|
-
const ns = useNamespace("
|
|
1003
|
+
const ns = useNamespace("editable-select");
|
|
639
1004
|
const {
|
|
640
|
-
|
|
1005
|
+
width,
|
|
1006
|
+
maxHeight
|
|
641
1007
|
} = toRefs(props);
|
|
1008
|
+
const select = inject(SELECT_KEY);
|
|
642
1009
|
const {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
1010
|
+
dropdownRef,
|
|
1011
|
+
hoveringIndex,
|
|
1012
|
+
handleOptionSelect,
|
|
1013
|
+
loadMore,
|
|
1014
|
+
emptyText
|
|
1015
|
+
} = select;
|
|
1016
|
+
const isHovering = (index2) => {
|
|
1017
|
+
return hoveringIndex.value === index2;
|
|
1018
|
+
};
|
|
1019
|
+
const isDisabled = (option) => {
|
|
1020
|
+
return select.disabledKey ? !!option[select.disabledKey] : false;
|
|
1021
|
+
};
|
|
1022
|
+
const debounceLoadMore = debounce(loadMore, 300);
|
|
1023
|
+
const onScroll = () => {
|
|
1024
|
+
debounceLoadMore();
|
|
1025
|
+
};
|
|
1026
|
+
const renderOption = () => {
|
|
1027
|
+
if (props.options.length === 0) {
|
|
1028
|
+
return createVNode("li", {
|
|
1029
|
+
"class": ns.em("item", "no-data-tip")
|
|
1030
|
+
}, [slots.noResultItem ? slots.noResultItem() : emptyText.value]);
|
|
1031
|
+
}
|
|
1032
|
+
return props.options.map((option, index2) => {
|
|
1033
|
+
return createVNode(Option, {
|
|
1034
|
+
"label": option.label,
|
|
1035
|
+
"value": option.value,
|
|
1036
|
+
"hovering": isHovering(index2),
|
|
1037
|
+
"disabled": isDisabled(option),
|
|
1038
|
+
"onSelect": () => {
|
|
1039
|
+
handleOptionSelect(option, true);
|
|
1040
|
+
}
|
|
1041
|
+
}, slots.item ? {
|
|
1042
|
+
default: () => renderSlot(useSlots(), "item", {
|
|
1043
|
+
option,
|
|
1044
|
+
index: index2
|
|
1045
|
+
})
|
|
1046
|
+
} : {});
|
|
1047
|
+
});
|
|
1048
|
+
};
|
|
650
1049
|
return () => {
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
"
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
"
|
|
658
|
-
|
|
659
|
-
"
|
|
660
|
-
|
|
661
|
-
|
|
1050
|
+
return withDirectives(createVNode("div", {
|
|
1051
|
+
"class": ns.e("dropdown"),
|
|
1052
|
+
"style": {
|
|
1053
|
+
width: `${width == null ? void 0 : width.value}px`
|
|
1054
|
+
}
|
|
1055
|
+
}, [createVNode("div", {
|
|
1056
|
+
"ref": dropdownRef,
|
|
1057
|
+
"class": ns.e("inner"),
|
|
1058
|
+
"style": {
|
|
1059
|
+
maxHeight: `${maxHeight == null ? void 0 : maxHeight.value}px`
|
|
1060
|
+
},
|
|
1061
|
+
"onScroll": onScroll
|
|
1062
|
+
}, [renderOption()])]), [[resolveDirective("loading"), select.loading.value]]);
|
|
662
1063
|
};
|
|
663
1064
|
}
|
|
664
1065
|
});
|
|
665
|
-
function useCacheFilteredOptions(filteredOptions) {
|
|
666
|
-
const cacheFilteredOptions = computed(() => {
|
|
667
|
-
const map = /* @__PURE__ */ new Map();
|
|
668
|
-
filteredOptions.value.forEach((item) => {
|
|
669
|
-
map.set(item, item.value);
|
|
670
|
-
});
|
|
671
|
-
return map;
|
|
672
|
-
});
|
|
673
|
-
const getOptionValue = (option) => cacheFilteredOptions.value.get(option);
|
|
674
|
-
return {
|
|
675
|
-
getOptionValue
|
|
676
|
-
};
|
|
677
|
-
}
|
|
678
1066
|
function deepAssign(...objects) {
|
|
679
|
-
const
|
|
1067
|
+
const isObject2 = (obj) => obj && typeof obj === "object";
|
|
680
1068
|
return objects.reduce((prev, from) => {
|
|
681
1069
|
Object.keys(from).forEach((key) => {
|
|
682
1070
|
const pVal = prev[key];
|
|
683
1071
|
const oVal = from[key];
|
|
684
1072
|
if (Array.isArray(pVal) && Array.isArray(oVal)) {
|
|
685
1073
|
prev[key] = Array.from(/* @__PURE__ */ new Set([...oVal, ...pVal]));
|
|
686
|
-
} else if (
|
|
1074
|
+
} else if (isObject2(pVal) && isObject2(oVal)) {
|
|
687
1075
|
prev[key] = deepAssign(pVal, oVal);
|
|
688
1076
|
} else {
|
|
689
1077
|
prev[key] = oVal;
|
|
@@ -844,167 +1232,454 @@ function createI18nTranslate(name, app, newPrefix) {
|
|
|
844
1232
|
return message;
|
|
845
1233
|
};
|
|
846
1234
|
}
|
|
1235
|
+
function useSelectStates() {
|
|
1236
|
+
return reactive({
|
|
1237
|
+
hoveringIndex: -1,
|
|
1238
|
+
selectedIndex: -1,
|
|
1239
|
+
query: "",
|
|
1240
|
+
inputValue: "",
|
|
1241
|
+
selectedLabel: "",
|
|
1242
|
+
isFocus: false,
|
|
1243
|
+
visible: false,
|
|
1244
|
+
softFocus: false,
|
|
1245
|
+
isSilentBlur: false,
|
|
1246
|
+
inputHovering: false
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
function useSelect(dropdownRef, props, states, setSoftFocus, ctx) {
|
|
1250
|
+
const app = getCurrentInstance();
|
|
1251
|
+
const t = createI18nTranslate("DEditableSelect", app);
|
|
1252
|
+
const cachedOptions = ref(props.options);
|
|
1253
|
+
const filteredOptions = computed(() => {
|
|
1254
|
+
return cachedOptions.value.filter((option) => {
|
|
1255
|
+
return option.label.toLocaleLowerCase().includes(states.query.toLocaleLowerCase().trim());
|
|
1256
|
+
});
|
|
1257
|
+
});
|
|
1258
|
+
const emptyText = computed(() => {
|
|
1259
|
+
let text = "";
|
|
1260
|
+
props.remote ? text = t("noData") : text = t("noRelatedRecords");
|
|
1261
|
+
return text;
|
|
1262
|
+
});
|
|
1263
|
+
const showClearable = computed(() => {
|
|
1264
|
+
const hasModelValue = !isNil(props.modelValue) && props.modelValue !== "";
|
|
1265
|
+
return props.allowClear && !props.disabled && states.inputHovering && hasModelValue;
|
|
1266
|
+
});
|
|
1267
|
+
const toggleMenu = () => {
|
|
1268
|
+
if (!props.disabled) {
|
|
1269
|
+
states.visible = !states.visible;
|
|
1270
|
+
}
|
|
1271
|
+
};
|
|
1272
|
+
const updateIndex = (index2) => {
|
|
1273
|
+
states.hoveringIndex = index2;
|
|
1274
|
+
states.selectedIndex = index2;
|
|
1275
|
+
};
|
|
1276
|
+
const setSelected = () => {
|
|
1277
|
+
const options = cachedOptions.value;
|
|
1278
|
+
if (!isNil(props.modelValue)) {
|
|
1279
|
+
const index2 = options.findIndex((option) => option.value === props.modelValue);
|
|
1280
|
+
if (index2 !== -1) {
|
|
1281
|
+
states.inputValue = options[index2].label;
|
|
1282
|
+
states.selectedLabel = options[index2].label;
|
|
1283
|
+
updateIndex(index2);
|
|
1284
|
+
} else {
|
|
1285
|
+
states.inputValue = `${props.modelValue}`;
|
|
1286
|
+
states.selectedLabel = `${props.modelValue}`;
|
|
1287
|
+
}
|
|
1288
|
+
} else {
|
|
1289
|
+
states.inputValue = "";
|
|
1290
|
+
}
|
|
1291
|
+
};
|
|
1292
|
+
const handleOptionSelect = (option, byClick) => {
|
|
1293
|
+
ctx.emit("update:modelValue", option.value);
|
|
1294
|
+
ctx.emit("change", option.value);
|
|
1295
|
+
states.isSilentBlur = byClick;
|
|
1296
|
+
setSoftFocus();
|
|
1297
|
+
states.visible = false;
|
|
1298
|
+
};
|
|
1299
|
+
const scrollToItem = (idx) => {
|
|
1300
|
+
const ul = dropdownRef.value;
|
|
1301
|
+
const li = ul.children[idx];
|
|
1302
|
+
nextTick(() => {
|
|
1303
|
+
if (li.scrollIntoViewIfNeeded) {
|
|
1304
|
+
li.scrollIntoViewIfNeeded(false);
|
|
1305
|
+
} else {
|
|
1306
|
+
const containerInfo = ul.getBoundingClientRect();
|
|
1307
|
+
const elementInfo = li.getBoundingClientRect();
|
|
1308
|
+
if (elementInfo.bottom > containerInfo.bottom || elementInfo.top < containerInfo.top) {
|
|
1309
|
+
li.scrollIntoView(false);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
});
|
|
1313
|
+
};
|
|
1314
|
+
watch(() => states.visible, (visible) => {
|
|
1315
|
+
if (visible) {
|
|
1316
|
+
states.selectedIndex !== -1 && nextTick(() => {
|
|
1317
|
+
scrollToItem(states.selectedIndex);
|
|
1318
|
+
});
|
|
1319
|
+
} else {
|
|
1320
|
+
states.query = "";
|
|
1321
|
+
states.inputValue = states.selectedLabel;
|
|
1322
|
+
}
|
|
1323
|
+
ctx.emit("visibleChange", visible);
|
|
1324
|
+
});
|
|
1325
|
+
watch(() => props.modelValue, () => {
|
|
1326
|
+
setSelected();
|
|
1327
|
+
});
|
|
1328
|
+
watch(() => props.options, (newOptions) => {
|
|
1329
|
+
if (newOptions.length !== 0) {
|
|
1330
|
+
cachedOptions.value = newOptions;
|
|
1331
|
+
}
|
|
1332
|
+
});
|
|
1333
|
+
onMounted(() => {
|
|
1334
|
+
setSelected();
|
|
1335
|
+
});
|
|
1336
|
+
return {
|
|
1337
|
+
cachedOptions,
|
|
1338
|
+
filteredOptions,
|
|
1339
|
+
emptyText,
|
|
1340
|
+
showClearable,
|
|
1341
|
+
toggleMenu,
|
|
1342
|
+
handleOptionSelect,
|
|
1343
|
+
scrollToItem
|
|
1344
|
+
};
|
|
1345
|
+
}
|
|
1346
|
+
const EVENT_CODE = {
|
|
1347
|
+
tab: "Tab",
|
|
1348
|
+
enter: "Enter",
|
|
1349
|
+
up: "ArrowUp",
|
|
1350
|
+
down: "ArrowDown",
|
|
1351
|
+
esc: "Escape"
|
|
1352
|
+
};
|
|
1353
|
+
function useKeyboardSelect(props, states, filteredOptions, scrollToItem, handleOptionSelect) {
|
|
1354
|
+
const updateHoveringIndex = (index2) => {
|
|
1355
|
+
states.hoveringIndex = index2;
|
|
1356
|
+
};
|
|
1357
|
+
const onKeyboardNavigate = (direction, hoverIndex = states.hoveringIndex) => {
|
|
1358
|
+
if (!states.visible) {
|
|
1359
|
+
states.visible = true;
|
|
1360
|
+
return;
|
|
1361
|
+
}
|
|
1362
|
+
if (filteredOptions.value.length === 0 || props.loading) {
|
|
1363
|
+
return;
|
|
1364
|
+
}
|
|
1365
|
+
let newIndex = 0;
|
|
1366
|
+
if (direction === "ArrowDown") {
|
|
1367
|
+
newIndex = hoverIndex + 1;
|
|
1368
|
+
if (newIndex > filteredOptions.value.length - 1) {
|
|
1369
|
+
newIndex = 0;
|
|
1370
|
+
}
|
|
1371
|
+
} else if (direction === "ArrowUp") {
|
|
1372
|
+
newIndex = hoverIndex - 1;
|
|
1373
|
+
if (newIndex < 0) {
|
|
1374
|
+
newIndex = filteredOptions.value.length - 1;
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
const option = filteredOptions.value[newIndex];
|
|
1378
|
+
if (option[props.disabledKey]) {
|
|
1379
|
+
return onKeyboardNavigate(direction, newIndex);
|
|
1380
|
+
} else {
|
|
1381
|
+
updateHoveringIndex(newIndex);
|
|
1382
|
+
scrollToItem(newIndex);
|
|
1383
|
+
}
|
|
1384
|
+
};
|
|
1385
|
+
const onEscOrTab = () => {
|
|
1386
|
+
states.visible = false;
|
|
1387
|
+
};
|
|
1388
|
+
const onKeyboardSelect = () => {
|
|
1389
|
+
if (!states.visible) {
|
|
1390
|
+
return states.visible = true;
|
|
1391
|
+
}
|
|
1392
|
+
const option = filteredOptions.value[states.hoveringIndex];
|
|
1393
|
+
if (option) {
|
|
1394
|
+
handleOptionSelect(option, false);
|
|
1395
|
+
}
|
|
1396
|
+
};
|
|
1397
|
+
const onKeydown = (e) => {
|
|
1398
|
+
const keyCode = e.key || e.code;
|
|
1399
|
+
const { tab, esc, down, up, enter } = EVENT_CODE;
|
|
1400
|
+
if (keyCode === up || keyCode === down) {
|
|
1401
|
+
e.preventDefault();
|
|
1402
|
+
}
|
|
1403
|
+
switch (keyCode) {
|
|
1404
|
+
case up:
|
|
1405
|
+
onKeyboardNavigate("ArrowUp");
|
|
1406
|
+
break;
|
|
1407
|
+
case down:
|
|
1408
|
+
onKeyboardNavigate("ArrowDown");
|
|
1409
|
+
break;
|
|
1410
|
+
case esc:
|
|
1411
|
+
case tab:
|
|
1412
|
+
onEscOrTab();
|
|
1413
|
+
break;
|
|
1414
|
+
case enter:
|
|
1415
|
+
onKeyboardSelect();
|
|
1416
|
+
break;
|
|
1417
|
+
}
|
|
1418
|
+
};
|
|
1419
|
+
return {
|
|
1420
|
+
onKeydown
|
|
1421
|
+
};
|
|
1422
|
+
}
|
|
1423
|
+
function useInputRender(props, states) {
|
|
1424
|
+
const ns = useNamespace("editable-select-input");
|
|
1425
|
+
const inputClasses = computed(() => ({
|
|
1426
|
+
[ns.b()]: true,
|
|
1427
|
+
[ns.m("sm")]: props.size === "sm",
|
|
1428
|
+
[ns.m("lg")]: props.size === "lg",
|
|
1429
|
+
[ns.m("open")]: states.visible
|
|
1430
|
+
}));
|
|
1431
|
+
const inputWrapperClasses = computed(() => ({
|
|
1432
|
+
[ns.e("wrapper")]: true,
|
|
1433
|
+
[ns.em("wrapper", "focus")]: states.isFocus,
|
|
1434
|
+
[ns.em("wrapper", "disabled")]: props.disabled
|
|
1435
|
+
}));
|
|
1436
|
+
const inputInnerClasses = computed(() => ({
|
|
1437
|
+
[ns.e("inner")]: true
|
|
1438
|
+
}));
|
|
1439
|
+
const inputPlaceholderClasses = computed(() => ({
|
|
1440
|
+
[ns.e("placeholder")]: true
|
|
1441
|
+
}));
|
|
1442
|
+
const inputSuffixClasses = computed(() => ({
|
|
1443
|
+
[ns.e("suffix")]: true
|
|
1444
|
+
}));
|
|
1445
|
+
return {
|
|
1446
|
+
inputClasses,
|
|
1447
|
+
inputWrapperClasses,
|
|
1448
|
+
inputInnerClasses,
|
|
1449
|
+
inputPlaceholderClasses,
|
|
1450
|
+
inputSuffixClasses
|
|
1451
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
function useInputEvent(inputRef, props, states, ctx) {
|
|
1454
|
+
const delay = computed(() => props.remote ? 300 : 0);
|
|
1455
|
+
const setSoftFocus = () => {
|
|
1456
|
+
var _a;
|
|
1457
|
+
const _input = inputRef.value;
|
|
1458
|
+
if (_input) {
|
|
1459
|
+
(_a = _input.focus) == null ? void 0 : _a.call(_input);
|
|
1460
|
+
}
|
|
1461
|
+
};
|
|
1462
|
+
const handleFocus = (e) => {
|
|
1463
|
+
if (!states.softFocus) {
|
|
1464
|
+
ctx.emit("focus", e);
|
|
1465
|
+
states.isFocus = true;
|
|
1466
|
+
} else {
|
|
1467
|
+
states.softFocus = false;
|
|
1468
|
+
}
|
|
1469
|
+
};
|
|
1470
|
+
const handleBlur = async (e) => {
|
|
1471
|
+
if (states.isSilentBlur) {
|
|
1472
|
+
states.isSilentBlur = false;
|
|
1473
|
+
} else {
|
|
1474
|
+
ctx.emit("blur", e);
|
|
1475
|
+
states.isFocus = true;
|
|
1476
|
+
}
|
|
1477
|
+
states.softFocus = false;
|
|
1478
|
+
};
|
|
1479
|
+
const updateInputValue = (value) => {
|
|
1480
|
+
states.inputValue = value;
|
|
1481
|
+
};
|
|
1482
|
+
const handleQueryChange = (value) => {
|
|
1483
|
+
if (props.remote && isFunction(props.remoteMethod)) {
|
|
1484
|
+
props.remoteMethod(value);
|
|
1485
|
+
} else if (isFunction(props.filterMethod)) {
|
|
1486
|
+
props.filterMethod(value);
|
|
1487
|
+
}
|
|
1488
|
+
};
|
|
1489
|
+
const handleInputChange = () => {
|
|
1490
|
+
states.query = states.inputValue;
|
|
1491
|
+
handleQueryChange(states.query);
|
|
1492
|
+
};
|
|
1493
|
+
const debouncedOnInputChange = debounce(handleInputChange, delay.value);
|
|
1494
|
+
const onInput = (e) => {
|
|
1495
|
+
const value = e.target.value;
|
|
1496
|
+
updateInputValue(value);
|
|
1497
|
+
if (states.inputValue.length > 0 && !states.visible) {
|
|
1498
|
+
states.visible = true;
|
|
1499
|
+
}
|
|
1500
|
+
if (props.remote) {
|
|
1501
|
+
debouncedOnInputChange();
|
|
1502
|
+
} else {
|
|
1503
|
+
handleInputChange();
|
|
1504
|
+
}
|
|
1505
|
+
};
|
|
1506
|
+
const onMouseenter = () => {
|
|
1507
|
+
states.inputHovering = true;
|
|
1508
|
+
};
|
|
1509
|
+
const onMouseleave = () => {
|
|
1510
|
+
states.inputHovering = false;
|
|
1511
|
+
};
|
|
1512
|
+
const handleClear = () => {
|
|
1513
|
+
ctx.emit("update:modelValue", "");
|
|
1514
|
+
ctx.emit("change", "");
|
|
1515
|
+
ctx.emit("clear");
|
|
1516
|
+
states.hoveringIndex = -1;
|
|
1517
|
+
states.visible = false;
|
|
1518
|
+
};
|
|
1519
|
+
return {
|
|
1520
|
+
blur,
|
|
1521
|
+
setSoftFocus,
|
|
1522
|
+
handleFocus,
|
|
1523
|
+
handleBlur,
|
|
1524
|
+
handleClear,
|
|
1525
|
+
onInput,
|
|
1526
|
+
onMouseenter,
|
|
1527
|
+
onMouseleave
|
|
1528
|
+
};
|
|
1529
|
+
}
|
|
1530
|
+
function useLazyLoad(dropdownRef, props, ctx) {
|
|
1531
|
+
const { enableLazyLoad } = toRefs(props);
|
|
1532
|
+
const loadMore = () => {
|
|
1533
|
+
if (!dropdownRef.value || !enableLazyLoad.value) {
|
|
1534
|
+
return;
|
|
1535
|
+
}
|
|
1536
|
+
if ((dropdownRef == null ? void 0 : dropdownRef.value.clientHeight) + dropdownRef.value.scrollTop >= dropdownRef.value.scrollHeight - 12) {
|
|
1537
|
+
ctx.emit("loadMore");
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
return { loadMore };
|
|
1541
|
+
}
|
|
1542
|
+
var editableSelect = "";
|
|
1543
|
+
function _isSlot(s) {
|
|
1544
|
+
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
|
|
1545
|
+
}
|
|
847
1546
|
var EditableSelect = defineComponent({
|
|
848
1547
|
name: "DEditableSelect",
|
|
849
|
-
directives: {
|
|
850
|
-
ClickOutside: clickoutsideDirective,
|
|
851
|
-
Loading: LoadingDirective
|
|
852
|
-
},
|
|
853
1548
|
props: editableSelectProps,
|
|
854
|
-
emits: ["update:modelValue", "
|
|
855
|
-
setup(props,
|
|
856
|
-
const app = getCurrentInstance();
|
|
857
|
-
const t = createI18nTranslate("DEditableSelect", app);
|
|
1549
|
+
emits: ["update:modelValue", "focus", "blur", "clear", "change", "visibleChange", "loadMore"],
|
|
1550
|
+
setup(props, ctx) {
|
|
858
1551
|
const ns = useNamespace("editable-select");
|
|
1552
|
+
const inputRef = ref();
|
|
1553
|
+
const originRef = ref();
|
|
859
1554
|
const dropdownRef = ref();
|
|
860
|
-
const
|
|
861
|
-
const
|
|
862
|
-
const selectedIndex = ref(0);
|
|
863
|
-
const position = ref(["bottom"]);
|
|
864
|
-
const visible = ref(false);
|
|
865
|
-
const inputValue = ref(props.modelValue);
|
|
866
|
-
const loading2 = ref(props.loading);
|
|
1555
|
+
const overlayRef = ref();
|
|
1556
|
+
const states = useSelectStates();
|
|
867
1557
|
const {
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
1558
|
+
appendToBody,
|
|
1559
|
+
disabled,
|
|
1560
|
+
modelValue,
|
|
1561
|
+
position,
|
|
1562
|
+
placeholder
|
|
1563
|
+
} = toRefs(props);
|
|
871
1564
|
const {
|
|
872
|
-
|
|
873
|
-
|
|
1565
|
+
onInput,
|
|
1566
|
+
onMouseenter,
|
|
1567
|
+
onMouseleave,
|
|
1568
|
+
setSoftFocus,
|
|
1569
|
+
handleBlur,
|
|
1570
|
+
handleFocus,
|
|
1571
|
+
handleClear
|
|
1572
|
+
} = useInputEvent(inputRef, props, states, ctx);
|
|
874
1573
|
const {
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
text = t("noRelatedRecords");
|
|
883
|
-
}
|
|
884
|
-
return text;
|
|
885
|
-
});
|
|
886
|
-
watch(() => props.loading, (newVal) => {
|
|
887
|
-
loading2.value = newVal;
|
|
888
|
-
});
|
|
889
|
-
const toggleMenu = () => {
|
|
890
|
-
visible.value = !visible.value;
|
|
891
|
-
};
|
|
892
|
-
const closeMenu = () => {
|
|
893
|
-
visible.value = false;
|
|
894
|
-
};
|
|
1574
|
+
filteredOptions,
|
|
1575
|
+
emptyText,
|
|
1576
|
+
showClearable,
|
|
1577
|
+
toggleMenu,
|
|
1578
|
+
handleOptionSelect,
|
|
1579
|
+
scrollToItem
|
|
1580
|
+
} = useSelect(dropdownRef, props, states, setSoftFocus, ctx);
|
|
895
1581
|
const {
|
|
896
|
-
|
|
897
|
-
} =
|
|
1582
|
+
onKeydown
|
|
1583
|
+
} = useKeyboardSelect(props, states, filteredOptions, scrollToItem, handleOptionSelect);
|
|
898
1584
|
const {
|
|
899
|
-
|
|
900
|
-
} =
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
1585
|
+
loadMore
|
|
1586
|
+
} = useLazyLoad(dropdownRef, props, ctx);
|
|
1587
|
+
provide(SELECT_KEY, {
|
|
1588
|
+
dropdownRef,
|
|
1589
|
+
disabledKey: props.disabledKey,
|
|
1590
|
+
modelValue,
|
|
1591
|
+
inputValue: toRef(states, "inputValue"),
|
|
1592
|
+
query: toRef(states, "query"),
|
|
1593
|
+
hoveringIndex: toRef(states, "hoveringIndex"),
|
|
1594
|
+
loading: toRef(props, "loading"),
|
|
1595
|
+
emptyText,
|
|
1596
|
+
loadMore,
|
|
1597
|
+
handleOptionSelect,
|
|
1598
|
+
setSoftFocus
|
|
1599
|
+
});
|
|
1600
|
+
onClickOutside(originRef, () => {
|
|
1601
|
+
states.visible = false;
|
|
1602
|
+
states.isFocus = false;
|
|
1603
|
+
}, {
|
|
1604
|
+
ignore: [overlayRef]
|
|
1605
|
+
});
|
|
915
1606
|
const {
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
1607
|
+
inputClasses,
|
|
1608
|
+
inputWrapperClasses,
|
|
1609
|
+
inputInnerClasses,
|
|
1610
|
+
inputSuffixClasses
|
|
1611
|
+
} = useInputRender(props, states);
|
|
1612
|
+
const renderBasicDropdown = () => {
|
|
1613
|
+
return createVNode(Transition, {
|
|
1614
|
+
"name": "fade"
|
|
1615
|
+
}, {
|
|
1616
|
+
default: () => [createVNode(FlexibleOverlay, {
|
|
1617
|
+
"ref": overlayRef,
|
|
1618
|
+
"modelValue": states.visible,
|
|
1619
|
+
"onUpdate:modelValue": ($event) => states.visible = $event,
|
|
1620
|
+
"origin": originRef.value,
|
|
1621
|
+
"position": position.value,
|
|
1622
|
+
"style": {
|
|
1623
|
+
zIndex: "var(--devui-z-index-dropdown, 1052)"
|
|
1624
|
+
}
|
|
1625
|
+
}, {
|
|
1626
|
+
default: () => [createVNode(Dropdown, {
|
|
1627
|
+
"options": filteredOptions.value,
|
|
1628
|
+
"width": props.width,
|
|
1629
|
+
"maxHeight": props.maxHeight
|
|
1630
|
+
}, ctx.slots)]
|
|
1631
|
+
})]
|
|
930
1632
|
});
|
|
931
1633
|
};
|
|
1634
|
+
const renderDropdown = () => {
|
|
1635
|
+
if (appendToBody.value) {
|
|
1636
|
+
let _slot;
|
|
1637
|
+
return createVNode(Teleport, {
|
|
1638
|
+
"to": "body"
|
|
1639
|
+
}, _isSlot(_slot = renderBasicDropdown()) ? _slot : {
|
|
1640
|
+
default: () => [_slot]
|
|
1641
|
+
});
|
|
1642
|
+
} else {
|
|
1643
|
+
return renderBasicDropdown();
|
|
1644
|
+
}
|
|
1645
|
+
};
|
|
932
1646
|
return () => {
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
const inputCls = className(`devui-form-control devui-dropdown-origin`, {
|
|
937
|
-
"devui-dropdown-origin-open": visible.value === true
|
|
938
|
-
});
|
|
939
|
-
return withDirectives(createVNode("div", {
|
|
940
|
-
"class": selectCls,
|
|
941
|
-
"ref": origin,
|
|
1647
|
+
return createVNode("div", {
|
|
1648
|
+
"ref": originRef,
|
|
1649
|
+
"class": ns.b(),
|
|
942
1650
|
"style": {
|
|
943
1651
|
width: props.width + "px"
|
|
944
|
-
}
|
|
1652
|
+
},
|
|
1653
|
+
"onClick": toggleMenu
|
|
1654
|
+
}, [createVNode("div", {
|
|
1655
|
+
"class": inputClasses.value,
|
|
1656
|
+
"onMouseenter": onMouseenter,
|
|
1657
|
+
"onMouseleave": onMouseleave
|
|
1658
|
+
}, [createVNode("div", {
|
|
1659
|
+
"class": inputWrapperClasses.value
|
|
945
1660
|
}, [createVNode("input", {
|
|
946
|
-
"
|
|
947
|
-
"
|
|
948
|
-
"
|
|
949
|
-
"
|
|
950
|
-
"value": inputValue
|
|
951
|
-
"
|
|
952
|
-
"
|
|
953
|
-
"
|
|
1661
|
+
"ref": inputRef,
|
|
1662
|
+
"class": inputInnerClasses.value,
|
|
1663
|
+
"disabled": disabled.value,
|
|
1664
|
+
"placeholder": placeholder.value,
|
|
1665
|
+
"value": states.inputValue,
|
|
1666
|
+
"type": "text",
|
|
1667
|
+
"onInput": onInput,
|
|
1668
|
+
"onFocus": handleFocus,
|
|
1669
|
+
"onBlur": handleBlur,
|
|
1670
|
+
"onKeydown": onKeydown
|
|
954
1671
|
}, null), createVNode("span", {
|
|
955
|
-
"class":
|
|
956
|
-
}, [createVNode("span", {
|
|
957
|
-
"class": "
|
|
958
|
-
"onClick": handleClear
|
|
959
|
-
}, [createVNode(
|
|
1672
|
+
"class": inputSuffixClasses.value
|
|
1673
|
+
}, [withDirectives(createVNode("span", {
|
|
1674
|
+
"class": ns.e("clear-icon"),
|
|
1675
|
+
"onClick": withModifiers(handleClear, ["stop"])
|
|
1676
|
+
}, [createVNode(Icon, {
|
|
960
1677
|
"name": "icon-remove"
|
|
961
|
-
}, null)]), createVNode("span", {
|
|
962
|
-
"class": "
|
|
963
|
-
}, [createVNode(
|
|
1678
|
+
}, null)]), [[vShow, showClearable.value]]), withDirectives(createVNode("span", {
|
|
1679
|
+
"class": ns.e("arrow-icon")
|
|
1680
|
+
}, [createVNode(Icon, {
|
|
964
1681
|
"name": "select-arrow"
|
|
965
|
-
}, null)])]),
|
|
966
|
-
"to": "body"
|
|
967
|
-
}, {
|
|
968
|
-
default: () => [createVNode(Transition, {
|
|
969
|
-
"name": "fade"
|
|
970
|
-
}, {
|
|
971
|
-
default: () => [createVNode(FlexibleOverlay, {
|
|
972
|
-
"origin": origin.value,
|
|
973
|
-
"modelValue": visible.value,
|
|
974
|
-
"onUpdate:modelValue": ($event) => visible.value = $event,
|
|
975
|
-
"position": position.value,
|
|
976
|
-
"style": {
|
|
977
|
-
zIndex: "var(--devui-z-index-dropdown, 1052)"
|
|
978
|
-
}
|
|
979
|
-
}, {
|
|
980
|
-
default: () => [createVNode("div", {
|
|
981
|
-
"style": {
|
|
982
|
-
width: props.width + "px"
|
|
983
|
-
},
|
|
984
|
-
"class": `${ns.e("menu")}`
|
|
985
|
-
}, [withDirectives(createVNode("div", {
|
|
986
|
-
"class": `devui-dropdown-menu`
|
|
987
|
-
}, [createVNode("ul", {
|
|
988
|
-
"ref": dropdownRef,
|
|
989
|
-
"class": `${ns.em("list", "unstyled")} devui-scrollbar scroll-height`,
|
|
990
|
-
"style": {
|
|
991
|
-
maxHeight: props.maxHeight + "px"
|
|
992
|
-
},
|
|
993
|
-
"onScroll": loadMore
|
|
994
|
-
}, [filteredOptions.value.map((option, index2) => {
|
|
995
|
-
return createVNode("li", {
|
|
996
|
-
"class": getItemCls(option, index2),
|
|
997
|
-
"onClick": (e) => {
|
|
998
|
-
e.stopPropagation();
|
|
999
|
-
handleClick(option, index2);
|
|
1000
|
-
}
|
|
1001
|
-
}, [ctx2.slots.item ? ctx2.slots.item(option) : option.label]);
|
|
1002
|
-
}), withDirectives(createVNode("div", {
|
|
1003
|
-
"class": "devui-no-data-tip"
|
|
1004
|
-
}, [ctx2.slots.noResultItem ? ctx2.slots.noResultItem(inputValue.value) : emptyText.value]), [[vShow, !filteredOptions.value.length]])])]), [[vShow, visible.value], [resolveDirective("loading"), props.loading]])])]
|
|
1005
|
-
})]
|
|
1006
|
-
})]
|
|
1007
|
-
})]), [[resolveDirective("click-outside"), closeMenu]]);
|
|
1682
|
+
}, null)]), [[vShow, !showClearable.value]])])])]), renderDropdown()]);
|
|
1008
1683
|
};
|
|
1009
1684
|
}
|
|
1010
1685
|
});
|
|
@@ -1016,4 +1691,4 @@ var index = {
|
|
|
1016
1691
|
app.component(EditableSelect.name, EditableSelect);
|
|
1017
1692
|
}
|
|
1018
1693
|
};
|
|
1019
|
-
export { EditableSelect, index as default, editableSelectProps };
|
|
1694
|
+
export { EditableSelect, SELECT_KEY, index as default, editableSelectProps };
|