gi-component 0.0.46 → 0.0.48

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.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineComponent, createElementBlock, openBlock, createElementVNode, getCurrentInstance, onMounted, watch, toValue, toRef, nextTick, onUnmounted, useAttrs, computed, createBlock, unref, mergeProps, withCtx, renderSlot, createTextVNode, toDisplayString, useSlots, normalizeClass, createCommentVNode, normalizeStyle, createVNode, createSlots, Fragment, renderList, mergeModels, useModel, ref, resolveDynamicComponent, resolveComponent, h, createApp, onUpdated, inject, toRefs, watchEffect, reactive, provide, normalizeProps, guardReactiveProps, useTemplateRef } from "vue";
1
+ import { defineComponent, createElementBlock, openBlock, createElementVNode, getCurrentInstance, ref, onMounted, watch, toValue, toRef, nextTick, onUnmounted, useAttrs, computed, createBlock, unref, mergeProps, withCtx, renderSlot, createTextVNode, toDisplayString, useSlots, normalizeClass, createCommentVNode, normalizeStyle, createVNode, createSlots, Fragment, renderList, mergeModels, useModel, resolveDynamicComponent, resolveComponent, h, createApp, onUpdated, inject, toRefs, watchEffect, reactive, provide, normalizeProps, guardReactiveProps, useTemplateRef } from "vue";
2
2
  import * as El from "element-plus";
3
3
  import El__default, { ElButton, ElSpace, ElDescriptions, ElDescriptionsItem, ElDialog, ElDrawer, ElInput, ElForm, ElTable, ElTableColumn, ElFormItem, ElText, ElMessage, ElIcon, ElSplitter, ElSplitterPanel, ElRow, ElPagination, ElTabs, ElTabPane, ElCheckbox, ElScrollbar, ElTree, ElCheckboxGroup, ElEmpty } from "element-plus";
4
4
  /*! Element Plus Icons Vue v2.3.2 */
@@ -300,6 +300,16 @@ function resolveElement(target, root) {
300
300
  const scope = root ?? document;
301
301
  return scope.querySelector(normalizeSelector(target));
302
302
  }
303
+ function getMaxScrollLeft(scrollEl) {
304
+ return Math.max(0, scrollEl.scrollWidth - scrollEl.clientWidth);
305
+ }
306
+ const SCROLL_EDGE_EPSILON = 1;
307
+ function canScrollToLeft(scrollEl) {
308
+ return scrollEl.scrollLeft > SCROLL_EDGE_EPSILON;
309
+ }
310
+ function canScrollToRight(scrollEl) {
311
+ return scrollEl.scrollLeft < getMaxScrollLeft(scrollEl) - SCROLL_EDGE_EPSILON;
312
+ }
303
313
  const WHEEL_SCROLL_LERP = 0.4;
304
314
  const WHEEL_LINE_HEIGHT = 16;
305
315
  function getWheelPixelDelta(event, scrollEl) {
@@ -312,11 +322,10 @@ function getWheelPixelDelta(event, scrollEl) {
312
322
  return delta;
313
323
  }
314
324
  function clampScrollLeft(scrollEl, left) {
315
- const maxScroll = Math.max(0, scrollEl.scrollWidth - scrollEl.clientWidth);
316
- return Math.max(0, Math.min(left, maxScroll));
325
+ return Math.max(0, Math.min(left, getMaxScrollLeft(scrollEl)));
317
326
  }
318
327
  function scrollItemToCenter(scrollEl, activeEl, behavior = "smooth") {
319
- const maxScroll = scrollEl.scrollWidth - scrollEl.clientWidth;
328
+ const maxScroll = getMaxScrollLeft(scrollEl);
320
329
  if (maxScroll <= 0) {
321
330
  return;
322
331
  }
@@ -329,27 +338,65 @@ function scrollItemToCenter(scrollEl, activeEl, behavior = "smooth") {
329
338
  behavior
330
339
  });
331
340
  }
341
+ function setElementVisible(el, visible) {
342
+ if (!el) {
343
+ return;
344
+ }
345
+ el.style.display = visible ? "flex" : "none";
346
+ }
347
+ function setBtnDisabled(el, disabled, disabledClassName) {
348
+ if (!el) {
349
+ return;
350
+ }
351
+ if (disabledClassName) {
352
+ el.classList.toggle(disabledClassName, disabled);
353
+ }
354
+ if (disabled) {
355
+ el.setAttribute("aria-disabled", "true");
356
+ } else {
357
+ el.removeAttribute("aria-disabled");
358
+ }
359
+ }
332
360
  function useNavTabs(options) {
333
361
  const {
334
362
  tabEl,
335
363
  tabScrollEl,
336
364
  tabItemClassName,
337
365
  activeValue,
338
- wheelSpeed = 1
366
+ wheelSpeed = 1,
367
+ tabLeftScrollBtnEl,
368
+ tabRightScrollBtnEl,
369
+ scrollBtnStepRatio = 0.6,
370
+ scrollBtnMinStep = 120,
371
+ navBtnDisabledClassName
339
372
  } = options;
340
373
  const activeClassName = `${tabItemClassName}--active`;
341
374
  const itemSelector = normalizeSelector(tabItemClassName);
375
+ const showNavBtn = ref(false);
376
+ const canScrollLeft = ref(false);
377
+ const canScrollRight = ref(false);
342
378
  let rootEl = null;
343
379
  let scrollEl = null;
380
+ let leftBtnEl = null;
381
+ let rightBtnEl = null;
344
382
  let resizeObserver = null;
345
383
  let wheelRafId = null;
346
384
  let wheelTargetScrollLeft = 0;
385
+ let navBtnRafId = null;
386
+ let onPrevClick = null;
387
+ let onNextClick = null;
347
388
  const cancelWheelAnimation = () => {
348
389
  if (wheelRafId !== null) {
349
390
  cancelAnimationFrame(wheelRafId);
350
391
  wheelRafId = null;
351
392
  }
352
393
  };
394
+ const cancelWheelScroll = () => {
395
+ if (scrollEl) {
396
+ wheelTargetScrollLeft = scrollEl.scrollLeft;
397
+ }
398
+ cancelWheelAnimation();
399
+ };
353
400
  const runWheelAnimation = () => {
354
401
  if (!scrollEl) {
355
402
  cancelWheelAnimation();
@@ -360,17 +407,80 @@ function useNavTabs(options) {
360
407
  if (Math.abs(diff) < 0.5) {
361
408
  scrollEl.scrollLeft = wheelTargetScrollLeft;
362
409
  cancelWheelAnimation();
410
+ scheduleUpdateNavBtnState();
363
411
  return;
364
412
  }
365
413
  scrollEl.scrollLeft = current + diff * WHEEL_SCROLL_LERP;
366
414
  wheelRafId = requestAnimationFrame(runWheelAnimation);
367
415
  };
416
+ const updateNavBtnState = () => {
417
+ if (!scrollEl) {
418
+ showNavBtn.value = false;
419
+ canScrollLeft.value = false;
420
+ canScrollRight.value = false;
421
+ setElementVisible(leftBtnEl, false);
422
+ setElementVisible(rightBtnEl, false);
423
+ setBtnDisabled(leftBtnEl, false, navBtnDisabledClassName);
424
+ setBtnDisabled(rightBtnEl, false, navBtnDisabledClassName);
425
+ return;
426
+ }
427
+ const overflow = getMaxScrollLeft(scrollEl) > 1;
428
+ const scrollLeftEnabled = canScrollToLeft(scrollEl);
429
+ const scrollRightEnabled = canScrollToRight(scrollEl);
430
+ showNavBtn.value = overflow;
431
+ canScrollLeft.value = scrollLeftEnabled;
432
+ canScrollRight.value = scrollRightEnabled;
433
+ setElementVisible(leftBtnEl, overflow);
434
+ setElementVisible(rightBtnEl, overflow);
435
+ setBtnDisabled(leftBtnEl, overflow && !scrollLeftEnabled, navBtnDisabledClassName);
436
+ setBtnDisabled(rightBtnEl, overflow && !scrollRightEnabled, navBtnDisabledClassName);
437
+ };
438
+ const scheduleUpdateNavBtnState = () => {
439
+ if (navBtnRafId !== null) {
440
+ return;
441
+ }
442
+ navBtnRafId = requestAnimationFrame(() => {
443
+ navBtnRafId = null;
444
+ updateNavBtnState();
445
+ });
446
+ };
447
+ const cancelNavBtnRaf = () => {
448
+ if (navBtnRafId !== null) {
449
+ cancelAnimationFrame(navBtnRafId);
450
+ navBtnRafId = null;
451
+ }
452
+ };
453
+ const scrollByStep = (direction) => {
454
+ if (!scrollEl) {
455
+ return;
456
+ }
457
+ if (direction === -1 && !canScrollToLeft(scrollEl)) {
458
+ return;
459
+ }
460
+ if (direction === 1 && !canScrollToRight(scrollEl)) {
461
+ return;
462
+ }
463
+ cancelWheelScroll();
464
+ const maxScroll = getMaxScrollLeft(scrollEl);
465
+ if (maxScroll <= 0) {
466
+ return;
467
+ }
468
+ const step = Math.max(scrollBtnMinStep, scrollEl.clientWidth * scrollBtnStepRatio);
469
+ const target = clampScrollLeft(scrollEl, scrollEl.scrollLeft + direction * step);
470
+ if (Math.abs(target - scrollEl.scrollLeft) < 1) {
471
+ return;
472
+ }
473
+ scrollEl.scrollTo({ left: target, behavior: "smooth" });
474
+ };
368
475
  const resolveElements = () => {
369
476
  var _a, _b;
370
477
  const instanceRoot = (_b = (_a = getCurrentInstance()) == null ? void 0 : _a.proxy) == null ? void 0 : _b.$el;
371
478
  const fallbackRoot = instanceRoot instanceof HTMLElement ? instanceRoot : document;
372
479
  rootEl = resolveElement(toValue(tabEl), fallbackRoot);
373
- scrollEl = resolveElement(toValue(tabScrollEl), rootEl ?? fallbackRoot);
480
+ const scope = rootEl ?? fallbackRoot;
481
+ scrollEl = resolveElement(toValue(tabScrollEl), scope);
482
+ leftBtnEl = resolveElement(toValue(tabLeftScrollBtnEl), scope);
483
+ rightBtnEl = resolveElement(toValue(tabRightScrollBtnEl), scope);
374
484
  return Boolean(rootEl && scrollEl);
375
485
  };
376
486
  const findActiveItem = () => {
@@ -393,11 +503,12 @@ function useNavTabs(options) {
393
503
  if (!scrollEl) {
394
504
  return;
395
505
  }
396
- cancelWheelAnimation();
506
+ cancelWheelScroll();
397
507
  const activeItem = findActiveItem();
398
508
  if (activeItem) {
399
509
  scrollItemToCenter(scrollEl, activeItem, behavior);
400
510
  }
511
+ scheduleUpdateNavBtnState();
401
512
  };
402
513
  const handleWheel = (event) => {
403
514
  if (!scrollEl) {
@@ -418,19 +529,59 @@ function useNavTabs(options) {
418
529
  if (wheelRafId === null) {
419
530
  wheelRafId = requestAnimationFrame(runWheelAnimation);
420
531
  }
532
+ scheduleUpdateNavBtnState();
533
+ };
534
+ const handleScroll = () => {
535
+ scheduleUpdateNavBtnState();
421
536
  };
422
537
  const bindWheel = () => {
423
538
  scrollEl == null ? void 0 : scrollEl.addEventListener("wheel", handleWheel, { passive: false });
539
+ scrollEl == null ? void 0 : scrollEl.addEventListener("scroll", handleScroll, { passive: true });
424
540
  };
425
541
  const unbindWheel = () => {
426
542
  scrollEl == null ? void 0 : scrollEl.removeEventListener("wheel", handleWheel);
543
+ scrollEl == null ? void 0 : scrollEl.removeEventListener("scroll", handleScroll);
427
544
  cancelWheelAnimation();
428
545
  };
546
+ const bindNavButtons = () => {
547
+ unbindNavButtons();
548
+ if (leftBtnEl) {
549
+ onPrevClick = (event) => {
550
+ if ((leftBtnEl == null ? void 0 : leftBtnEl.getAttribute("aria-disabled")) === "true") {
551
+ event.preventDefault();
552
+ return;
553
+ }
554
+ scrollByStep(-1);
555
+ };
556
+ leftBtnEl.addEventListener("click", onPrevClick);
557
+ }
558
+ if (rightBtnEl) {
559
+ onNextClick = (event) => {
560
+ if ((rightBtnEl == null ? void 0 : rightBtnEl.getAttribute("aria-disabled")) === "true") {
561
+ event.preventDefault();
562
+ return;
563
+ }
564
+ scrollByStep(1);
565
+ };
566
+ rightBtnEl.addEventListener("click", onNextClick);
567
+ }
568
+ };
569
+ const unbindNavButtons = () => {
570
+ if (leftBtnEl && onPrevClick) {
571
+ leftBtnEl.removeEventListener("click", onPrevClick);
572
+ }
573
+ if (rightBtnEl && onNextClick) {
574
+ rightBtnEl.removeEventListener("click", onNextClick);
575
+ }
576
+ onPrevClick = null;
577
+ onNextClick = null;
578
+ };
429
579
  const bindResizeObserver = () => {
430
580
  if (!scrollEl || typeof ResizeObserver === "undefined") {
431
581
  return;
432
582
  }
433
583
  resizeObserver = new ResizeObserver(() => {
584
+ scheduleUpdateNavBtnState();
434
585
  scrollToActive("auto");
435
586
  });
436
587
  resizeObserver.observe(scrollEl);
@@ -439,23 +590,40 @@ function useNavTabs(options) {
439
590
  resizeObserver == null ? void 0 : resizeObserver.disconnect();
440
591
  resizeObserver = null;
441
592
  };
593
+ const teardown = () => {
594
+ unbindWheel();
595
+ unbindNavButtons();
596
+ unbindResizeObserver();
597
+ cancelWheelAnimation();
598
+ cancelNavBtnRaf();
599
+ rootEl = null;
600
+ scrollEl = null;
601
+ leftBtnEl = null;
602
+ rightBtnEl = null;
603
+ };
442
604
  const setup = async () => {
443
605
  await nextTick();
444
606
  if (!resolveElements()) {
445
607
  return;
446
608
  }
447
609
  bindWheel();
610
+ bindNavButtons();
448
611
  bindResizeObserver();
612
+ updateNavBtnState();
449
613
  scrollToActive("auto");
450
614
  };
451
615
  onMounted(() => {
452
616
  setup();
453
617
  });
454
618
  watch(
455
- () => [toValue(tabEl), toValue(tabScrollEl)],
619
+ () => [
620
+ toValue(tabEl),
621
+ toValue(tabScrollEl),
622
+ toValue(tabLeftScrollBtnEl),
623
+ toValue(tabRightScrollBtnEl)
624
+ ],
456
625
  () => {
457
- unbindWheel();
458
- unbindResizeObserver();
626
+ teardown();
459
627
  setup();
460
628
  }
461
629
  );
@@ -465,15 +633,16 @@ function useNavTabs(options) {
465
633
  });
466
634
  }
467
635
  onUnmounted(() => {
468
- unbindWheel();
469
- unbindResizeObserver();
470
- cancelWheelAnimation();
471
- rootEl = null;
472
- scrollEl = null;
636
+ teardown();
473
637
  });
474
638
  return {
475
639
  scrollToActive,
476
- getScrollEl: () => scrollEl
640
+ getScrollEl: () => scrollEl,
641
+ cancelWheelScroll,
642
+ scrollByStep,
643
+ showNavBtn,
644
+ canScrollLeft,
645
+ canScrollRight
477
646
  };
478
647
  }
479
648
  const _sfc_main$l = /* @__PURE__ */ defineComponent({
@@ -523,7 +692,8 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
523
692
  return { ...attrs, ...props, ...btnProps };
524
693
  });
525
694
  const btnText = computed(() => {
526
- return obj[props.type].btnText;
695
+ var _a;
696
+ return ((_a = obj == null ? void 0 : obj[props.type]) == null ? void 0 : _a.btnText) || "";
527
697
  });
528
698
  return (_ctx, _cache) => {
529
699
  return openBlock(), createBlock(unref(ElButton), mergeProps({
@@ -2512,13 +2682,18 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
2512
2682
  const { b } = useBemClass();
2513
2683
  const rootRef = ref(null);
2514
2684
  const scrollRef = ref(null);
2685
+ const leftBtnRef = ref(null);
2686
+ const rightBtnRef = ref(null);
2515
2687
  const tabItemClassName = b("nav-tabs-item");
2516
2688
  useNavTabs({
2517
2689
  tabEl: rootRef,
2518
2690
  tabScrollEl: scrollRef,
2519
2691
  tabItemClassName,
2520
2692
  activeValue: model,
2521
- wheelSpeed: props.wheelSpeed
2693
+ wheelSpeed: props.wheelSpeed,
2694
+ tabLeftScrollBtnEl: leftBtnRef,
2695
+ tabRightScrollBtnEl: rightBtnRef,
2696
+ navBtnDisabledClassName: b("nav-tabs__nav-btn--disabled")
2522
2697
  });
2523
2698
  function handleItemClick(item) {
2524
2699
  if (item.disabled) {
@@ -2540,32 +2715,62 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
2540
2715
  renderSlot(_ctx.$slots, "left-extra", {}, void 0, true)
2541
2716
  ], 2)) : createCommentVNode("", true),
2542
2717
  createElementVNode("div", {
2543
- ref_key: "scrollRef",
2544
- ref: scrollRef,
2545
- class: normalizeClass(unref(b)("nav-tabs__scroll"))
2718
+ class: normalizeClass(unref(b)("nav-tabs__scroll-wrap"))
2546
2719
  }, [
2547
- (openBlock(true), createElementBlock(Fragment, null, renderList(props.data, (item) => {
2548
- return openBlock(), createElementBlock("div", {
2549
- key: item.value,
2550
- class: normalizeClass([
2551
- unref(b)("nav-tabs-item"),
2552
- props.custom ? unref(b)("nav-tabs-item--custom") : {
2553
- [unref(b)("nav-tabs-item--active")]: model.value === item.value,
2554
- [unref(b)("nav-tabs-item--disabled")]: item.disabled
2555
- }
2720
+ createElementVNode("button", {
2721
+ ref_key: "leftBtnRef",
2722
+ ref: leftBtnRef,
2723
+ type: "button",
2724
+ class: normalizeClass([unref(b)("nav-tabs__nav-btn"), unref(b)("nav-tabs__nav-btn--prev")])
2725
+ }, [
2726
+ createVNode(unref(ElIcon), null, {
2727
+ default: withCtx(() => [
2728
+ createVNode(unref(arrow_left_default))
2556
2729
  ]),
2557
- "data-value": item.value,
2558
- onClick: ($event) => handleItemClick(item)
2559
- }, [
2560
- renderSlot(_ctx.$slots, "default", {
2561
- item,
2562
- active: model.value === item.value,
2563
- disabled: !!item.disabled
2564
- }, () => [
2565
- createTextVNode(toDisplayString(item.label), 1)
2566
- ], true)
2567
- ], 10, _hoisted_1$1);
2568
- }), 128))
2730
+ _: 1
2731
+ })
2732
+ ], 2),
2733
+ createElementVNode("div", {
2734
+ ref_key: "scrollRef",
2735
+ ref: scrollRef,
2736
+ class: normalizeClass(unref(b)("nav-tabs__scroll"))
2737
+ }, [
2738
+ (openBlock(true), createElementBlock(Fragment, null, renderList(props.data, (item) => {
2739
+ return openBlock(), createElementBlock("div", {
2740
+ key: item.value,
2741
+ class: normalizeClass([
2742
+ unref(b)("nav-tabs-item"),
2743
+ props.custom ? unref(b)("nav-tabs-item--custom") : {
2744
+ [unref(b)("nav-tabs-item--active")]: model.value === item.value,
2745
+ [unref(b)("nav-tabs-item--disabled")]: item.disabled
2746
+ }
2747
+ ]),
2748
+ "data-value": item.value,
2749
+ onClick: ($event) => handleItemClick(item)
2750
+ }, [
2751
+ renderSlot(_ctx.$slots, "default", {
2752
+ item,
2753
+ active: model.value === item.value,
2754
+ disabled: !!item.disabled
2755
+ }, () => [
2756
+ createTextVNode(toDisplayString(item.label), 1)
2757
+ ], true)
2758
+ ], 10, _hoisted_1$1);
2759
+ }), 128))
2760
+ ], 2),
2761
+ createElementVNode("button", {
2762
+ ref_key: "rightBtnRef",
2763
+ ref: rightBtnRef,
2764
+ type: "button",
2765
+ class: normalizeClass([unref(b)("nav-tabs__nav-btn"), unref(b)("nav-tabs__nav-btn--next")])
2766
+ }, [
2767
+ createVNode(unref(ElIcon), null, {
2768
+ default: withCtx(() => [
2769
+ createVNode(unref(arrow_right_default))
2770
+ ]),
2771
+ _: 1
2772
+ })
2773
+ ], 2)
2569
2774
  ], 2),
2570
2775
  unref(slots)["right-extra"] ? (openBlock(), createElementBlock("div", {
2571
2776
  key: 1,
@@ -2577,7 +2782,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
2577
2782
  };
2578
2783
  }
2579
2784
  });
2580
- const NavTabs = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["__scopeId", "data-v-5bdac2b9"]]);
2785
+ const NavTabs = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["__scopeId", "data-v-5c4435f1"]]);
2581
2786
  const _sfc_main$6 = /* @__PURE__ */ defineComponent({
2582
2787
  __name: "split-button",
2583
2788
  props: {
@@ -2736,7 +2941,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
2736
2941
  };
2737
2942
  }
2738
2943
  });
2739
- const PageLayout = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["__scopeId", "data-v-a35bb713"]]);
2944
+ const PageLayout = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["__scopeId", "data-v-29bffa31"]]);
2740
2945
  const _sfc_main$4 = /* @__PURE__ */ defineComponent({
2741
2946
  __name: "TableColumn",
2742
2947
  props: {
@@ -3133,7 +3338,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
3133
3338
  };
3134
3339
  }
3135
3340
  });
3136
- const Tag = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-9d73e3e2"]]);
3341
+ const Tag = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-cd3b3c6d"]]);
3137
3342
  function getDefaultExportFromCjs(x) {
3138
3343
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
3139
3344
  }