@destyler/combobox 0.0.6 → 0.0.7-beta.2

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.
@@ -1,1101 +0,0 @@
1
- 'use strict';
2
-
3
- const vue = require('vue');
4
- const primitive = require('@destyler/primitive');
5
- const composition = require('@destyler/composition');
6
- const popper = require('@destyler/popper');
7
- const component$2 = require('@destyler/popper/component');
8
- const shared = require('@destyler/shared');
9
- const component = require('@destyler/visually-hidden/component');
10
- const composition$1 = require('@destyler/collection/composition');
11
- const collection = require('@destyler/collection');
12
- const dismissableLayer = require('@destyler/dismissable-layer');
13
- const component$1 = require('@destyler/dismissable-layer/component');
14
- const directives = require('@destyler/directives');
15
- const presence = require('@destyler/presence');
16
- const teleport = require('@destyler/teleport');
17
-
18
- const comboboxAnchorProps = {
19
- ...primitive.primitiveProps
20
- };
21
- const ComboboxAnchor = vue.defineComponent({
22
- name: "DestylerComboboxAnchor",
23
- props: comboboxAnchorProps,
24
- setup() {
25
- const { forwardRef } = composition.useForwardExpose();
26
- return {
27
- forwardRef
28
- };
29
- },
30
- render() {
31
- return vue.h(popper.PopperAnchor, {
32
- asChild: true
33
- }, () => {
34
- return vue.h(primitive.Primitive, vue.mergeProps(this.$attrs, {
35
- ref: (el) => this.forwardRef(el),
36
- as: this.$props.as,
37
- asChild: this.$props.asChild
38
- }), {
39
- default: () => this.$slots.default?.()
40
- });
41
- });
42
- }
43
- });
44
-
45
- const comboboxRootProps = {
46
- ...primitive.primitiveProps,
47
- /**
48
- * The controlled value of the Combobox. Can be binded-with with `v-model`.
49
- *
50
- * @default undefined
51
- */
52
- modelValue: {
53
- type: [String, Number, Boolean, Object, Array],
54
- required: false,
55
- default: void 0
56
- },
57
- /**
58
- * The value of the combobox when initially rendered.
59
- * Use when you do not need to control the state of the Combobox
60
- *
61
- * @default undefined
62
- */
63
- defaultValue: {
64
- type: [String, Number, Boolean, Object, Array],
65
- required: false,
66
- default: void 0
67
- },
68
- /**
69
- * The controlled open state of the Combobox. Can be binded-with with `v-model:open`.
70
- *
71
- * @default undefined
72
- */
73
- open: {
74
- type: Boolean,
75
- required: false,
76
- default: void 0
77
- },
78
- /**
79
- * The open state of the combobox when it is initially rendered.
80
- * Use when you do not need to control its open state.
81
- */
82
- defaultOpen: {
83
- type: Boolean,
84
- required: false
85
- },
86
- /**
87
- * The controlled search term of the Combobox.
88
- * Can be binded-with with `v-model:searchTerm`.
89
- */
90
- searchTerm: {
91
- type: String,
92
- required: false
93
- },
94
- /**
95
- * Whether multiple options can be selected or not.
96
- *
97
- * @default false
98
- */
99
- multiple: {
100
- type: Boolean,
101
- required: false,
102
- default: false
103
- },
104
- /**
105
- * When `true`, prevents the user from interacting with Combobox.
106
- *
107
- * @default false
108
- */
109
- disabled: {
110
- type: Boolean,
111
- required: false,
112
- default: false
113
- },
114
- /**
115
- * The name of the Combobox. Submitted with its owning form as part of a name/value pair.
116
- */
117
- name: {
118
- type: String,
119
- required: false
120
- },
121
- /**
122
- * The reading direction of the combobox when applicable.
123
- */
124
- dir: {
125
- type: String,
126
- required: false
127
- },
128
- /**
129
- * The custom filter function for filtering `ComboboxItem`.
130
- */
131
- filterFunction: {
132
- type: Function,
133
- required: false
134
- },
135
- /**
136
- * The display value of input for selected item. Does not work with `multiple`.
137
- */
138
- displayValue: {
139
- type: Function,
140
- required: false
141
- }
142
- };
143
- const comboboxRootEmits = {
144
- /**
145
- * Event handler called when the value changes.
146
- */
147
- "update:modelValue": (_value) => true,
148
- /**
149
- * Event handler called when the open state of the combobox changes.
150
- */
151
- "update:open": (_value) => true,
152
- /**
153
- * Event handler called when the searchTerm of the combobox changes.
154
- */
155
- "update:searchTerm": (_value) => true
156
- };
157
- const [injectComboboxRootContext, provideComboboxRootContext] = shared.createContext("DestylerComboboxRoot");
158
- const ComboboxRoot = vue.defineComponent({
159
- name: "DestylerComboboxRoot",
160
- props: comboboxRootProps,
161
- emits: comboboxRootEmits,
162
- slots: Object,
163
- setup(props, { emit }) {
164
- const { multiple, disabled, dir: propDir } = vue.toRefs(props);
165
- const dir = composition.useDirection(propDir);
166
- const searchTerm = composition.useVModel(props, "searchTerm", emit, {
167
- defaultValue: "",
168
- passive: props.searchTerm === void 0
169
- });
170
- const modelValue = composition.useVModel(props, "modelValue", emit, {
171
- defaultValue: props.defaultValue ?? multiple.value ? [] : void 0,
172
- passive: props.modelValue === void 0,
173
- deep: true
174
- });
175
- const open = composition.useVModel(props, "open", emit, {
176
- defaultValue: props.defaultOpen,
177
- passive: props.open === void 0
178
- });
179
- const selectedValue = vue.ref();
180
- const inputElement = vue.ref();
181
- const contentElement = vue.ref();
182
- const { forwardRef, currentElement: parentElement } = composition.useForwardExpose();
183
- const { getItems, reactiveItems, itemMapSize } = composition$1.createCollection("data-destyler-combobox-item");
184
- const isUserInputted = vue.ref(false);
185
- async function onOpenChange(val) {
186
- open.value = val;
187
- await vue.nextTick();
188
- if (val) {
189
- if (modelValue.value) {
190
- if (Array.isArray(modelValue.value) && multiple.value)
191
- selectedValue.value = getItems().find((i) => i.ref?.dataset?.state === "checked")?.value;
192
- else
193
- selectedValue.value = modelValue.value;
194
- }
195
- inputElement.value?.focus();
196
- scrollSelectedValueIntoView();
197
- } else {
198
- isUserInputted.value = false;
199
- resetSearchTerm();
200
- }
201
- }
202
- function onValueChange(val) {
203
- if (Array.isArray(modelValue.value) && multiple.value) {
204
- const index = modelValue.value.findIndex((i) => shared.isEqual(i, val));
205
- index === -1 ? modelValue.value.push(val) : modelValue.value.splice(index, 1);
206
- } else {
207
- modelValue.value = val;
208
- onOpenChange(false);
209
- }
210
- }
211
- const options = vue.ref([]);
212
- vue.watch(() => itemMapSize.value, () => {
213
- options.value = getItems().map((i) => i.value);
214
- }, { immediate: true });
215
- const filteredOptions = vue.computed(() => {
216
- if (isUserInputted.value) {
217
- if (props.filterFunction)
218
- return props.filterFunction(options.value, searchTerm.value);
219
- const optionsWithTypeString = options.value.filter((i) => typeof i === "string");
220
- if (optionsWithTypeString.length)
221
- return optionsWithTypeString.filter((i) => i.toLowerCase().includes(searchTerm.value?.toLowerCase()));
222
- }
223
- return options.value;
224
- });
225
- function resetSearchTerm() {
226
- if (!multiple.value && modelValue.value && !Array.isArray(modelValue.value)) {
227
- if (props.displayValue)
228
- searchTerm.value = props.displayValue(modelValue.value);
229
- else if (typeof modelValue.value !== "object")
230
- searchTerm.value = modelValue.value.toString();
231
- else
232
- searchTerm.value = "";
233
- } else {
234
- searchTerm.value = "";
235
- }
236
- }
237
- const activeIndex = vue.computed(() => filteredOptions.value.findIndex((i) => shared.isEqual(i, selectedValue.value)));
238
- const selectedElement = vue.computed(() => {
239
- return reactiveItems.value.find((i) => i.value === selectedValue.value)?.ref;
240
- });
241
- const stringifiedModelValue = vue.computed(() => JSON.stringify(modelValue.value));
242
- vue.watch(stringifiedModelValue, async () => {
243
- await vue.nextTick();
244
- await vue.nextTick();
245
- resetSearchTerm();
246
- }, { immediate: true });
247
- vue.watch(() => filteredOptions.value.length, async (length) => {
248
- await vue.nextTick();
249
- await vue.nextTick();
250
- if (length && activeIndex.value === -1)
251
- selectedValue.value = filteredOptions.value[0];
252
- });
253
- const isFormControl = composition.useFormControl(parentElement);
254
- function scrollSelectedValueIntoView() {
255
- if (selectedElement.value instanceof Element)
256
- selectedElement.value.scrollIntoView({ block: "nearest" });
257
- }
258
- provideComboboxRootContext({
259
- searchTerm,
260
- modelValue,
261
- onValueChange,
262
- isUserInputted,
263
- multiple,
264
- disabled,
265
- open,
266
- onOpenChange,
267
- filteredOptions,
268
- contentId: "",
269
- inputElement,
270
- onInputElementChange: (val) => inputElement.value = val,
271
- onInputNavigation: async (val) => {
272
- const index = activeIndex.value;
273
- if (index === 0 && val === "up" || index === filteredOptions.value.length - 1 && val === "down")
274
- return;
275
- if (index === -1 && filteredOptions.value.length || val === "home")
276
- selectedValue.value = filteredOptions.value[0];
277
- else if (val === "end")
278
- selectedValue.value = filteredOptions.value[filteredOptions.value.length - 1];
279
- else
280
- selectedValue.value = filteredOptions.value[val === "up" ? index - 1 : index + 1];
281
- scrollSelectedValueIntoView();
282
- },
283
- onInputEnter: async () => {
284
- if (filteredOptions.value.length && selectedValue.value && selectedElement.value instanceof Element)
285
- selectedElement.value?.click();
286
- },
287
- selectedValue,
288
- onSelectedValueChange: (val) => selectedValue.value = val,
289
- parentElement,
290
- contentElement,
291
- onContentElementChange: (val) => contentElement.value = val
292
- });
293
- return {
294
- forwardRef,
295
- isFormControl,
296
- open,
297
- modelValue,
298
- dir
299
- };
300
- },
301
- render() {
302
- return vue.h(popper.PopperRoot, null, {
303
- default: () => {
304
- return vue.h(primitive.Primitive, vue.mergeProps(this.$attrs, {
305
- ref: (el) => this.forwardRef(el),
306
- style: {
307
- pointerEvents: this.open ? "auto" : void 0
308
- },
309
- as: this.$props.as,
310
- asChild: this.$props.asChild,
311
- dir: this.dir
312
- }), {
313
- default: () => {
314
- return [
315
- this.$slots.default?.({ open: this.open, modelValue: this.modelValue }),
316
- this.isFormControl && this.$props.name ? vue.h(component.VisuallyHiddenInput, {
317
- name: this.$props.name,
318
- value: this.modelValue
319
- }) : null
320
- ];
321
- }
322
- });
323
- }
324
- });
325
- }
326
- });
327
-
328
- const comboboxContentImplProps = {
329
- ...dismissableLayer.dismissableLayerProps,
330
- ...popper.popperContentProps,
331
- /**
332
- * The positioning mode to use, <br>
333
- * `inline` is the default and you can control the position using CSS. <br>
334
- * `popper` positions content in the same way as our other primitives, for example `Popover` or `DropdownMenu`.
335
- *
336
- * @default inline
337
- */
338
- position: {
339
- type: String,
340
- required: false,
341
- default: "inline"
342
- },
343
- /**
344
- * The document.body will be lock, and scrolling will be disabled.
345
- */
346
- bodyLock: {
347
- type: Boolean,
348
- required: false
349
- },
350
- /**
351
- * Allow component to be dismissableLayer.
352
- *
353
- * @default true
354
- */
355
- dismissable: {
356
- type: Boolean,
357
- required: false,
358
- default: true
359
- }
360
- };
361
- const comboboxContentImplEmits = {
362
- ...component$1.dismissableLayerEmits
363
- };
364
- const [injectComboboxContentContext, provideComboboxContentContext] = shared.createContext("DestylerComboboxContent");
365
- const ComboboxContentImpl = vue.defineComponent({
366
- name: "DestylerComboboxContentImpl",
367
- props: comboboxContentImplProps,
368
- emits: comboboxContentImplEmits,
369
- setup(props) {
370
- const { position } = vue.toRefs(props);
371
- const rootContext = injectComboboxRootContext();
372
- composition.useBodyScrollLock(props.bodyLock);
373
- const { forwardRef, currentElement } = composition.useForwardExpose();
374
- composition.useHideOthers(currentElement);
375
- const pickedProps = vue.computed(() => {
376
- if (props.position === "popper")
377
- return props;
378
- else
379
- return {};
380
- });
381
- const forwardedProps = composition.useForwardProps(pickedProps.value);
382
- function handleLeave() {
383
- rootContext.onSelectedValueChange("");
384
- }
385
- vue.onMounted(() => {
386
- rootContext.onContentElementChange(currentElement.value);
387
- });
388
- const popperStyle = {
389
- "boxSizing": "border-box",
390
- "--destyler-combobox-content-transform-origin": "var(--destyler-popper-transform-origin)",
391
- "--destyler-combobox-content-available-width": "var(--destyler-popper-available-width)",
392
- "--destyler-combobox-content-available-height": "var(--destyler-popper-available-height)",
393
- "--destyler-combobox-trigger-width": "var(--destyler-popper-anchor-width)",
394
- "--destyler-combobox-trigger-height": "var(--destyler-popper-anchor-height)"
395
- };
396
- provideComboboxContentContext({ position });
397
- return {
398
- rootContext,
399
- popperStyle,
400
- forwardedProps,
401
- pickedProps,
402
- forwardRef,
403
- handleLeave
404
- };
405
- },
406
- render() {
407
- return vue.h(collection.CollectionSlot, null, {
408
- default: () => {
409
- return [
410
- this.$props.dismissable ? vue.h(dismissableLayer.DismissableLayer, {
411
- asChild: true,
412
- disableOutsidePointerEvents: this.$props.disableOutsidePointerEvents,
413
- onDismiss: () => {
414
- this.rootContext.onOpenChange(false);
415
- },
416
- onFocusOutside: (event) => {
417
- if (this.rootContext.parentElement.value?.contains(event.target))
418
- event.preventDefault();
419
- this.$emit("focusOutside", event);
420
- },
421
- onInteractOutside: (event) => {
422
- this.$emit("interactOutside", event);
423
- },
424
- onEscapeKeyDown: (event) => {
425
- this.$emit("escapeKeyDown", event);
426
- },
427
- onPointerDownOutside: (event) => {
428
- if (this.rootContext.parentElement.value?.contains(event.target))
429
- event.preventDefault();
430
- this.$emit("pointerDownOutside", event);
431
- }
432
- }, {
433
- default: () => {
434
- return vue.withDirectives(vue.h(this.$props.position === "popper" ? popper.PopperContent : primitive.Primitive, vue.mergeProps(this.$attrs, this.forwardedProps, {
435
- "ref": (el) => this.forwardRef(el),
436
- "role": "listbox",
437
- "data-state": this.rootContext.open.value ? "open" : "closed",
438
- "style": {
439
- display: "flex",
440
- flexDirection: "column",
441
- outline: "none",
442
- ...this.$props.position === "popper" ? this.popperStyle : {}
443
- },
444
- "onPointerleave": () => {
445
- this.handleLeave();
446
- }
447
- }), {
448
- default: () => this.$slots.default?.()
449
- }), [
450
- [directives.BindOnceDirective, { id: this.rootContext.contentId }]
451
- ]);
452
- }
453
- }) : vue.withDirectives(vue.h(this.$props.position === "popper" ? popper.PopperContent : primitive.Primitive, vue.mergeProps(this.$attrs, this.pickedProps, {
454
- "ref": (el) => this.forwardRef(el),
455
- "role": "listbox",
456
- "data-state": this.rootContext.open.value ? "open" : "closed",
457
- "style": {
458
- display: "flex",
459
- flexDirection: "column",
460
- outline: "none",
461
- ...this.$props.position === "popper" ? this.popperStyle : {}
462
- },
463
- "onPointerleave": () => {
464
- this.handleLeave();
465
- }
466
- }), {
467
- default: () => this.$slots.default?.()
468
- }), [
469
- [directives.BindOnceDirective, { id: this.rootContext.contentId }]
470
- ])
471
- ];
472
- }
473
- });
474
- }
475
- });
476
-
477
- const comboboxArrowProps = {
478
- ...component$2.popperArrowProps
479
- };
480
- const ComboboxArrow = vue.defineComponent({
481
- name: "DestylerComboboxArrow",
482
- props: comboboxArrowProps,
483
- setup() {
484
- composition.useForwardExpose();
485
- const rootContext = injectComboboxRootContext();
486
- const contentContext = injectComboboxContentContext();
487
- return {
488
- rootContext,
489
- contentContext
490
- };
491
- },
492
- render() {
493
- if (this.rootContext.open.value && this.contentContext.position.value === "popper")
494
- return vue.h(popper.PopperArrow, this.$props, () => this.$slots.default?.());
495
- else
496
- return null;
497
- }
498
- });
499
-
500
- const comboboxCancelProps = {
501
- ...primitive.primitiveProps,
502
- /**
503
- * @default button
504
- */
505
- as: {
506
- ...primitive.primitiveProps.as,
507
- default: "button"
508
- }
509
- };
510
- const ComboboxCancel = vue.defineComponent({
511
- name: "DestylerComboboxCancel",
512
- props: comboboxCancelProps,
513
- setup() {
514
- composition.useForwardExpose();
515
- const rootContext = injectComboboxRootContext();
516
- function handleClick() {
517
- rootContext.searchTerm.value = "";
518
- rootContext.inputElement.value?.focus();
519
- }
520
- return {
521
- rootContext,
522
- handleClick
523
- };
524
- },
525
- render() {
526
- return vue.h(primitive.Primitive, vue.mergeProps(this.$props, {
527
- type: this.$props.as === "button" ? "button" : void 0,
528
- tabindex: "-1",
529
- onClick: () => {
530
- this.handleClick();
531
- }
532
- }), () => this.$slots.default?.());
533
- }
534
- });
535
-
536
- const comboboxContentProps = {
537
- ...comboboxContentImplProps,
538
- /**
539
- * Used to force mounting when more control is needed.
540
- * Useful when controlling animation with Vue animation libraries.
541
- */
542
- forceMount: {
543
- type: Boolean,
544
- required: false
545
- }
546
- };
547
- const comboboxContentEmits = {
548
- ...comboboxContentImplEmits
549
- };
550
- const ComboboxContent = vue.defineComponent({
551
- name: "DestylerComboboxContent",
552
- props: comboboxContentProps,
553
- emits: comboboxContentEmits,
554
- setup(props, { emit }) {
555
- const forwarded = composition.useForwardPropsEmits(props, emit);
556
- const { forwardRef } = composition.useForwardExpose();
557
- const rootContext = injectComboboxRootContext();
558
- rootContext.contentId || (rootContext.contentId = composition.useId(void 0, "destyler-combobox-content"));
559
- return {
560
- forwardRef,
561
- forwarded,
562
- rootContext
563
- };
564
- },
565
- render() {
566
- return vue.h(presence.Presence, {
567
- present: this.$props.forceMount || this.rootContext.open.value
568
- }, () => vue.h(ComboboxContentImpl, vue.mergeProps(this.$attrs, this.forwarded, {
569
- ref: (el) => this.forwardRef(el)
570
- }), () => this.$slots.default?.()));
571
- }
572
- });
573
-
574
- const comboboxEmptyProps = {
575
- ...primitive.primitiveProps
576
- };
577
- const ComboboxEmpty = vue.defineComponent({
578
- name: "DestylerComboboxEmpty",
579
- props: comboboxEmptyProps,
580
- setup() {
581
- composition.useForwardExpose();
582
- const rootContext = injectComboboxRootContext();
583
- const isEmpty = vue.computed(() => rootContext.filteredOptions.value.length === 0);
584
- return {
585
- rootContext,
586
- isEmpty
587
- };
588
- },
589
- render() {
590
- if (this.isEmpty) {
591
- return vue.h(primitive.Primitive, this.$props, {
592
- default: () => this.$slots.default ? this.$slots.default?.() : "No options"
593
- });
594
- }
595
- }
596
- });
597
-
598
- const comboboxGroupProps = {
599
- ...primitive.primitiveProps
600
- };
601
- const [injectComboboxGroupContext, provideComboboxGroupContext] = shared.createContext("DestylerComboboxGroup");
602
- const ComboboxGroup = vue.defineComponent({
603
- name: "DestylerComboboxGroup",
604
- props: comboboxGroupProps,
605
- setup() {
606
- const { currentRef, currentElement } = composition.useForwardExpose();
607
- const id = composition.useId(void 0, "destyler-combobox-group");
608
- const rootContext = injectComboboxRootContext();
609
- const hasOptions = vue.ref(false);
610
- function checkCollectionItem() {
611
- if (!currentElement.value)
612
- return;
613
- const collectionItem = currentElement.value.querySelectorAll("[data-destyler-combobox-item]:not([data-hidden])");
614
- hasOptions.value = !!collectionItem.length;
615
- }
616
- composition.useMutationObserver(currentElement, () => {
617
- checkCollectionItem();
618
- }, {
619
- childList: true
620
- });
621
- vue.watch(() => rootContext.searchTerm.value, () => {
622
- vue.nextTick(() => {
623
- checkCollectionItem();
624
- });
625
- }, {
626
- immediate: true
627
- });
628
- provideComboboxGroupContext({
629
- id
630
- });
631
- return {
632
- currentRef,
633
- hasOptions,
634
- id
635
- };
636
- },
637
- render() {
638
- return vue.h(primitive.Primitive, vue.mergeProps(this.$props, {
639
- "ref": "currentRef",
640
- "role": "group",
641
- "aria-labelledby": this.id,
642
- ...this.hasOptions ? {} : { style: { display: "none" } }
643
- }), {
644
- default: () => this.$slots.default?.()
645
- });
646
- }
647
- });
648
-
649
- const comboboxInputProps = {
650
- ...primitive.primitiveProps,
651
- /**
652
- * @default input
653
- */
654
- as: {
655
- ...primitive.primitiveProps.as,
656
- default: "input"
657
- },
658
- /**
659
- * Native input type
660
- *
661
- * @default text
662
- */
663
- type: {
664
- type: String,
665
- required: false,
666
- default: "text"
667
- },
668
- /**
669
- * When `true`, prevents the user from interacting with item
670
- */
671
- disabled: {
672
- type: Boolean,
673
- required: false
674
- },
675
- /**
676
- * Focus on element when mounted.
677
- *
678
- * @default false
679
- */
680
- autoFocus: {
681
- type: Boolean,
682
- required: false
683
- }
684
- };
685
- const ComboboxInput = vue.defineComponent({
686
- name: "DestylerComboboxInput",
687
- props: comboboxInputProps,
688
- setup(props) {
689
- const rootContext = injectComboboxRootContext();
690
- const { forwardRef, currentElement } = composition.useForwardExpose();
691
- vue.onMounted(() => {
692
- const inputEl = currentElement.value.nodeName === "INPUT" ? currentElement.value : currentElement.value.querySelector("input");
693
- if (!inputEl)
694
- return;
695
- rootContext.onInputElementChange(inputEl);
696
- setTimeout(() => {
697
- if (props.autoFocus)
698
- inputEl?.focus();
699
- }, 1);
700
- });
701
- const disabled = vue.computed(() => props.disabled || rootContext.disabled.value || false);
702
- function handleKeyDown(ev) {
703
- if (!rootContext.open.value)
704
- rootContext.onOpenChange(true);
705
- else
706
- rootContext.onInputNavigation(ev.key === "ArrowUp" ? "up" : "down");
707
- }
708
- function handleHomeEnd(ev) {
709
- if (!rootContext.open.value)
710
- return;
711
- rootContext.onInputNavigation(ev.key === "Home" ? "home" : "end");
712
- }
713
- function handleInput(event) {
714
- rootContext.searchTerm.value = event.target?.value;
715
- if (!rootContext.open.value)
716
- rootContext.onOpenChange(true);
717
- rootContext.isUserInputted.value = true;
718
- }
719
- return {
720
- disabled,
721
- rootContext,
722
- forwardRef,
723
- handleInput,
724
- handleKeyDown,
725
- handleHomeEnd
726
- };
727
- },
728
- render() {
729
- return vue.h(primitive.Primitive, {
730
- "ref": (el) => this.forwardRef(el),
731
- "as": this.$props.as,
732
- "asChild": this.$props.asChild,
733
- "type": this.$props.type,
734
- "disabled": this.disabled,
735
- "value": this.rootContext.searchTerm.value,
736
- "aria-expanded": this.rootContext.open.value,
737
- "aria-controls": this.rootContext.contentId,
738
- "aria-disabled": this.disabled ?? void 0,
739
- "aria-autocomplete": "list",
740
- "role": "combobox",
741
- "autocomplete": "false",
742
- "onInput": (event) => {
743
- this.handleInput(event);
744
- },
745
- "onKeydown": vue.withKeys((event) => {
746
- switch (event.key) {
747
- case "ArrowUp":
748
- case "ArrowDown":
749
- event.preventDefault();
750
- this.handleKeyDown(event);
751
- break;
752
- case "Home":
753
- case "End":
754
- event.preventDefault();
755
- this.handleHomeEnd(event);
756
- break;
757
- case "Enter":
758
- this.rootContext.onInputEnter();
759
- break;
760
- }
761
- }, ["down", "up", "enter", "home", "end"])
762
- }, {
763
- default: () => this.$slots.default?.()
764
- });
765
- }
766
- });
767
-
768
- const COMBOBOX_SELECT = "combobox.select";
769
- const comboboxItemProps = {
770
- ...primitive.primitiveProps,
771
- /**
772
- * The value given as data when submitted with a `name`.
773
- */
774
- value: {
775
- type: [String, Number, Boolean, Object],
776
- required: true
777
- },
778
- /**
779
- * When true, prevents the user from interacting with the `item`.
780
- */
781
- disabled: {
782
- type: Boolean,
783
- required: false
784
- }
785
- };
786
- const comboboxItemEmits = {
787
- /**
788
- * Event handler called when the selecting item. <br>
789
- * It can be prevented by calling `event.preventDefault`.
790
- */
791
- select: (_ev) => true
792
- };
793
- const [injectComboboxItemContext, provideComboboxItemContext] = shared.createContext("DestylerComboboxItem");
794
- const ComboboxItem = vue.defineComponent({
795
- name: "DestylerComboboxItem",
796
- props: comboboxItemProps,
797
- emits: comboboxItemEmits,
798
- setup(props, { emit }) {
799
- const { disabled } = vue.toRefs(props);
800
- const rootContext = injectComboboxRootContext();
801
- injectComboboxGroupContext({ id: "", options: vue.ref([]) });
802
- const { forwardRef } = composition.useForwardExpose();
803
- const isSelected = vue.computed(
804
- () => rootContext.multiple.value && Array.isArray(rootContext.modelValue.value) ? rootContext.modelValue.value?.some((val) => shared.isEqual(val, props.value)) : shared.isEqual(rootContext.modelValue?.value, props.value)
805
- );
806
- const isFocused = vue.computed(() => shared.isEqual(rootContext.selectedValue.value, props.value));
807
- const textId = composition.useId(void 0, "destyler-combobox-item");
808
- const isInOption = vue.computed(() => rootContext.isUserInputted.value ? rootContext.searchTerm.value === "" || !!rootContext.filteredOptions.value.find((i) => shared.isEqual(i, props.value)) : true);
809
- async function handleSelect(ev) {
810
- emit("select", ev);
811
- if (ev?.defaultPrevented)
812
- return;
813
- if (!disabled.value && ev)
814
- rootContext.onValueChange(props.value);
815
- }
816
- function handleSelectCustomEvent(ev) {
817
- if (!ev)
818
- return;
819
- const eventDetail = { originalEvent: ev, value: props.value };
820
- shared.handleAndDispatchCustomEvent(COMBOBOX_SELECT, handleSelect, eventDetail);
821
- }
822
- async function handlePointerMove(event) {
823
- await vue.nextTick();
824
- if (event.defaultPrevented)
825
- return;
826
- rootContext.onSelectedValueChange(props.value);
827
- }
828
- if (props.value === "") {
829
- throw new Error(
830
- "A <DestylerSelectItem /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder."
831
- );
832
- }
833
- provideComboboxItemContext({
834
- isSelected
835
- });
836
- return {
837
- forwardRef,
838
- textId,
839
- isFocused,
840
- isSelected,
841
- isInOption,
842
- handleSelectCustomEvent,
843
- handlePointerMove
844
- };
845
- },
846
- render() {
847
- return vue.h(collection.CollectionItem, null, {
848
- default: () => {
849
- return vue.h(primitive.Primitive, {
850
- "ref": (el) => this.forwardRef(el),
851
- "role": "option",
852
- "tabindex": "-1",
853
- "aria-labelledby": this.textId,
854
- "data-highlighted": this.isFocused ? "" : void 0,
855
- "aria-selected": this.isSelected,
856
- "data-state": this.isSelected ? "checked" : "unchecked",
857
- "aria-disabled": this.$props.disabled || void 0,
858
- "data-disabled": this.$props.disabled ? "" : void 0,
859
- "as": this.$props.as,
860
- "asChild": this.$props.asChild,
861
- "data-hidden": !this.isInOption ? true : void 0,
862
- "onClick": (event) => {
863
- this.handleSelectCustomEvent(event);
864
- },
865
- "onPointermove": (event) => {
866
- this.handlePointerMove(event);
867
- },
868
- ...this.isInOption ? {} : { style: { display: "none" } }
869
- }, {
870
- default: () => this.$slots.default ? this.$slots.default?.() : this.$props.value
871
- });
872
- }
873
- });
874
- }
875
- });
876
-
877
- const comboboxItemIndicatorProps = {
878
- ...primitive.primitiveProps,
879
- /**
880
- * @default span
881
- */
882
- as: {
883
- ...primitive.primitiveProps.as,
884
- default: "span"
885
- }
886
- };
887
- const ComboboxItemIndicator = vue.defineComponent({
888
- name: "DestylerComboboxItemIndicator",
889
- props: comboboxItemIndicatorProps,
890
- setup() {
891
- composition.useForwardExpose();
892
- const itemContext = injectComboboxItemContext();
893
- return {
894
- itemContext
895
- };
896
- },
897
- render() {
898
- if (this.itemContext.isSelected.value) {
899
- return vue.h(primitive.Primitive, vue.mergeProps(this.$props, {
900
- "aria-hidden": ""
901
- }), {
902
- default: () => this.$slots.default?.()
903
- });
904
- }
905
- }
906
- });
907
-
908
- const comboboxLabelProps = {
909
- ...primitive.primitiveProps,
910
- /**
911
- * The id of the element the label is associated with.
912
- */
913
- for: {
914
- type: String,
915
- required: false
916
- }
917
- };
918
- const ComboboxLabel = vue.defineComponent({
919
- name: "DestylerComboboxLabel",
920
- props: comboboxLabelProps,
921
- setup() {
922
- composition.useForwardExpose();
923
- const groupContext = injectComboboxGroupContext({ id: "" });
924
- return {
925
- groupContext
926
- };
927
- },
928
- render() {
929
- return vue.withDirectives(vue.h(primitive.Primitive, this.$props, {
930
- default: () => this.$slots.default?.()
931
- }), [
932
- [directives.BindOnceDirective, { id: this.groupContext.id }]
933
- ]);
934
- }
935
- });
936
-
937
- const comboboxPortalProps = {
938
- ...teleport.teleportPrimitiveProps
939
- };
940
- const ComboboxPortal = vue.defineComponent({
941
- name: "DestylerComboboxPortal",
942
- props: comboboxPortalProps,
943
- render() {
944
- return vue.h(teleport.TeleportPrimitive, this.$props, {
945
- default: () => this.$slots.default?.()
946
- });
947
- }
948
- });
949
-
950
- const comboboxSeparatorProps = {
951
- ...primitive.primitiveProps
952
- };
953
- const ComboboxSeparator = vue.defineComponent({
954
- name: "DestylerComboboxSeparator",
955
- props: comboboxSeparatorProps,
956
- setup() {
957
- composition.useForwardExpose();
958
- },
959
- render() {
960
- return vue.h(primitive.Primitive, vue.mergeProps(this.$props, {
961
- "aria-hidden": ""
962
- }), () => this.$slots.default?.());
963
- }
964
- });
965
-
966
- const comboboxTriggerProps = {
967
- ...primitive.primitiveProps,
968
- /**
969
- * @default button
970
- */
971
- as: {
972
- ...primitive.primitiveProps.as,
973
- default: "button"
974
- },
975
- /**
976
- * When `true`, prevents the user from interacting with item.
977
- */
978
- disabled: {
979
- type: Boolean,
980
- required: false
981
- }
982
- };
983
- const ComboboxTrigger = vue.defineComponent({
984
- name: "DestylerComboboxTrigger",
985
- props: comboboxTriggerProps,
986
- setup(props) {
987
- composition.useForwardExpose();
988
- const rootContext = injectComboboxRootContext();
989
- const disabled = vue.computed(() => props.disabled || rootContext.disabled.value || false);
990
- return {
991
- rootContext,
992
- disabled
993
- };
994
- },
995
- render() {
996
- return vue.h(primitive.Primitive, vue.mergeProps(this.$props, {
997
- "type": this.$props.as === "button" ? "button" : void 0,
998
- "tabindex": "-1",
999
- "aria-label": "Show popup",
1000
- "aria-haspopup": "listbox",
1001
- "aria-expanded": this.rootContext.open.value,
1002
- "aria-controls": this.rootContext.contentId,
1003
- "data-state": this.rootContext.open.value ? "open" : "closed",
1004
- "disabled": this.disabled,
1005
- "data-disabled": this.disabled ? "" : void 0,
1006
- "aria-disabled": this.disabled ?? void 0,
1007
- "onClick": () => {
1008
- this.rootContext.onOpenChange(!this.rootContext.open.value);
1009
- }
1010
- }), {
1011
- default: () => this.$slots.default?.()
1012
- });
1013
- }
1014
- });
1015
-
1016
- const comboboxViewportProps = {
1017
- ...primitive.primitiveProps,
1018
- /**
1019
- * Will add `nonce` attribute to the style tag which can be used by Content Security Policy.
1020
- */
1021
- nonce: {
1022
- type: String,
1023
- required: false
1024
- }
1025
- };
1026
- const ComboboxViewport = vue.defineComponent({
1027
- name: "DestylerComboboxViewport",
1028
- props: comboboxViewportProps,
1029
- inheritAttrs: false,
1030
- setup() {
1031
- const { forwardRef } = composition.useForwardExpose();
1032
- return {
1033
- forwardRef
1034
- };
1035
- },
1036
- render() {
1037
- return [
1038
- vue.h(primitive.Primitive, vue.mergeProps(this.$attrs, this.$props, {
1039
- "ref": (el) => this.forwardRef(el),
1040
- "data-destyler-combobox-viewport": "",
1041
- "role": "presentation",
1042
- "style": {
1043
- position: "relative",
1044
- flex: 1,
1045
- overflow: "auto"
1046
- }
1047
- }), () => this.$slots.default?.()),
1048
- vue.h(primitive.Primitive, {
1049
- as: "style",
1050
- nonce: this.$props.nonce
1051
- }, () => `
1052
- /* Hide scrollbars cross-browser and enable momentum scroll for touch devices */
1053
- [data-destyler-combobox-viewport] {
1054
- scrollbar-width:none;
1055
- -ms-overflow-style: none;
1056
- -webkit-overflow-scrolling: touch;
1057
- }
1058
- [data-destyler-combobox-viewport]::-webkit-scrollbar {
1059
- display: none;
1060
- }
1061
- `)
1062
- ];
1063
- }
1064
- });
1065
-
1066
- exports.ComboboxAnchor = ComboboxAnchor;
1067
- exports.ComboboxArrow = ComboboxArrow;
1068
- exports.ComboboxCancel = ComboboxCancel;
1069
- exports.ComboboxContent = ComboboxContent;
1070
- exports.ComboboxContentImpl = ComboboxContentImpl;
1071
- exports.ComboboxEmpty = ComboboxEmpty;
1072
- exports.ComboboxGroup = ComboboxGroup;
1073
- exports.ComboboxInput = ComboboxInput;
1074
- exports.ComboboxItem = ComboboxItem;
1075
- exports.ComboboxItemIndicator = ComboboxItemIndicator;
1076
- exports.ComboboxLabel = ComboboxLabel;
1077
- exports.ComboboxPortal = ComboboxPortal;
1078
- exports.ComboboxRoot = ComboboxRoot;
1079
- exports.ComboboxSeparator = ComboboxSeparator;
1080
- exports.ComboboxTrigger = ComboboxTrigger;
1081
- exports.ComboboxViewport = ComboboxViewport;
1082
- exports.comboboxAnchorProps = comboboxAnchorProps;
1083
- exports.comboboxArrowProps = comboboxArrowProps;
1084
- exports.comboboxCancelProps = comboboxCancelProps;
1085
- exports.comboboxContentEmits = comboboxContentEmits;
1086
- exports.comboboxContentImplEmits = comboboxContentImplEmits;
1087
- exports.comboboxContentImplProps = comboboxContentImplProps;
1088
- exports.comboboxContentProps = comboboxContentProps;
1089
- exports.comboboxEmptyProps = comboboxEmptyProps;
1090
- exports.comboboxGroupProps = comboboxGroupProps;
1091
- exports.comboboxInputProps = comboboxInputProps;
1092
- exports.comboboxItemEmits = comboboxItemEmits;
1093
- exports.comboboxItemIndicatorProps = comboboxItemIndicatorProps;
1094
- exports.comboboxItemProps = comboboxItemProps;
1095
- exports.comboboxLabelProps = comboboxLabelProps;
1096
- exports.comboboxPortalProps = comboboxPortalProps;
1097
- exports.comboboxRootEmits = comboboxRootEmits;
1098
- exports.comboboxRootProps = comboboxRootProps;
1099
- exports.comboboxSeparatorProps = comboboxSeparatorProps;
1100
- exports.comboboxTriggerProps = comboboxTriggerProps;
1101
- exports.comboboxViewportProps = comboboxViewportProps;