@hoci/components 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,831 @@
1
+ import { classPropType, defineHookComponent, defineHookEmits, defineHookProps, elementRef, getFirstChilld, isWindow, labelPropType, throttleByRaf, toReactive, useElement, useSharedConfig, valuePropType } from "@hoci/shared";
2
+ import { KeepAlive, Teleport, computed, defineComponent, h, inject, provide, reactive, ref, renderSlot, shallowRef, triggerRef, watch, watchPostEffect } from "vue";
3
+ import { isDefined, syncRef, tryOnScopeDispose, useElementBounding, useElementVisibility, useEventListener } from "@vueuse/core";
4
+ import { capitalize, cls, each, px } from "tslx";
5
+ import { affixProps, configProviderProps, fileUploadEmits, fileUploadProps, iconProps, itemEmits, itemProps, popoverEmits, popoverProps, provideSharedConfig, selectionEmits, selectionProps, switchEmits, switchProps, useAffix, useFileUpload, useIcon, usePopover, useSelectionItem, useSelectionList, useSwitch } from "@hoci/core";
6
+ import { Virtualizer, elementScroll, observeElementOffset, observeElementRect } from "@tanstack/virtual-core";
7
+
8
+ //#region rolldown:runtime
9
+ var __defProp = Object.defineProperty;
10
+ var __exportAll = (all, symbols) => {
11
+ let target = {};
12
+ for (var name in all) {
13
+ __defProp(target, name, {
14
+ get: all[name],
15
+ enumerable: true
16
+ });
17
+ }
18
+ if (symbols) {
19
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
20
+ }
21
+ return target;
22
+ };
23
+
24
+ //#endregion
25
+ //#region ../core/src/affix/index.ts
26
+ const affixProps$1 = defineHookProps({
27
+ fixedClass: {
28
+ type: String,
29
+ default: ""
30
+ },
31
+ offset: {
32
+ type: Number,
33
+ default: 0
34
+ },
35
+ position: {
36
+ type: String,
37
+ default: "top"
38
+ },
39
+ target: { type: [
40
+ String,
41
+ Object,
42
+ Function
43
+ ] },
44
+ zIndex: {
45
+ type: Number,
46
+ default: 998
47
+ }
48
+ });
49
+ const affixEmits = defineHookEmits(["scroll", "change"]);
50
+ const AFFIX_TARGET_KEY = Symbol("AFFIX_TARGET_KEY");
51
+ function getTargetRect(target) {
52
+ return isWindow(target) ? {
53
+ top: 0,
54
+ bottom: window.innerHeight
55
+ } : target.getBoundingClientRect();
56
+ }
57
+ const useAffix$1 = defineHookComponent({
58
+ props: affixProps$1,
59
+ setup(props, { emit }) {
60
+ const wrapperRef = elementRef();
61
+ const wrapperRect = toReactive(useElementBounding(wrapperRef));
62
+ const parentRef = inject(AFFIX_TARGET_KEY, void 0);
63
+ const targetRef = useElement(props.target, parentRef);
64
+ const isFixed = ref(false);
65
+ const placeholderStyle = ref({});
66
+ const fixedStyle = ref({});
67
+ const className = computed(() => {
68
+ return isFixed.value ? props.fixedClass : "";
69
+ });
70
+ const wrapperVisible = useElementVisibility(wrapperRef);
71
+ const containerRef = computed(() => {
72
+ if (!wrapperVisible.value) return null;
73
+ return targetRef.value ?? window;
74
+ });
75
+ const updatePosition = throttleByRaf(async () => {
76
+ if (!wrapperRef.value || !containerRef.value) return;
77
+ if (wrapperRect.width * wrapperRect.height === 0) return;
78
+ const newPlaceholderStyles = {
79
+ width: px(wrapperRect.width),
80
+ height: px(wrapperRect.height)
81
+ };
82
+ const targetRect = getTargetRect(containerRef.value);
83
+ let newIsFixed = false;
84
+ let newFixedStyles = {};
85
+ const offset = props.offset;
86
+ if (props.position === "top") {
87
+ newIsFixed = wrapperRect.top - targetRect.top < offset && offset >= 0;
88
+ newFixedStyles = newIsFixed ? {
89
+ position: "fixed",
90
+ zIndex: props.zIndex,
91
+ top: px(targetRect.top + offset)
92
+ } : {};
93
+ } else {
94
+ newIsFixed = targetRect.bottom - wrapperRect.bottom < offset;
95
+ newFixedStyles = newIsFixed ? {
96
+ position: "fixed",
97
+ bottom: px(window.innerHeight - targetRect.bottom + offset)
98
+ } : {};
99
+ }
100
+ if (newIsFixed !== isFixed.value) {
101
+ isFixed.value = newIsFixed;
102
+ emit("change", newIsFixed);
103
+ }
104
+ placeholderStyle.value = newPlaceholderStyles;
105
+ fixedStyle.value = {
106
+ ...newFixedStyles,
107
+ ...newIsFixed ? newPlaceholderStyles : {}
108
+ };
109
+ });
110
+ useEventListener(containerRef, "scroll", () => {
111
+ emit("scroll");
112
+ updatePosition();
113
+ });
114
+ useEventListener(containerRef, "resize", updatePosition);
115
+ watchPostEffect(updatePosition);
116
+ return {
117
+ className,
118
+ wrapperRef,
119
+ containerRef,
120
+ isFixed,
121
+ placeholderStyle,
122
+ fixedStyle,
123
+ updatePosition
124
+ };
125
+ }
126
+ });
127
+ function provideAffixTarget(target) {
128
+ provide(AFFIX_TARGET_KEY, target);
129
+ }
130
+
131
+ //#endregion
132
+ //#region ../core/src/affix-target/component.ts
133
+ const HiAffixTarget = defineComponent({
134
+ name: "HiAffixTarget",
135
+ setup(_, context) {
136
+ const targetRef = elementRef();
137
+ provideAffixTarget(targetRef);
138
+ return () => h("div", {
139
+ ref: targetRef,
140
+ ...context.attrs
141
+ }, renderSlot(context.slots, "default"));
142
+ }
143
+ });
144
+
145
+ //#endregion
146
+ //#region ../core/src/affix/component.ts
147
+ const HiAffix = defineComponent({
148
+ name: "HiAffix",
149
+ props: {
150
+ ...affixProps,
151
+ as: {
152
+ type: String,
153
+ default: "div"
154
+ }
155
+ },
156
+ setup(props, context) {
157
+ const { className, wrapperRef, isFixed, placeholderStyle, fixedStyle } = useAffix(props, context);
158
+ return () => h(props.as, { ref: wrapperRef }, [isFixed.value && h("div", { style: placeholderStyle.value }), h("div", {
159
+ class: className.value,
160
+ style: fixedStyle.value
161
+ }, renderSlot(context.slots, "default"))]);
162
+ }
163
+ });
164
+
165
+ //#endregion
166
+ //#region ../core/src/config-provider/component.ts
167
+ const HiConfigProvider = defineComponent({
168
+ props: {
169
+ ...configProviderProps,
170
+ as: { type: String }
171
+ },
172
+ setup(props, context) {
173
+ provideSharedConfig(props);
174
+ return () => {
175
+ const content = renderSlot(context.slots, "default", void 0);
176
+ if (props.as) return h(props.as, content);
177
+ return content;
178
+ };
179
+ }
180
+ });
181
+
182
+ //#endregion
183
+ //#region ../core/src/file-upload/component.ts
184
+ const HiFileUpload = defineComponent({
185
+ name: "HiFileUpload",
186
+ props: {
187
+ ...fileUploadProps,
188
+ accept: {
189
+ type: String,
190
+ default: "*/*"
191
+ },
192
+ as: {
193
+ type: String,
194
+ default: "div"
195
+ }
196
+ },
197
+ emits: fileUploadEmits,
198
+ setup(props, context) {
199
+ const { slots } = context;
200
+ const { fileInputRef, files, openFileInput } = useFileUpload(props, context);
201
+ return () => {
202
+ return h(props.as, { onClick: openFileInput }, [h("input", {
203
+ ref: fileInputRef,
204
+ type: "file",
205
+ accept: props.accept,
206
+ multiple: props.multiple,
207
+ style: { display: "none" }
208
+ }), renderSlot(slots, "default", { files: files.value })]);
209
+ };
210
+ }
211
+ });
212
+
213
+ //#endregion
214
+ //#region ../core/src/icon/component.ts
215
+ const HiIcon = defineComponent({
216
+ props: {
217
+ ...iconProps,
218
+ as: {
219
+ type: String,
220
+ default: "div"
221
+ }
222
+ },
223
+ setup(props, context) {
224
+ const { style } = useIcon(props, context);
225
+ return () => {
226
+ return h(props.as, { style: style.value });
227
+ };
228
+ }
229
+ });
230
+
231
+ //#endregion
232
+ //#region ../core/src/item/component.ts
233
+ const HiItem = defineComponent({
234
+ name: "HiItem",
235
+ props: {
236
+ ...itemProps,
237
+ as: {
238
+ type: String,
239
+ default: "div"
240
+ }
241
+ },
242
+ emits: itemEmits,
243
+ setup(props, context) {
244
+ const { render, activate, className, isDisabled, activateEvent } = useSelectionItem(props, context);
245
+ return () => h(props.as, {
246
+ class: className.value,
247
+ [`on${capitalize(activateEvent.value)}`]: activate,
248
+ disabled: isDisabled.value
249
+ }, render());
250
+ }
251
+ });
252
+
253
+ //#endregion
254
+ //#region ../core/src/popover/component.ts
255
+ const HiPopover = defineComponent({
256
+ name: "HiPopover",
257
+ props: {
258
+ ...popoverProps,
259
+ as: {
260
+ type: String,
261
+ default: "div"
262
+ }
263
+ },
264
+ emits: popoverEmits,
265
+ setup(props, context) {
266
+ const { triggerRef, popupClass, events, popupRef, popupStyle } = usePopover(props, context);
267
+ return () => {
268
+ let content = h("div", {
269
+ class: popupClass.value,
270
+ style: popupStyle.value,
271
+ ref: popupRef
272
+ }, renderSlot(context.slots, "popup"));
273
+ if (props.teleport) content = h(Teleport, { to: props.teleport === true ? "body" : props.teleport }, content);
274
+ return h(props.as, {
275
+ ref: triggerRef,
276
+ ...events
277
+ }, [renderSlot(context.slots, "default"), content]);
278
+ };
279
+ }
280
+ });
281
+
282
+ //#endregion
283
+ //#region ../core/src/selection/component.ts
284
+ const HiSelection = defineComponent({
285
+ name: "HiSelection",
286
+ props: {
287
+ ...selectionProps,
288
+ as: {
289
+ type: String,
290
+ default: "div"
291
+ }
292
+ },
293
+ emits: selectionEmits,
294
+ setup(props, context) {
295
+ const { render } = useSelectionList(props, context);
296
+ return () => h(props.as, {}, render());
297
+ }
298
+ });
299
+
300
+ //#endregion
301
+ //#region ../core/src/switch/component.ts
302
+ const HiSwitch = defineComponent({
303
+ name: "HiSwitch",
304
+ props: {
305
+ ...switchProps,
306
+ as: {
307
+ type: String,
308
+ default: "div"
309
+ }
310
+ },
311
+ emits: switchEmits,
312
+ setup(props, context) {
313
+ const { slots } = context;
314
+ const { className, toggle, modelValue, isDisabled, activateEvent } = useSwitch(props, context);
315
+ return () => {
316
+ return h(props.as, {
317
+ class: className.value,
318
+ [`on${capitalize(activateEvent.value)}`]: toggle
319
+ }, renderSlot(slots, "default", {
320
+ active: modelValue.value,
321
+ isDisabled: isDisabled.value
322
+ }));
323
+ };
324
+ }
325
+ });
326
+
327
+ //#endregion
328
+ //#region ../core/src/selection/index.ts
329
+ const selectionProps$1 = defineHookProps({
330
+ modelValue: {
331
+ type: valuePropType,
332
+ default: () => null
333
+ },
334
+ activeClass: {
335
+ type: classPropType,
336
+ default: "active"
337
+ },
338
+ itemClass: {
339
+ type: classPropType,
340
+ default: ""
341
+ },
342
+ disabledClass: {
343
+ type: classPropType,
344
+ default: "disabled"
345
+ },
346
+ unactiveClass: {
347
+ type: classPropType,
348
+ default: ""
349
+ },
350
+ label: { type: labelPropType },
351
+ multiple: {
352
+ type: [
353
+ Boolean,
354
+ Number,
355
+ Array
356
+ ],
357
+ default: () => false
358
+ },
359
+ clearable: { type: Boolean },
360
+ defaultValue: {
361
+ type: valuePropType,
362
+ default: () => null
363
+ },
364
+ activateEvent: { type: String }
365
+ });
366
+ const selectionEmits$1 = defineHookEmits([
367
+ "update:modelValue",
368
+ "change",
369
+ "load",
370
+ "unload",
371
+ "reject"
372
+ ]);
373
+ const HiSelectionContextSymbol = Symbol("[hi-selection]context");
374
+ function useSelectionContext() {
375
+ return inject(HiSelectionContextSymbol, {
376
+ isActive: () => false,
377
+ activate: () => {},
378
+ changeActive: () => {},
379
+ reject: () => {},
380
+ activeClass: "active",
381
+ unactiveClass: "unactive",
382
+ disabledClass: "disabled",
383
+ itemClass: "",
384
+ activateEvent: useSharedConfig().activateEvent,
385
+ label: null,
386
+ multiple: false,
387
+ limit: [0, Number.POSITIVE_INFINITY]
388
+ });
389
+ }
390
+ const useSelectionList$1 = defineHookComponent({
391
+ props: selectionProps$1,
392
+ emits: selectionEmits$1,
393
+ setup(props, { emit, slots }) {
394
+ const options = reactive([]);
395
+ function toArray(value) {
396
+ if (!isDefined(value)) return [];
397
+ if (props.multiple && Array.isArray(value)) return value.filter((v) => v != null || v !== void 0);
398
+ return [value];
399
+ }
400
+ const actives = reactive([...toArray(props.modelValue ?? props.defaultValue)]);
401
+ const currentValue = computed({
402
+ get() {
403
+ return props.multiple ? actives : actives[0];
404
+ },
405
+ set(val) {
406
+ actives.splice(0, actives.length, ...toArray(val));
407
+ }
408
+ });
409
+ syncRef(currentValue, computed({
410
+ get() {
411
+ return props.modelValue ?? props.defaultValue;
412
+ },
413
+ set(val) {
414
+ emit("update:modelValue", val);
415
+ }
416
+ }), {
417
+ immediate: true,
418
+ deep: true
419
+ });
420
+ const emitChange = () => emit("change", currentValue.value);
421
+ function isActive(value) {
422
+ return actives.includes(value);
423
+ }
424
+ const multipleActive = computed(() => !!props.multiple);
425
+ /**
426
+ * [min,max]
427
+ */
428
+ const multipleLimit = computed(() => {
429
+ if (Array.isArray(props.multiple)) {
430
+ if (props.multiple[1] === void 0) return [props.multiple[0], Number.POSITIVE_INFINITY];
431
+ return props.multiple;
432
+ }
433
+ return [0, Number.POSITIVE_INFINITY];
434
+ });
435
+ function activate(value) {
436
+ const [min, max] = multipleLimit.value;
437
+ if (isActive(value)) {
438
+ if (multipleActive.value && actives.length > min || props.clearable) {
439
+ actives.splice(actives.indexOf(value), 1);
440
+ emitChange();
441
+ }
442
+ } else if (props.multiple) {
443
+ if (actives.length < max) {
444
+ actives.push(value);
445
+ emitChange();
446
+ }
447
+ } else {
448
+ actives.splice(0, actives.length, value);
449
+ emitChange();
450
+ }
451
+ }
452
+ function reject(value) {
453
+ emit("reject", value);
454
+ }
455
+ const init = (option) => {
456
+ function remove() {
457
+ const index = options.findIndex((e) => e.id === option.id);
458
+ if (index > -1) {
459
+ options.splice(index, 1);
460
+ emit("unload", option);
461
+ }
462
+ }
463
+ for (let i = 0; i < options.length; i++) if (options[i].value === option.value) {
464
+ options.splice(i, 1);
465
+ i--;
466
+ }
467
+ options.push(option);
468
+ emit("load", option);
469
+ return remove;
470
+ };
471
+ const sharedConfig = useSharedConfig();
472
+ provide(HiSelectionContextSymbol, toReactive({
473
+ activeClass: computed(() => cls(props.activeClass)),
474
+ unactiveClass: computed(() => cls(props.unactiveClass)),
475
+ disabledClass: computed(() => cls(props.disabledClass)),
476
+ itemClass: computed(() => cls(props.itemClass)),
477
+ label: computed(() => props.label),
478
+ multiple: multipleActive,
479
+ limit: multipleLimit,
480
+ clearable: computed(() => props.clearable),
481
+ defaultValue: computed(() => props.defaultValue),
482
+ activateEvent: computed(() => props.activateEvent ?? sharedConfig.activateEvent),
483
+ active: currentValue,
484
+ activate,
485
+ changeActive: activate,
486
+ isActive,
487
+ reject,
488
+ init
489
+ }));
490
+ const renderItem = () => {
491
+ const children = options.filter((e) => actives.includes(e.value)).map((e) => e.render());
492
+ return props.multiple ? children : getFirstChilld(children);
493
+ };
494
+ const slotData = {
495
+ isActive,
496
+ changeActive: activate,
497
+ renderItem
498
+ };
499
+ const render = () => {
500
+ return renderSlot(slots, "default", slotData);
501
+ };
502
+ return {
503
+ options,
504
+ actives,
505
+ isActive,
506
+ changeActive: activate,
507
+ renderItem,
508
+ render
509
+ };
510
+ }
511
+ });
512
+
513
+ //#endregion
514
+ //#region ../core/src/item/index.ts
515
+ const itemProps$1 = defineHookProps({
516
+ value: {
517
+ type: valuePropType,
518
+ default() {
519
+ return Math.random().toString(16).slice(2);
520
+ }
521
+ },
522
+ label: { type: [Function, String] },
523
+ keepAlive: {
524
+ type: Boolean,
525
+ default: () => true
526
+ },
527
+ activateEvent: { type: String },
528
+ disabled: {
529
+ type: Boolean,
530
+ default: false
531
+ }
532
+ });
533
+ const itemEmits$1 = defineHookEmits(["reject"]);
534
+ const useSelectionItem$1 = defineHookComponent({
535
+ props: itemProps$1,
536
+ emits: itemEmits$1,
537
+ setup(props, { slots, emit }) {
538
+ const context = useSelectionContext();
539
+ const activate = () => {
540
+ if (props.disabled) {
541
+ emit("reject", props.value);
542
+ context.reject(props.value);
543
+ return;
544
+ }
545
+ context.activate(props.value);
546
+ };
547
+ const label = computed(() => {
548
+ let label = props.label ?? context.label;
549
+ if (label && typeof label === "function") label = label(props.value);
550
+ return Array.isArray(label) ? label : [label];
551
+ });
552
+ function render() {
553
+ return slots.default?.({
554
+ active: context.isActive(props.value),
555
+ activate
556
+ }) ?? label.value.filter(Boolean);
557
+ }
558
+ let remove = () => {};
559
+ const init = context.init;
560
+ if (init) {
561
+ watch(() => props.value, (value) => {
562
+ remove();
563
+ remove = init({
564
+ id: Math.random().toString(16).slice(2),
565
+ label: typeof props.label === "string" ? props.label : void 0,
566
+ value,
567
+ render
568
+ });
569
+ }, { immediate: true });
570
+ tryOnScopeDispose(remove);
571
+ }
572
+ const isActive = computed(() => context.isActive(props.value));
573
+ const isDisabled = computed(() => props.disabled);
574
+ return {
575
+ activate,
576
+ render,
577
+ isActive,
578
+ isDisabled,
579
+ className: computed(() => {
580
+ const array = [context.itemClass];
581
+ if (!isDisabled.value) array.push(context.isActive(props.value) ? context.activeClass : context.unactiveClass);
582
+ else array.push(context.disabledClass);
583
+ return cls(array);
584
+ }),
585
+ activateEvent: computed(() => props.activateEvent ?? context.activateEvent),
586
+ label
587
+ };
588
+ }
589
+ });
590
+
591
+ //#endregion
592
+ //#region ../core/src/tab-pane/component.ts
593
+ const HiTabPane = defineComponent({
594
+ name: "HiTabPane",
595
+ props: { ...itemProps$1 },
596
+ emits: itemEmits$1,
597
+ inheritAttrs: true,
598
+ setup(props, context) {
599
+ const { className, activateEvent, activate, isDisabled, label } = useSelectionItem$1(props, context);
600
+ return () => {
601
+ return h("div", {
602
+ class: className.value,
603
+ [`on${capitalize(activateEvent.value)}`]: activate,
604
+ disabled: isDisabled.value
605
+ }, label.value);
606
+ };
607
+ }
608
+ });
609
+
610
+ //#endregion
611
+ //#region ../core/src/tabs/component.ts
612
+ const HiTabs = defineComponent({
613
+ name: "HiTabs",
614
+ props: {
615
+ ...selectionProps$1,
616
+ headerClass: { type: classPropType },
617
+ as: {
618
+ type: String,
619
+ default: "div"
620
+ },
621
+ headerAs: {
622
+ type: String,
623
+ default: "div"
624
+ },
625
+ contentAs: {
626
+ type: String,
627
+ default: "div"
628
+ },
629
+ contentClass: { type: classPropType },
630
+ keepAlive: {
631
+ type: [Boolean, Object],
632
+ default: false
633
+ }
634
+ },
635
+ inheritAttrs: true,
636
+ setup(props, context) {
637
+ const selection = useSelectionList$1(props, context);
638
+ return () => {
639
+ let component = selection.renderItem();
640
+ if (props.keepAlive) component = h(KeepAlive, { ...typeof props.keepAlive === "object" ? props.keepAlive : {} }, component);
641
+ if (context.slots.content) component = context.slots.content({ component });
642
+ else component = h(props.contentAs, { class: props.contentClass }, component);
643
+ return h(props.as, [h(props.headerAs, { class: props.headerClass }, renderSlot(context.slots, "default")), component]);
644
+ };
645
+ }
646
+ });
647
+
648
+ //#endregion
649
+ //#region ../core/src/virtual-list/index.ts
650
+ const virtualListProps = defineHookProps({
651
+ options: {
652
+ type: Object,
653
+ default: () => ({})
654
+ },
655
+ count: {
656
+ type: Number,
657
+ default: () => 0
658
+ },
659
+ estimateSize: {
660
+ type: [Function, Number],
661
+ default: () => 50
662
+ },
663
+ horizontal: {
664
+ type: Boolean,
665
+ default: () => false
666
+ }
667
+ });
668
+ const virtualListEmits = defineHookEmits({
669
+ scrollEnd: () => true,
670
+ scrollStart: () => true,
671
+ scroll: (_) => true
672
+ });
673
+ const useVirtualList = defineHookComponent({
674
+ props: virtualListProps,
675
+ emits: virtualListEmits,
676
+ setup(props, context) {
677
+ const { emit } = context;
678
+ const scrollElementRef = elementRef();
679
+ const propsEstimateSize = props.estimateSize;
680
+ const estimateSize = typeof propsEstimateSize === "function" ? propsEstimateSize : () => propsEstimateSize;
681
+ const options = computed(() => {
682
+ return {
683
+ ...props.options || {},
684
+ count: props.count,
685
+ estimateSize,
686
+ horizontal: props.horizontal,
687
+ getScrollElement: () => scrollElementRef.value,
688
+ observeElementRect,
689
+ observeElementOffset,
690
+ scrollToFn: elementScroll
691
+ };
692
+ });
693
+ const virtualizer = new Virtualizer(options.value);
694
+ const state = shallowRef(virtualizer);
695
+ const virtualItems = computed(() => state.value.getVirtualItems());
696
+ const virtualIndexes = computed(() => state.value.getVirtualIndexes());
697
+ const totalSize = computed(() => state.value.getTotalSize());
698
+ watch(virtualIndexes, (indexes) => {
699
+ if (indexes.length === 0) return;
700
+ if (indexes[indexes.length - 1] === props.count - 1) emit("scrollEnd");
701
+ else if (indexes[0] === 0) emit("scrollStart");
702
+ emit("scroll", indexes);
703
+ }, { immediate: true });
704
+ watch(options, (opts) => {
705
+ virtualizer.setOptions({
706
+ ...opts,
707
+ onChange: (instance, sync) => {
708
+ opts.onChange?.(instance, sync);
709
+ triggerRef(state);
710
+ }
711
+ });
712
+ virtualizer._willUpdate();
713
+ triggerRef(state);
714
+ }, { immediate: true });
715
+ watch(scrollElementRef, (el) => {
716
+ if (el) {
717
+ virtualizer._willUpdate();
718
+ triggerRef(state);
719
+ }
720
+ }, { immediate: true });
721
+ tryOnScopeDispose(virtualizer._didMount());
722
+ const measureElement = (el) => {
723
+ virtualizer.measureElement(el);
724
+ };
725
+ const scrollToIndex = (index, options = { behavior: "smooth" }) => {
726
+ virtualizer.scrollToIndex(index, options);
727
+ };
728
+ const scrollToStart = (options = { behavior: "smooth" }) => {
729
+ scrollToIndex(0, options);
730
+ };
731
+ const scrollToEnd = (options = { behavior: "smooth" }) => {
732
+ scrollToIndex(props.count - 1, options);
733
+ };
734
+ return {
735
+ virtualizer,
736
+ virtualItems,
737
+ virtualIndexes,
738
+ totalSize,
739
+ scrollElementRef,
740
+ measureElement,
741
+ scrollToIndex,
742
+ scrollToStart,
743
+ scrollToEnd
744
+ };
745
+ }
746
+ });
747
+
748
+ //#endregion
749
+ //#region ../core/src/virtual-list/component.ts
750
+ const HiVirtualList = defineComponent({
751
+ name: "HiVirtualList",
752
+ inheritAttrs: true,
753
+ props: {
754
+ ...virtualListProps,
755
+ as: {
756
+ type: String,
757
+ default: () => "div"
758
+ },
759
+ wrapperAs: {
760
+ type: String,
761
+ default: () => "div"
762
+ },
763
+ wrapperStyle: {
764
+ type: Object,
765
+ default: () => ({})
766
+ },
767
+ wrapperClass: {
768
+ type: classPropType,
769
+ default: () => ""
770
+ }
771
+ },
772
+ emits: virtualListEmits,
773
+ setup(props, context) {
774
+ const { slots, expose } = context;
775
+ const { totalSize, scrollElementRef, virtualItems, scrollToIndex, scrollToStart, scrollToEnd } = useVirtualList(props, context);
776
+ expose({
777
+ scrollToIndex,
778
+ scrollToStart,
779
+ scrollToEnd
780
+ });
781
+ const wrapperStyle = computed(() => {
782
+ return {
783
+ position: "relative",
784
+ [props.horizontal ? "width" : "height"]: `${totalSize.value}px`,
785
+ ...props.wrapperStyle
786
+ };
787
+ });
788
+ return () => h(props.as, {
789
+ ref: scrollElementRef,
790
+ style: { [props.horizontal ? "overflowX" : "overflowY"]: "auto" }
791
+ }, [h(props.wrapperAs, {
792
+ style: wrapperStyle.value,
793
+ class: props.wrapperClass
794
+ }, each(virtualItems.value, (item) => {
795
+ return renderSlot(slots, "item", {
796
+ ...item,
797
+ style: {
798
+ position: "absolute",
799
+ [props.horizontal ? "left" : "top"]: `${item.start}px`,
800
+ [props.horizontal ? "width" : "height"]: `${item.size}px`
801
+ }
802
+ });
803
+ }))]);
804
+ }
805
+ });
806
+
807
+ //#endregion
808
+ //#region components.ts
809
+ var components_exports = /* @__PURE__ */ __exportAll({
810
+ HiAffix: () => HiAffix,
811
+ HiAffixTarget: () => HiAffixTarget,
812
+ HiConfigProvider: () => HiConfigProvider,
813
+ HiFileUpload: () => HiFileUpload,
814
+ HiIcon: () => HiIcon,
815
+ HiItem: () => HiItem,
816
+ HiPopover: () => HiPopover,
817
+ HiSelection: () => HiSelection,
818
+ HiSwitch: () => HiSwitch,
819
+ HiTabPane: () => HiTabPane,
820
+ HiTabs: () => HiTabs,
821
+ HiVirtualList: () => HiVirtualList
822
+ });
823
+
824
+ //#endregion
825
+ //#region install.ts
826
+ function install(app) {
827
+ for (const key in components_exports) app.component(key, components_exports[key]);
828
+ }
829
+
830
+ //#endregion
831
+ export { HiAffix, HiAffixTarget, HiConfigProvider, HiFileUpload, HiIcon, HiItem, HiPopover, HiSelection, HiSwitch, HiTabPane, HiTabs, HiVirtualList, install };