gi-component 0.0.45 → 0.0.47

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,37 +300,187 @@ 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
+ }
313
+ const WHEEL_SCROLL_LERP = 0.4;
314
+ const WHEEL_LINE_HEIGHT = 16;
315
+ function getWheelPixelDelta(event, scrollEl) {
316
+ let delta = Math.abs(event.deltaX) > Math.abs(event.deltaY) ? event.deltaX : event.deltaY;
317
+ if (event.deltaMode === WheelEvent.DOM_DELTA_LINE) {
318
+ delta *= WHEEL_LINE_HEIGHT;
319
+ } else if (event.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
320
+ delta *= scrollEl.clientWidth;
321
+ }
322
+ return delta;
323
+ }
324
+ function clampScrollLeft(scrollEl, left) {
325
+ return Math.max(0, Math.min(left, getMaxScrollLeft(scrollEl)));
326
+ }
303
327
  function scrollItemToCenter(scrollEl, activeEl, behavior = "smooth") {
304
- const maxScroll = scrollEl.scrollWidth - scrollEl.clientWidth;
328
+ const maxScroll = getMaxScrollLeft(scrollEl);
305
329
  if (maxScroll <= 0) {
306
330
  return;
307
331
  }
308
- const target = activeEl.offsetLeft - (scrollEl.clientWidth - activeEl.offsetWidth) / 2;
332
+ const scrollRect = scrollEl.getBoundingClientRect();
333
+ const activeRect = activeEl.getBoundingClientRect();
334
+ const activeLeftInContent = activeRect.left - scrollRect.left + scrollEl.scrollLeft;
335
+ const target = activeLeftInContent - (scrollEl.clientWidth - activeRect.width) / 2;
309
336
  scrollEl.scrollTo({
310
337
  left: Math.max(0, Math.min(target, maxScroll)),
311
338
  behavior
312
339
  });
313
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
+ }
314
360
  function useNavTabs(options) {
315
361
  const {
316
362
  tabEl,
317
363
  tabScrollEl,
318
364
  tabItemClassName,
319
365
  activeValue,
320
- activeClassSuffix = "--active",
321
- wheelSpeed = 1
366
+ wheelSpeed = 1,
367
+ tabLeftScrollBtnEl,
368
+ tabRightScrollBtnEl,
369
+ scrollBtnStepRatio = 0.6,
370
+ scrollBtnMinStep = 120,
371
+ navBtnDisabledClassName
322
372
  } = options;
323
- const activeClassName = `${tabItemClassName}${activeClassSuffix}`;
373
+ const activeClassName = `${tabItemClassName}--active`;
324
374
  const itemSelector = normalizeSelector(tabItemClassName);
375
+ const showNavBtn = ref(false);
376
+ const canScrollLeft = ref(false);
377
+ const canScrollRight = ref(false);
325
378
  let rootEl = null;
326
379
  let scrollEl = null;
380
+ let leftBtnEl = null;
381
+ let rightBtnEl = null;
327
382
  let resizeObserver = null;
383
+ let wheelRafId = null;
384
+ let wheelTargetScrollLeft = 0;
385
+ let navBtnRafId = null;
386
+ let onPrevClick = null;
387
+ let onNextClick = null;
388
+ const cancelWheelAnimation = () => {
389
+ if (wheelRafId !== null) {
390
+ cancelAnimationFrame(wheelRafId);
391
+ wheelRafId = null;
392
+ }
393
+ };
394
+ const cancelWheelScroll = () => {
395
+ if (scrollEl) {
396
+ wheelTargetScrollLeft = scrollEl.scrollLeft;
397
+ }
398
+ cancelWheelAnimation();
399
+ };
400
+ const runWheelAnimation = () => {
401
+ if (!scrollEl) {
402
+ cancelWheelAnimation();
403
+ return;
404
+ }
405
+ const current = scrollEl.scrollLeft;
406
+ const diff = wheelTargetScrollLeft - current;
407
+ if (Math.abs(diff) < 0.5) {
408
+ scrollEl.scrollLeft = wheelTargetScrollLeft;
409
+ cancelWheelAnimation();
410
+ scheduleUpdateNavBtnState();
411
+ return;
412
+ }
413
+ scrollEl.scrollLeft = current + diff * WHEEL_SCROLL_LERP;
414
+ wheelRafId = requestAnimationFrame(runWheelAnimation);
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
+ };
328
475
  const resolveElements = () => {
329
476
  var _a, _b;
330
477
  const instanceRoot = (_b = (_a = getCurrentInstance()) == null ? void 0 : _a.proxy) == null ? void 0 : _b.$el;
331
478
  const fallbackRoot = instanceRoot instanceof HTMLElement ? instanceRoot : document;
332
479
  rootEl = resolveElement(toValue(tabEl), fallbackRoot);
333
- 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);
334
484
  return Boolean(rootEl && scrollEl);
335
485
  };
336
486
  const findActiveItem = () => {
@@ -353,33 +503,85 @@ function useNavTabs(options) {
353
503
  if (!scrollEl) {
354
504
  return;
355
505
  }
506
+ cancelWheelScroll();
356
507
  const activeItem = findActiveItem();
357
508
  if (activeItem) {
358
509
  scrollItemToCenter(scrollEl, activeItem, behavior);
359
510
  }
511
+ scheduleUpdateNavBtnState();
360
512
  };
361
513
  const handleWheel = (event) => {
362
514
  if (!scrollEl) {
363
515
  return;
364
516
  }
365
- const delta = Math.abs(event.deltaX) > Math.abs(event.deltaY) ? event.deltaX : event.deltaY;
517
+ const delta = getWheelPixelDelta(event, scrollEl);
366
518
  if (delta === 0) {
367
519
  return;
368
520
  }
369
521
  event.preventDefault();
370
- scrollEl.scrollLeft += delta * wheelSpeed;
522
+ if (wheelRafId === null) {
523
+ wheelTargetScrollLeft = scrollEl.scrollLeft;
524
+ }
525
+ wheelTargetScrollLeft = clampScrollLeft(
526
+ scrollEl,
527
+ wheelTargetScrollLeft + delta * wheelSpeed
528
+ );
529
+ if (wheelRafId === null) {
530
+ wheelRafId = requestAnimationFrame(runWheelAnimation);
531
+ }
532
+ scheduleUpdateNavBtnState();
533
+ };
534
+ const handleScroll = () => {
535
+ scheduleUpdateNavBtnState();
371
536
  };
372
537
  const bindWheel = () => {
373
538
  scrollEl == null ? void 0 : scrollEl.addEventListener("wheel", handleWheel, { passive: false });
539
+ scrollEl == null ? void 0 : scrollEl.addEventListener("scroll", handleScroll, { passive: true });
374
540
  };
375
541
  const unbindWheel = () => {
376
542
  scrollEl == null ? void 0 : scrollEl.removeEventListener("wheel", handleWheel);
543
+ scrollEl == null ? void 0 : scrollEl.removeEventListener("scroll", handleScroll);
544
+ cancelWheelAnimation();
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;
377
578
  };
378
579
  const bindResizeObserver = () => {
379
580
  if (!scrollEl || typeof ResizeObserver === "undefined") {
380
581
  return;
381
582
  }
382
583
  resizeObserver = new ResizeObserver(() => {
584
+ scheduleUpdateNavBtnState();
383
585
  scrollToActive("auto");
384
586
  });
385
587
  resizeObserver.observe(scrollEl);
@@ -388,23 +590,40 @@ function useNavTabs(options) {
388
590
  resizeObserver == null ? void 0 : resizeObserver.disconnect();
389
591
  resizeObserver = null;
390
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
+ };
391
604
  const setup = async () => {
392
605
  await nextTick();
393
606
  if (!resolveElements()) {
394
607
  return;
395
608
  }
396
609
  bindWheel();
610
+ bindNavButtons();
397
611
  bindResizeObserver();
612
+ updateNavBtnState();
398
613
  scrollToActive("auto");
399
614
  };
400
615
  onMounted(() => {
401
616
  setup();
402
617
  });
403
618
  watch(
404
- () => [toValue(tabEl), toValue(tabScrollEl)],
619
+ () => [
620
+ toValue(tabEl),
621
+ toValue(tabScrollEl),
622
+ toValue(tabLeftScrollBtnEl),
623
+ toValue(tabRightScrollBtnEl)
624
+ ],
405
625
  () => {
406
- unbindWheel();
407
- unbindResizeObserver();
626
+ teardown();
408
627
  setup();
409
628
  }
410
629
  );
@@ -414,14 +633,16 @@ function useNavTabs(options) {
414
633
  });
415
634
  }
416
635
  onUnmounted(() => {
417
- unbindWheel();
418
- unbindResizeObserver();
419
- rootEl = null;
420
- scrollEl = null;
636
+ teardown();
421
637
  });
422
638
  return {
423
639
  scrollToActive,
424
- getScrollEl: () => scrollEl
640
+ getScrollEl: () => scrollEl,
641
+ cancelWheelScroll,
642
+ scrollByStep,
643
+ showNavBtn,
644
+ canScrollLeft,
645
+ canScrollRight
425
646
  };
426
647
  }
427
648
  const _sfc_main$l = /* @__PURE__ */ defineComponent({
@@ -2446,7 +2667,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
2446
2667
  props: /* @__PURE__ */ mergeModels({
2447
2668
  data: { default: () => [] },
2448
2669
  wheelSpeed: { default: 1 },
2449
- activeClassSuffix: { default: "--active" }
2670
+ custom: { type: Boolean, default: false }
2450
2671
  }, {
2451
2672
  "modelValue": {},
2452
2673
  "modelModifiers": {}
@@ -2460,14 +2681,18 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
2460
2681
  const { b } = useBemClass();
2461
2682
  const rootRef = ref(null);
2462
2683
  const scrollRef = ref(null);
2684
+ const leftBtnRef = ref(null);
2685
+ const rightBtnRef = ref(null);
2463
2686
  const tabItemClassName = b("nav-tabs-item");
2464
2687
  useNavTabs({
2465
2688
  tabEl: rootRef,
2466
2689
  tabScrollEl: scrollRef,
2467
2690
  tabItemClassName,
2468
2691
  activeValue: model,
2469
- activeClassSuffix: props.activeClassSuffix,
2470
- wheelSpeed: props.wheelSpeed
2692
+ wheelSpeed: props.wheelSpeed,
2693
+ tabLeftScrollBtnEl: leftBtnRef,
2694
+ tabRightScrollBtnEl: rightBtnRef,
2695
+ navBtnDisabledClassName: b("nav-tabs__nav-btn--disabled")
2471
2696
  });
2472
2697
  function handleItemClick(item) {
2473
2698
  if (item.disabled) {
@@ -2480,7 +2705,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
2480
2705
  return openBlock(), createElementBlock("div", {
2481
2706
  ref_key: "rootRef",
2482
2707
  ref: rootRef,
2483
- class: normalizeClass(unref(b)("nav-tabs"))
2708
+ class: normalizeClass([unref(b)("nav-tabs"), { [unref(b)("nav-tabs--custom")]: props.custom }])
2484
2709
  }, [
2485
2710
  unref(slots)["left-extra"] ? (openBlock(), createElementBlock("div", {
2486
2711
  key: 0,
@@ -2489,28 +2714,62 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
2489
2714
  renderSlot(_ctx.$slots, "left-extra", {}, void 0, true)
2490
2715
  ], 2)) : createCommentVNode("", true),
2491
2716
  createElementVNode("div", {
2492
- ref_key: "scrollRef",
2493
- ref: scrollRef,
2494
- class: normalizeClass(unref(b)("nav-tabs__scroll"))
2717
+ class: normalizeClass(unref(b)("nav-tabs__scroll-wrap"))
2495
2718
  }, [
2496
- renderSlot(_ctx.$slots, "default", {
2497
- data: props.data
2498
- }, () => [
2719
+ createElementVNode("button", {
2720
+ ref_key: "leftBtnRef",
2721
+ ref: leftBtnRef,
2722
+ type: "button",
2723
+ class: normalizeClass([unref(b)("nav-tabs__nav-btn"), unref(b)("nav-tabs__nav-btn--prev")])
2724
+ }, [
2725
+ createVNode(unref(ElIcon), null, {
2726
+ default: withCtx(() => [
2727
+ createVNode(unref(arrow_left_default))
2728
+ ]),
2729
+ _: 1
2730
+ })
2731
+ ], 2),
2732
+ createElementVNode("div", {
2733
+ ref_key: "scrollRef",
2734
+ ref: scrollRef,
2735
+ class: normalizeClass(unref(b)("nav-tabs__scroll"))
2736
+ }, [
2499
2737
  (openBlock(true), createElementBlock(Fragment, null, renderList(props.data, (item) => {
2500
2738
  return openBlock(), createElementBlock("div", {
2501
2739
  key: item.value,
2502
2740
  class: normalizeClass([
2503
2741
  unref(b)("nav-tabs-item"),
2504
- {
2742
+ props.custom ? unref(b)("nav-tabs-item--custom") : {
2505
2743
  [unref(b)("nav-tabs-item--active")]: model.value === item.value,
2506
2744
  [unref(b)("nav-tabs-item--disabled")]: item.disabled
2507
2745
  }
2508
2746
  ]),
2509
2747
  "data-value": item.value,
2510
2748
  onClick: ($event) => handleItemClick(item)
2511
- }, toDisplayString(item.label), 11, _hoisted_1$1);
2749
+ }, [
2750
+ renderSlot(_ctx.$slots, "default", {
2751
+ item,
2752
+ active: model.value === item.value,
2753
+ disabled: !!item.disabled
2754
+ }, () => [
2755
+ createTextVNode(toDisplayString(item.label), 1)
2756
+ ], true)
2757
+ ], 10, _hoisted_1$1);
2512
2758
  }), 128))
2513
- ], true)
2759
+ ], 2),
2760
+ createElementVNode("button", {
2761
+ ref_key: "rightBtnRef",
2762
+ ref: rightBtnRef,
2763
+ type: "button",
2764
+ class: normalizeClass([unref(b)("nav-tabs__nav-btn"), unref(b)("nav-tabs__nav-btn--next")])
2765
+ }, [
2766
+ createVNode(unref(ElIcon), null, {
2767
+ default: withCtx(() => [
2768
+ createVNode(unref(arrow_right_default))
2769
+ ]),
2770
+ _: 1
2771
+ })
2772
+ ], 2)
2514
2773
  ], 2),
2515
2774
  unref(slots)["right-extra"] ? (openBlock(), createElementBlock("div", {
2516
2775
  key: 1,
@@ -2522,7 +2781,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
2522
2781
  };
2523
2782
  }
2524
2783
  });
2525
- const NavTabs = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["__scopeId", "data-v-198d4dd6"]]);
2784
+ const NavTabs = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["__scopeId", "data-v-5c4435f1"]]);
2526
2785
  const _sfc_main$6 = /* @__PURE__ */ defineComponent({
2527
2786
  __name: "split-button",
2528
2787
  props: {
@@ -2681,7 +2940,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
2681
2940
  };
2682
2941
  }
2683
2942
  });
2684
- const PageLayout = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["__scopeId", "data-v-a35bb713"]]);
2943
+ const PageLayout = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["__scopeId", "data-v-29bffa31"]]);
2685
2944
  const _sfc_main$4 = /* @__PURE__ */ defineComponent({
2686
2945
  __name: "TableColumn",
2687
2946
  props: {
@@ -3078,7 +3337,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
3078
3337
  };
3079
3338
  }
3080
3339
  });
3081
- const Tag = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-9d73e3e2"]]);
3340
+ const Tag = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-cd3b3c6d"]]);
3082
3341
  function getDefaultExportFromCjs(x) {
3083
3342
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
3084
3343
  }