vue-devui 1.0.0-beta.13 → 1.0.0-beta.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1121 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ var __publicField = (obj, key, value) => {
18
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
19
+ return value;
20
+ };
21
+ import { ref, nextTick, defineComponent, createVNode, h, render, inject, withDirectives, createTextVNode, resolveDirective, vShow, Teleport, Transition, renderSlot, isVNode, computed, onMounted, watch, onUnmounted, reactive, toRef, isRef, toRefs, provide } from "vue";
22
+ const defaultFormatter = (item) => item ? item.label || item.toString() : "";
23
+ const defaultValueParse = (item) => item;
24
+ const autoCompleteProps = {
25
+ modelValue: {
26
+ type: String,
27
+ default: ""
28
+ },
29
+ source: {
30
+ type: Array,
31
+ default: null
32
+ },
33
+ allowEmptyValueSearch: {
34
+ type: Boolean,
35
+ default: false
36
+ },
37
+ appendToBody: {
38
+ type: Boolean,
39
+ default: false
40
+ },
41
+ appendToBodyDirections: {
42
+ type: Object,
43
+ default: () => ({
44
+ originX: "left",
45
+ originY: "bottom",
46
+ overlayX: "left",
47
+ overlayY: "top"
48
+ })
49
+ },
50
+ disabled: {
51
+ type: Boolean,
52
+ default: false
53
+ },
54
+ delay: {
55
+ type: Number,
56
+ default: 300
57
+ },
58
+ disabledKey: {
59
+ type: String,
60
+ default: null
61
+ },
62
+ formatter: {
63
+ type: Function,
64
+ default: defaultFormatter
65
+ },
66
+ isSearching: {
67
+ type: Boolean,
68
+ default: false
69
+ },
70
+ sceneType: {
71
+ type: String,
72
+ default: null
73
+ },
74
+ searchFn: {
75
+ type: Function,
76
+ default: null
77
+ },
78
+ tipsText: {
79
+ type: String,
80
+ default: "\u6700\u8FD1\u8F93\u5165"
81
+ },
82
+ latestSource: {
83
+ type: Array,
84
+ default: null
85
+ },
86
+ valueParser: {
87
+ type: Function,
88
+ default: defaultValueParse
89
+ },
90
+ enableLazyLoad: {
91
+ type: Boolean,
92
+ default: false
93
+ },
94
+ dAutoCompleteWidth: {
95
+ type: Number,
96
+ default: null
97
+ },
98
+ showAnimation: {
99
+ type: Boolean,
100
+ default: true
101
+ },
102
+ maxHeight: {
103
+ type: Number,
104
+ default: 300
105
+ },
106
+ transInputFocusEmit: {
107
+ type: Function,
108
+ default: null
109
+ },
110
+ selectValue: {
111
+ type: Function,
112
+ default: null
113
+ },
114
+ loadMore: {
115
+ type: Function,
116
+ default: null
117
+ }
118
+ };
119
+ const DropdownPropsKey = Symbol("DropdownPropsKey");
120
+ function useCustomTemplate(ctx2, modelValue) {
121
+ const itemTemplate = (item, index2) => {
122
+ const arr = { item, index: index2 };
123
+ if (ctx2.slots.itemTemplate) {
124
+ return ctx2.slots.itemTemplate(arr);
125
+ }
126
+ return null;
127
+ };
128
+ const noResultItemTemplate = () => {
129
+ if (ctx2.slots.noResultItemTemplate) {
130
+ return ctx2.slots.noResultItemTemplate(modelValue.value);
131
+ }
132
+ return null;
133
+ };
134
+ const searchingTemplate = () => {
135
+ if (ctx2.slots.searchingTemplate) {
136
+ return ctx2.slots.searchingTemplate(modelValue.value);
137
+ }
138
+ return null;
139
+ };
140
+ const customRenderSolts = () => {
141
+ const slots = {};
142
+ if (ctx2.slots.itemTemplate) {
143
+ slots["itemTemplate"] = itemTemplate;
144
+ }
145
+ if (ctx2.slots.noResultItemTemplate) {
146
+ slots["noResultItemTemplate"] = noResultItemTemplate;
147
+ }
148
+ if (ctx2.slots.searchingTemplate) {
149
+ slots["searchingTemplate"] = searchingTemplate;
150
+ }
151
+ return slots;
152
+ };
153
+ return { customRenderSolts };
154
+ }
155
+ function useSearchFn(ctx2, allowEmptyValueSearch, source, searchFn, formatter) {
156
+ const searchList = ref([]);
157
+ const showNoResultItemTemplate = ref(false);
158
+ const handleSearch = async (term, enableLazyLoad) => {
159
+ if (term == "" && !allowEmptyValueSearch.value) {
160
+ searchList.value = [];
161
+ showNoResultItemTemplate.value = false;
162
+ return;
163
+ }
164
+ let arr = [];
165
+ term = term.toLowerCase();
166
+ if (enableLazyLoad) {
167
+ arr = source.value;
168
+ } else if (!searchFn.value) {
169
+ source.value.forEach((item) => {
170
+ let cur = formatter.value(item);
171
+ cur = cur.toLowerCase();
172
+ if (cur.startsWith(term)) {
173
+ arr.push(item);
174
+ }
175
+ });
176
+ } else {
177
+ arr = await searchFn.value(term);
178
+ }
179
+ searchList.value = arr;
180
+ if (searchList.value.length == 0) {
181
+ showNoResultItemTemplate.value = true;
182
+ } else {
183
+ showNoResultItemTemplate.value = false;
184
+ }
185
+ };
186
+ const recentlyFocus = (latestSource) => {
187
+ if (latestSource) {
188
+ searchList.value = latestSource;
189
+ }
190
+ };
191
+ return {
192
+ handleSearch,
193
+ recentlyFocus,
194
+ searchList,
195
+ showNoResultItemTemplate
196
+ };
197
+ }
198
+ function useInputHandle(ctx2, searchList, showNoResultItemTemplate, modelValue, disabled, delay, handleSearch, transInputFocusEmit, recentlyFocus, latestSource) {
199
+ const visible = ref(false);
200
+ const inputRef = ref();
201
+ const searchStatus = ref(false);
202
+ const debounce = (cb, time) => {
203
+ let timer;
204
+ return (...args) => {
205
+ if (timer) {
206
+ clearTimeout(timer);
207
+ }
208
+ timer = setTimeout(async () => {
209
+ searchStatus.value = true;
210
+ await cb(...args);
211
+ searchStatus.value = false;
212
+ }, time);
213
+ };
214
+ };
215
+ const onInputCb = async (value) => {
216
+ await handleSearch(value);
217
+ visible.value = true;
218
+ };
219
+ const onInputDebounce = debounce(onInputCb, delay.value);
220
+ const onInput = (e) => {
221
+ const inp = e.target;
222
+ searchStatus.value = false;
223
+ showNoResultItemTemplate.value = false;
224
+ ctx2.emit("update:modelValue", inp.value);
225
+ onInputDebounce(inp.value);
226
+ };
227
+ const onFocus = () => {
228
+ handleSearch(modelValue.value);
229
+ recentlyFocus(latestSource.value);
230
+ transInputFocusEmit.value && transInputFocusEmit.value();
231
+ };
232
+ const handleClose = () => {
233
+ visible.value = false;
234
+ searchStatus.value = false;
235
+ showNoResultItemTemplate.value = false;
236
+ };
237
+ const toggleMenu = () => {
238
+ if (!disabled.value) {
239
+ if (visible.value) {
240
+ handleClose();
241
+ } else {
242
+ visible.value = true;
243
+ if (ctx2.slots.noResultItemTemplate && searchList.value.length == 0 && modelValue.value.trim() != "") {
244
+ showNoResultItemTemplate.value = true;
245
+ }
246
+ }
247
+ }
248
+ };
249
+ return {
250
+ handleClose,
251
+ toggleMenu,
252
+ onInput,
253
+ onFocus,
254
+ inputRef,
255
+ visible,
256
+ searchStatus
257
+ };
258
+ }
259
+ function useSelectHandle(ctx2, searchList, selectValue, handleSearch, formatter, handleClose) {
260
+ const selectedIndex = ref(0);
261
+ const getListIndex = (item) => {
262
+ if (searchList.value.length == 0) {
263
+ return 0;
264
+ }
265
+ const ind = searchList.value.indexOf(item);
266
+ return ind == -1 ? 0 : ind;
267
+ };
268
+ const selectOptionClick = async (item) => {
269
+ const cur = formatter.value(item);
270
+ ctx2.emit("update:modelValue", cur);
271
+ handleClose();
272
+ await handleSearch(cur);
273
+ selectedIndex.value = getListIndex(cur);
274
+ selectValue.value && selectValue.value();
275
+ };
276
+ return {
277
+ selectedIndex,
278
+ selectOptionClick
279
+ };
280
+ }
281
+ function useLazyHandle(props, ctx2, handleSearch) {
282
+ const showLoading = ref(false);
283
+ const dropDownRef = ref();
284
+ const loadMore = () => {
285
+ if (!props.enableLazyLoad && showLoading)
286
+ return;
287
+ const dropDownValue = dropDownRef.value;
288
+ const height = dropDownValue.scrollHeight;
289
+ const scrollTop = dropDownValue.clientHeight + dropDownValue.scrollTop;
290
+ if (scrollTop >= height && scrollTop >= props.maxHeight) {
291
+ props.loadMore();
292
+ showLoading.value = true;
293
+ }
294
+ };
295
+ ctx2.expose({ loadFinish });
296
+ async function loadFinish() {
297
+ await handleSearch(props.modelValue, props.enableLazyLoad);
298
+ showLoading.value = false;
299
+ }
300
+ return {
301
+ showLoading,
302
+ dropDownRef,
303
+ loadMore
304
+ };
305
+ }
306
+ function useKeyBoardHandle(dropDownRef, visible, searchList, selectedIndex, searchStatus, showNoResultItemTemplate, selectOptionClick, handleClose) {
307
+ var _a;
308
+ const hoverIndex = ref((_a = selectedIndex.value) != null ? _a : 0);
309
+ const scrollToActive = (index2) => {
310
+ const ul = dropDownRef.value;
311
+ const li = ul.children[index2];
312
+ nextTick(() => {
313
+ if (li.scrollIntoViewIfNeeded) {
314
+ li.scrollIntoViewIfNeeded(false);
315
+ } else {
316
+ const containerInfo = ul.getBoundingClientRect();
317
+ const elementInfo = li.getBoundingClientRect();
318
+ if (elementInfo.bottom > containerInfo.bottom || elementInfo.top < containerInfo.top) {
319
+ li.scrollIntoView(false);
320
+ }
321
+ }
322
+ });
323
+ };
324
+ const handlekeyDown = (e) => {
325
+ var _a2;
326
+ const keyCode = e.key || e.code;
327
+ if (keyCode === "Escape" && (visible.value && searchList.value.length || searchStatus.value || showNoResultItemTemplate.value)) {
328
+ handleClose();
329
+ return;
330
+ }
331
+ const status = visible.value && searchList.value.length && !searchStatus.value && !showNoResultItemTemplate.value;
332
+ if (keyCode === "ArrowDown" && status) {
333
+ if (hoverIndex.value === searchList.value.length - 1) {
334
+ hoverIndex.value = 0;
335
+ scrollToActive(hoverIndex.value);
336
+ return;
337
+ }
338
+ hoverIndex.value = hoverIndex.value + 1;
339
+ scrollToActive(hoverIndex.value);
340
+ } else if (keyCode === "ArrowUp" && status) {
341
+ if (hoverIndex.value === 0) {
342
+ hoverIndex.value = searchList.value.length - 1;
343
+ scrollToActive(hoverIndex.value);
344
+ return;
345
+ }
346
+ hoverIndex.value = hoverIndex.value - 1;
347
+ scrollToActive(hoverIndex.value);
348
+ }
349
+ if (keyCode === "Enter" && status) {
350
+ selectOptionClick(searchList.value[hoverIndex.value]);
351
+ hoverIndex.value = (_a2 = selectedIndex.value) != null ? _a2 : 0;
352
+ return;
353
+ }
354
+ };
355
+ return {
356
+ hoverIndex,
357
+ handlekeyDown
358
+ };
359
+ }
360
+ var autoComplete = "";
361
+ class View {
362
+ constructor() {
363
+ __publicField(this, "top", "50%");
364
+ __publicField(this, "left", "50%");
365
+ }
366
+ }
367
+ const componentProps = {
368
+ message: String,
369
+ backdrop: Boolean,
370
+ view: {
371
+ type: Object,
372
+ default: () => new View()
373
+ },
374
+ zIndex: Number,
375
+ isFull: {
376
+ type: Boolean,
377
+ default: false
378
+ }
379
+ };
380
+ class LoadingProps {
381
+ constructor() {
382
+ __publicField(this, "target");
383
+ __publicField(this, "message");
384
+ __publicField(this, "loadingTemplateRef");
385
+ __publicField(this, "backdrop", true);
386
+ __publicField(this, "positionType", "relative");
387
+ __publicField(this, "view", new View());
388
+ __publicField(this, "zIndex");
389
+ }
390
+ }
391
+ var loading = "";
392
+ var Loading = defineComponent({
393
+ name: "DLoading",
394
+ inheritAttrs: false,
395
+ props: componentProps,
396
+ setup(props) {
397
+ const style = {
398
+ top: props.view.top,
399
+ left: props.view.left,
400
+ zIndex: props.zIndex
401
+ };
402
+ if (!props.message) {
403
+ style.background = "none";
404
+ }
405
+ const isShow = ref(false);
406
+ const open = () => {
407
+ isShow.value = true;
408
+ };
409
+ const close = () => {
410
+ isShow.value = false;
411
+ };
412
+ return {
413
+ style,
414
+ isShow,
415
+ open,
416
+ close
417
+ };
418
+ },
419
+ render() {
420
+ var _a;
421
+ const {
422
+ isShow,
423
+ isFull,
424
+ backdrop,
425
+ style,
426
+ message,
427
+ $slots
428
+ } = this;
429
+ return isShow && createVNode("div", {
430
+ "class": ["devui-loading-contanier", isFull ? "devui-loading--full" : ""]
431
+ }, [((_a = $slots.default) == null ? void 0 : _a.call($slots)) || createVNode("div", {
432
+ "class": "devui-loading-wrapper"
433
+ }, [backdrop ? createVNode("div", {
434
+ "class": "devui-loading-mask"
435
+ }, null) : null, createVNode("div", {
436
+ "style": style,
437
+ "class": "devui-loading-area"
438
+ }, [createVNode("div", {
439
+ "class": "devui-busy-default-spinner"
440
+ }, [createVNode("div", {
441
+ "class": "devui-loading-bar1"
442
+ }, null), createVNode("div", {
443
+ "class": "devui-loading-bar2"
444
+ }, null), createVNode("div", {
445
+ "class": "devui-loading-bar3"
446
+ }, null), createVNode("div", {
447
+ "class": "devui-loading-bar4"
448
+ }, null)]), message ? createVNode("span", {
449
+ "class": "devui-loading-text"
450
+ }, [message]) : null])])]);
451
+ }
452
+ });
453
+ const COMPONENT_CONTAINER_SYMBOL = Symbol("dev_component_container");
454
+ function createComponent(Component, props, children = null) {
455
+ const vnode = h(Component, __spreadValues({}, props), children);
456
+ const container = document.createElement("div");
457
+ vnode[COMPONENT_CONTAINER_SYMBOL] = container;
458
+ render(vnode, container);
459
+ return vnode.component;
460
+ }
461
+ function unmountComponent(ComponnetInstance) {
462
+ render(null, ComponnetInstance == null ? void 0 : ComponnetInstance.vnode[COMPONENT_CONTAINER_SYMBOL]);
463
+ }
464
+ const loadingConstructor = defineComponent(Loading);
465
+ const cacheInstance = new WeakSet();
466
+ const isEmpty = (val) => {
467
+ if (!val)
468
+ return true;
469
+ if (Array.isArray(val))
470
+ return val.length === 0;
471
+ if (val instanceof Set || val instanceof Map)
472
+ return val.size === 0;
473
+ if (val instanceof Promise)
474
+ return false;
475
+ if (typeof val === "object") {
476
+ try {
477
+ return Object.keys(val).length === 0;
478
+ } catch (e) {
479
+ return false;
480
+ }
481
+ }
482
+ return false;
483
+ };
484
+ const getType = (vari) => {
485
+ return Object.prototype.toString.call(vari).slice(8, -1).toLowerCase();
486
+ };
487
+ const isPromise = (value) => {
488
+ const type = getType(value);
489
+ switch (type) {
490
+ case "promise":
491
+ return [value];
492
+ case "array":
493
+ if (value.some((val) => getType(val) !== "promise")) {
494
+ console.error(new TypeError("Binding values should all be of type Promise"));
495
+ return "error";
496
+ }
497
+ return value;
498
+ default:
499
+ return false;
500
+ }
501
+ };
502
+ const unmount = (el) => {
503
+ cacheInstance.delete(el);
504
+ el.instance.proxy.close();
505
+ unmountComponent(el.instance);
506
+ };
507
+ const toggleLoading = (el, binding) => {
508
+ if (binding.value) {
509
+ const vals = isPromise(binding.value);
510
+ if (vals === "error")
511
+ return;
512
+ el.instance.proxy.open();
513
+ el.appendChild(el.mask);
514
+ cacheInstance.add(el);
515
+ if (vals) {
516
+ Promise.all(vals).catch((err) => {
517
+ console.error(new Error("Promise handling errors"), err);
518
+ }).finally(() => {
519
+ unmount(el);
520
+ });
521
+ }
522
+ } else {
523
+ unmount(el);
524
+ }
525
+ };
526
+ const removeAttribute = (el) => {
527
+ el.removeAttribute("zindex");
528
+ el.removeAttribute("positiontype");
529
+ el.removeAttribute("backdrop");
530
+ el.removeAttribute("message");
531
+ el.removeAttribute("view");
532
+ el.removeAttribute("loadingtemplateref");
533
+ };
534
+ const handleProps = (el, vprops) => {
535
+ const props = __spreadValues(__spreadValues({}, new LoadingProps()), vprops);
536
+ const loadingTemplateRef = props.loadingTemplateRef;
537
+ const loadingInstance = createComponent(loadingConstructor, __spreadValues({}, props), loadingTemplateRef ? () => loadingTemplateRef : null);
538
+ el.style.position = props.positionType;
539
+ el.options = props;
540
+ el.instance = loadingInstance;
541
+ el.mask = loadingInstance.proxy.$el;
542
+ };
543
+ const loadingDirective = {
544
+ mounted: function(el, binding, vnode) {
545
+ handleProps(el, vnode.props);
546
+ removeAttribute(el);
547
+ !isEmpty(binding.value) && toggleLoading(el, binding);
548
+ },
549
+ updated: function(el, binding, vnode) {
550
+ if (!isEmpty(binding.value) && cacheInstance.has(el) || isEmpty(binding.value) && !cacheInstance.has(el))
551
+ return;
552
+ !cacheInstance.has(el) && handleProps(el, vnode.props);
553
+ removeAttribute(el);
554
+ toggleLoading(el, binding);
555
+ }
556
+ };
557
+ var DAutoCompleteDropdown = defineComponent({
558
+ name: "DAutoCompleteDropdown",
559
+ directives: {
560
+ dLoading: loadingDirective
561
+ },
562
+ setup(props, ctx2) {
563
+ const propsData = inject(DropdownPropsKey);
564
+ const {
565
+ visible,
566
+ selectedIndex,
567
+ selectOptionClick,
568
+ searchList,
569
+ searchStatus,
570
+ dropDownRef,
571
+ loadMore,
572
+ showLoading,
573
+ showNoResultItemTemplate,
574
+ latestSource,
575
+ modelValue,
576
+ hoverIndex
577
+ } = propsData;
578
+ const {
579
+ disabled,
580
+ maxHeight,
581
+ appendToBody,
582
+ formatter,
583
+ disabledKey,
584
+ isSearching
585
+ } = propsData.props;
586
+ const onSelect = (item) => {
587
+ if (item[disabledKey]) {
588
+ return;
589
+ }
590
+ selectOptionClick(item);
591
+ };
592
+ return () => {
593
+ return withDirectives(createVNode("div", {
594
+ "class": ["devui-dropdown-menu", appendToBody && "devui-dropdown-menu-cdk", disabled && "disabled", latestSource.value && "devui-dropdown-latestSource"]
595
+ }, [createVNode("ul", {
596
+ "ref": dropDownRef,
597
+ "class": "devui-list-unstyled scroll-height",
598
+ "style": {
599
+ maxHeight: `${maxHeight}px`
600
+ },
601
+ "onScroll": loadMore
602
+ }, [isSearching && ctx2.slots.searchingTemplate && searchStatus.value && createVNode("li", {
603
+ "class": "devui-is-searching-template"
604
+ }, [createVNode("div", {
605
+ "class": "devui-no-data-tip"
606
+ }, [ctx2.slots.searchingTemplate()])]), latestSource.value && !modelValue.value && createVNode("li", {
607
+ "class": "devui-popup-tips"
608
+ }, [createTextVNode("\u6700\u8FD1\u8F93\u5165")]), !showNoResultItemTemplate.value && !searchStatus.value && searchList != null && searchList.value.length > 0 && searchList.value.map((item, index2) => {
609
+ return createVNode("li", {
610
+ "onClick": () => onSelect(item),
611
+ "class": ["devui-dropdown-item", selectedIndex.value == index2 && "selected", {
612
+ "disabled": disabledKey && item[disabledKey]
613
+ }, {
614
+ "devui-dropdown-bg": hoverIndex.value == index2
615
+ }],
616
+ "title": formatter(item),
617
+ "key": formatter(item)
618
+ }, [ctx2.slots.itemTemplate ? ctx2.slots.itemTemplate(item, index2) : formatter(item)]);
619
+ }), !searchStatus.value && searchList.value.length == 0 && ctx2.slots.noResultItemTemplate && showNoResultItemTemplate.value && createVNode("li", {
620
+ "class": "devui-no-result-template"
621
+ }, [createVNode("div", {
622
+ "class": "devui-no-data-tip"
623
+ }, [ctx2.slots.noResultItemTemplate()])])])]), [[resolveDirective("dLoading"), showLoading.value], [vShow, visible.value && searchList.value.length > 0 || ctx2.slots.noResultItemTemplate && showNoResultItemTemplate.value || isSearching && ctx2.slots.searchingTemplate && searchStatus.value]]);
624
+ };
625
+ }
626
+ });
627
+ const inBrowser = typeof window !== "undefined";
628
+ function on(element, eventName, handler) {
629
+ if (document.addEventListener) {
630
+ if (element && eventName && handler) {
631
+ element.addEventListener(eventName, handler, false);
632
+ }
633
+ } else {
634
+ if (element && eventName && handler) {
635
+ element.attachEvent("on" + eventName, handler);
636
+ }
637
+ }
638
+ }
639
+ const ctx = Symbol("@@clickoutside");
640
+ const nodeList = new Map();
641
+ let startClick;
642
+ let nid = 0;
643
+ let isFirst = true;
644
+ function createDocumentHandler(el, binding, vnode) {
645
+ if (inBrowser && isFirst) {
646
+ isFirst = false;
647
+ on(document, "mousedown", (e) => {
648
+ startClick = e;
649
+ });
650
+ on(document, "mouseup", (e) => {
651
+ for (const [id, node] of nodeList) {
652
+ node[ctx].documentHandler(e, startClick);
653
+ }
654
+ });
655
+ }
656
+ return function(mouseup, mousedown) {
657
+ if (!vnode || !binding.instance || !mouseup.target || !mousedown.target || el.contains(mouseup.target) || el.contains(mousedown.target) || el === mouseup.target) {
658
+ return;
659
+ }
660
+ el[ctx].bindingFn && el[ctx].bindingFn();
661
+ };
662
+ }
663
+ const clickoutsideDirective = {
664
+ beforeMount: function(el, binding, vnode) {
665
+ nid++;
666
+ nodeList.set(nid, el);
667
+ el[ctx] = {
668
+ nid,
669
+ documentHandler: createDocumentHandler(el, binding, vnode),
670
+ bindingFn: binding.value
671
+ };
672
+ },
673
+ updated: function(el, binding, vnode) {
674
+ el[ctx].documentHandler = createDocumentHandler(el, binding, vnode);
675
+ el[ctx].bindingFn = binding.value;
676
+ },
677
+ unmounted: function(el) {
678
+ nodeList.delete(el[ctx].nid);
679
+ delete el[ctx];
680
+ }
681
+ };
682
+ var overlay = "";
683
+ function _isSlot$1(s) {
684
+ return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
685
+ }
686
+ const CommonOverlay = defineComponent({
687
+ setup(props, ctx2) {
688
+ return () => {
689
+ let _slot;
690
+ return createVNode(Teleport, {
691
+ "to": "#d-overlay-anchor"
692
+ }, {
693
+ default: () => [createVNode(Transition, {
694
+ "name": "devui-overlay-fade"
695
+ }, _isSlot$1(_slot = renderSlot(ctx2.slots, "default")) ? _slot : {
696
+ default: () => [_slot]
697
+ })]
698
+ });
699
+ };
700
+ }
701
+ });
702
+ const overlayProps = {
703
+ visible: {
704
+ type: Boolean
705
+ },
706
+ backgroundBlock: {
707
+ type: Boolean,
708
+ default: false
709
+ },
710
+ backgroundClass: {
711
+ type: String,
712
+ default: ""
713
+ },
714
+ backgroundStyle: {
715
+ type: [String, Object]
716
+ },
717
+ onBackdropClick: {
718
+ type: Function
719
+ },
720
+ backdropClose: {
721
+ type: Boolean,
722
+ default: true
723
+ },
724
+ hasBackdrop: {
725
+ type: Boolean,
726
+ default: true
727
+ }
728
+ };
729
+ const overlayEmits = ["update:visible", "backdropClick"];
730
+ const flexibleOverlayProps = __spreadValues({
731
+ origin: {
732
+ type: Object,
733
+ require: true
734
+ },
735
+ position: {
736
+ type: Object,
737
+ default: () => ({
738
+ originX: "left",
739
+ originY: "top",
740
+ overlayX: "left",
741
+ overlayY: "top"
742
+ })
743
+ }
744
+ }, overlayProps);
745
+ function useOverlayLogic(props, ctx2) {
746
+ const backgroundClass = computed(() => {
747
+ return [
748
+ "devui-overlay-background",
749
+ props.backgroundClass,
750
+ !props.hasBackdrop ? "devui-overlay-background__disabled" : "devui-overlay-background__color"
751
+ ];
752
+ });
753
+ const overlayClass = computed(() => {
754
+ return "devui-overlay";
755
+ });
756
+ const handleBackdropClick = (event) => {
757
+ var _a;
758
+ event.preventDefault();
759
+ (_a = props.onBackdropClick) == null ? void 0 : _a.call(props);
760
+ if (props.backdropClose) {
761
+ ctx2.emit("update:visible", false);
762
+ }
763
+ };
764
+ const handleOverlayBubbleCancel = (event) => event.cancelBubble = true;
765
+ onMounted(() => {
766
+ const body = document.body;
767
+ const originOverflow = body.style.overflow;
768
+ const originPosition = body.style.position;
769
+ watch([() => props.visible, () => props.backgroundBlock], ([visible, backgroundBlock]) => {
770
+ if (backgroundBlock) {
771
+ const top = body.getBoundingClientRect().y;
772
+ if (visible) {
773
+ body.style.overflowY = "scroll";
774
+ body.style.position = visible ? "fixed" : "";
775
+ body.style.top = `${top}px`;
776
+ } else {
777
+ body.style.overflowY = originOverflow;
778
+ body.style.position = originPosition;
779
+ body.style.top = "";
780
+ window.scrollTo(0, -top);
781
+ }
782
+ }
783
+ });
784
+ onUnmounted(() => {
785
+ document.body.style.overflow = originOverflow;
786
+ });
787
+ });
788
+ return {
789
+ backgroundClass,
790
+ overlayClass,
791
+ handleBackdropClick,
792
+ handleOverlayBubbleCancel
793
+ };
794
+ }
795
+ function isComponent(target) {
796
+ return !!(target == null ? void 0 : target.$el);
797
+ }
798
+ function getElement(element) {
799
+ if (element instanceof Element) {
800
+ return element;
801
+ }
802
+ if (element && typeof element === "object" && element.$el instanceof Element) {
803
+ return element.$el;
804
+ }
805
+ return null;
806
+ }
807
+ const FlexibleOverlay = defineComponent({
808
+ name: "DFlexibleOverlay",
809
+ props: flexibleOverlayProps,
810
+ emits: overlayEmits,
811
+ setup(props, ctx2) {
812
+ const overlayRef = ref(null);
813
+ const positionedStyle = reactive({
814
+ position: "absolute"
815
+ });
816
+ onMounted(async () => {
817
+ const handleRectChange = (position, rect, origin) => {
818
+ const point = calculatePosition(position, rect, origin);
819
+ positionedStyle.left = `${point.x}px`;
820
+ positionedStyle.top = `${point.y}px`;
821
+ };
822
+ const locationElements = computed(() => {
823
+ const overlay2 = overlayRef.value;
824
+ const origin = getOrigin(props.origin);
825
+ if (!overlay2 || !origin) {
826
+ return;
827
+ }
828
+ return {
829
+ origin,
830
+ overlay: overlay2
831
+ };
832
+ });
833
+ const visibleRef = toRef(props, "visible");
834
+ const positionRef = toRef(props, "position");
835
+ watch([locationElements, visibleRef, positionRef], async ([locationElements2, visible, position], ov, onInvalidate) => {
836
+ if (!visible || !locationElements2) {
837
+ return;
838
+ }
839
+ const {
840
+ origin,
841
+ overlay: overlay2
842
+ } = locationElements2;
843
+ handleRectChange(position, overlay2.getBoundingClientRect(), origin);
844
+ const unsubscriptions = [subscribeLayoutEvent(() => handleRectChange(position, overlay2.getBoundingClientRect(), origin)), subscribeOverlayResize(overlay2, (entries) => handleRectChange(position, entries[0].contentRect, origin)), subscribeOriginResize(origin, () => handleRectChange(position, overlay2.getBoundingClientRect(), origin))];
845
+ onInvalidate(() => {
846
+ unsubscriptions.forEach((fn) => fn());
847
+ });
848
+ });
849
+ });
850
+ const {
851
+ backgroundClass,
852
+ overlayClass,
853
+ handleBackdropClick,
854
+ handleOverlayBubbleCancel
855
+ } = useOverlayLogic(props, ctx2);
856
+ return () => createVNode(CommonOverlay, null, {
857
+ default: () => [withDirectives(createVNode("div", {
858
+ "style": props.backgroundStyle,
859
+ "class": backgroundClass.value,
860
+ "onClick": handleBackdropClick
861
+ }, [createVNode("div", {
862
+ "ref": overlayRef,
863
+ "class": overlayClass.value,
864
+ "style": positionedStyle,
865
+ "onClick": handleOverlayBubbleCancel
866
+ }, [renderSlot(ctx2.slots, "default")])]), [[vShow, props.visible]])]
867
+ });
868
+ }
869
+ });
870
+ function getOrigin(origin) {
871
+ if (origin instanceof Element) {
872
+ return origin;
873
+ }
874
+ if (isRef(origin)) {
875
+ return getElement(origin.value);
876
+ }
877
+ if (isComponent(origin)) {
878
+ return getElement(origin);
879
+ }
880
+ return origin;
881
+ }
882
+ function calculatePosition(position, rect, origin) {
883
+ const originRect = getOriginRect(origin);
884
+ const originPoint = getOriginRelativePoint(originRect, position);
885
+ return getOverlayPoint(originPoint, rect, position);
886
+ }
887
+ function getOriginRect(origin) {
888
+ if (origin instanceof Element) {
889
+ return origin.getBoundingClientRect();
890
+ }
891
+ const width = origin.width || 0;
892
+ const height = origin.height || 0;
893
+ return {
894
+ top: origin.y,
895
+ bottom: origin.y + height,
896
+ left: origin.x,
897
+ right: origin.x + width,
898
+ height,
899
+ width
900
+ };
901
+ }
902
+ function getOverlayPoint(originPoint, rect, position) {
903
+ let x;
904
+ const {
905
+ width,
906
+ height
907
+ } = rect;
908
+ if (position.overlayX == "center") {
909
+ x = originPoint.x - width / 2;
910
+ } else {
911
+ x = position.overlayX == "left" ? originPoint.x : originPoint.x - width;
912
+ }
913
+ let y;
914
+ if (position.overlayY == "center") {
915
+ y = originPoint.y - height / 2;
916
+ } else {
917
+ y = position.overlayY == "top" ? originPoint.y : originPoint.y - height;
918
+ }
919
+ return {
920
+ x,
921
+ y
922
+ };
923
+ }
924
+ function getOriginRelativePoint(originRect, position) {
925
+ let x;
926
+ if (position.originX == "center") {
927
+ x = originRect.left + originRect.width / 2;
928
+ } else {
929
+ const startX = originRect.left;
930
+ const endX = originRect.right;
931
+ x = position.originX == "left" ? startX : endX;
932
+ }
933
+ let y;
934
+ if (position.originY == "center") {
935
+ y = originRect.top + originRect.height / 2;
936
+ } else {
937
+ y = position.originY == "top" ? originRect.top : originRect.bottom;
938
+ }
939
+ return {
940
+ x,
941
+ y
942
+ };
943
+ }
944
+ function subscribeLayoutEvent(event) {
945
+ window.addEventListener("scroll", event, true);
946
+ window.addEventListener("resize", event);
947
+ window.addEventListener("orientationchange", event);
948
+ return () => {
949
+ window.removeEventListener("scroll", event, true);
950
+ window.removeEventListener("resize", event);
951
+ window.removeEventListener("orientationchange", event);
952
+ };
953
+ }
954
+ function subscribeOverlayResize(overlay2, callback) {
955
+ if (overlay2 instanceof Element) {
956
+ const resizeObserver = new ResizeObserver(callback);
957
+ resizeObserver.observe(overlay2);
958
+ return () => resizeObserver.disconnect();
959
+ }
960
+ return () => {
961
+ };
962
+ }
963
+ function subscribeOriginResize(origin, callback) {
964
+ if (origin instanceof Element) {
965
+ const observer = new MutationObserver(callback);
966
+ observer.observe(origin, {
967
+ attributeFilter: ["style"]
968
+ });
969
+ return () => observer.disconnect();
970
+ }
971
+ return () => {
972
+ };
973
+ }
974
+ function _isSlot(s) {
975
+ return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
976
+ }
977
+ var AutoComplete = defineComponent({
978
+ name: "DAutoComplete",
979
+ directives: {
980
+ ClickOutside: clickoutsideDirective
981
+ },
982
+ props: autoCompleteProps,
983
+ emits: ["update:modelValue"],
984
+ setup(props, ctx2) {
985
+ const {
986
+ disabled,
987
+ modelValue,
988
+ appendToBody,
989
+ dAutoCompleteWidth,
990
+ delay,
991
+ allowEmptyValueSearch,
992
+ formatter,
993
+ transInputFocusEmit,
994
+ selectValue,
995
+ source,
996
+ searchFn,
997
+ appendToBodyDirections,
998
+ latestSource,
999
+ showAnimation
1000
+ } = toRefs(props);
1001
+ const {
1002
+ handleSearch,
1003
+ searchList,
1004
+ showNoResultItemTemplate,
1005
+ recentlyFocus
1006
+ } = useSearchFn(ctx2, allowEmptyValueSearch, source, searchFn, formatter);
1007
+ const {
1008
+ onInput,
1009
+ onFocus,
1010
+ inputRef,
1011
+ visible,
1012
+ searchStatus,
1013
+ handleClose,
1014
+ toggleMenu
1015
+ } = useInputHandle(ctx2, searchList, showNoResultItemTemplate, modelValue, disabled, delay, handleSearch, transInputFocusEmit, recentlyFocus, latestSource);
1016
+ const {
1017
+ selectedIndex,
1018
+ selectOptionClick
1019
+ } = useSelectHandle(ctx2, searchList, selectValue, handleSearch, formatter, handleClose);
1020
+ const {
1021
+ showLoading,
1022
+ dropDownRef,
1023
+ loadMore
1024
+ } = useLazyHandle(props, ctx2, handleSearch);
1025
+ const {
1026
+ customRenderSolts
1027
+ } = useCustomTemplate(ctx2, modelValue);
1028
+ const {
1029
+ hoverIndex,
1030
+ handlekeyDown
1031
+ } = useKeyBoardHandle(dropDownRef, visible, searchList, selectedIndex, searchStatus, showNoResultItemTemplate, selectOptionClick, handleClose);
1032
+ provide(DropdownPropsKey, {
1033
+ props,
1034
+ visible,
1035
+ term: "",
1036
+ searchList,
1037
+ selectedIndex,
1038
+ searchStatus,
1039
+ selectOptionClick,
1040
+ dropDownRef,
1041
+ showLoading,
1042
+ loadMore,
1043
+ latestSource,
1044
+ modelValue,
1045
+ showNoResultItemTemplate,
1046
+ hoverIndex
1047
+ });
1048
+ const origin = ref();
1049
+ const position = reactive({
1050
+ appendToBodyDirections: {}
1051
+ });
1052
+ position.appendToBodyDirections = appendToBodyDirections;
1053
+ const renderDropdown = () => {
1054
+ if (appendToBody.value) {
1055
+ let _slot;
1056
+ return createVNode(FlexibleOverlay, {
1057
+ "hasBackdrop": false,
1058
+ "origin": origin,
1059
+ "position": position.appendToBodyDirections,
1060
+ "visible": visible.value,
1061
+ "onUpdate:visible": ($event) => visible.value = $event
1062
+ }, {
1063
+ default: () => [createVNode("div", {
1064
+ "class": "devui-dropdown devui-auto-complete-menu",
1065
+ "style": {
1066
+ width: dAutoCompleteWidth.value > 0 && dAutoCompleteWidth.value + "px"
1067
+ }
1068
+ }, [createVNode(DAutoCompleteDropdown, null, _isSlot(_slot = customRenderSolts()) ? _slot : {
1069
+ default: () => [_slot]
1070
+ })])]
1071
+ });
1072
+ } else {
1073
+ let _slot2;
1074
+ return createVNode("div", {
1075
+ "class": "devui-dropdown",
1076
+ "style": {
1077
+ width: dAutoCompleteWidth.value > 0 && dAutoCompleteWidth.value + "px"
1078
+ }
1079
+ }, [createVNode(Transition, {
1080
+ "name": showAnimation ? "fade" : ""
1081
+ }, {
1082
+ default: () => [createVNode(DAutoCompleteDropdown, null, _isSlot(_slot2 = customRenderSolts()) ? _slot2 : {
1083
+ default: () => [_slot2]
1084
+ })]
1085
+ })]);
1086
+ }
1087
+ };
1088
+ return () => {
1089
+ return withDirectives(createVNode("div", {
1090
+ "class": ["devui-auto-complete", "devui-form-group", "devui-has-feedback", visible.value && "devui-select-open"],
1091
+ "ref": origin,
1092
+ "style": {
1093
+ width: dAutoCompleteWidth.value > 0 && dAutoCompleteWidth.value + "px"
1094
+ }
1095
+ }, [createVNode("input", {
1096
+ "disabled": disabled.value,
1097
+ "type": "text",
1098
+ "onClick": toggleMenu,
1099
+ "class": ["devui-form-control", "devui-dropdown-origin", "devui-dropdown-origin-open", disabled.value && "disabled"],
1100
+ "placeholder": "Search",
1101
+ "onInput": onInput,
1102
+ "onFocus": onFocus,
1103
+ "value": modelValue.value,
1104
+ "ref": inputRef,
1105
+ "onKeydown": handlekeyDown
1106
+ }, null), renderDropdown()]), [[resolveDirective("click-outside"), handleClose]]);
1107
+ };
1108
+ }
1109
+ });
1110
+ AutoComplete.install = function(app) {
1111
+ app.component(AutoComplete.name, AutoComplete);
1112
+ };
1113
+ var index = {
1114
+ title: "AutoComplete \u81EA\u52A8\u8865\u5168",
1115
+ category: "\u6570\u636E\u5F55\u5165",
1116
+ status: "100%",
1117
+ install(app) {
1118
+ app.use(AutoComplete);
1119
+ }
1120
+ };
1121
+ export { AutoComplete, index as default };