@fastkit/vui 0.6.19 → 0.6.20

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/vui.cjs.js CHANGED
@@ -8,7 +8,9 @@ var vueColorScheme = require('@fastkit/vue-color-scheme');
8
8
  var vueUtils = require('@fastkit/vue-utils');
9
9
  var vueLoading = require('@fastkit/vue-loading');
10
10
  var iconFont = require('@fastkit/icon-font');
11
+ var helpers = require('@fastkit/helpers');
11
12
  var vueRouter = require('vue-router');
13
+ var vueAppLayout = require('@fastkit/vue-app-layout');
12
14
 
13
15
  const CONTROL_SIZES = ['sm', 'md', 'lg'];
14
16
  const CONTROL_FIELD_VARIANTS = ['outlined', 'filled', 'flat'];
@@ -531,6 +533,296 @@ const VButton = vue.defineComponent({
531
533
 
532
534
  });
533
535
 
536
+ function _isSlot$8(s) {
537
+ return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !vue.isVNode(s);
538
+ }
539
+
540
+ const PAGINATION_ALIGNS = ['left', 'center', 'right'];
541
+ function paginationProps() {
542
+ return vueUtils.createPropsOptions({
543
+ /**
544
+ * Active Pages
545
+ */
546
+ modelValue: {
547
+ type: vueUtils.rawNumberPropType,
548
+ default: 1
549
+ },
550
+
551
+ /**
552
+ * Total number of pages
553
+ */
554
+ length: {
555
+ type: vueUtils.rawNumberPropType,
556
+ default: 0
557
+ },
558
+
559
+ /**
560
+ * Maximum number of links to display.
561
+ */
562
+ totalVisible: vueUtils.rawNumberPropType,
563
+
564
+ /**
565
+ * true when narrowing
566
+ */
567
+ dense: Boolean,
568
+ disabled: Boolean,
569
+ align: {
570
+ type: String,
571
+ default: 'center'
572
+ },
573
+
574
+ /**
575
+ * To synchronize with a query, use the query name
576
+ */
577
+ routeQuery: String,
578
+ beforeChange: Function,
579
+ color: String
580
+ });
581
+ }
582
+ const VPagination = vue.defineComponent({
583
+ name: 'VPagination',
584
+ props: paginationProps(),
585
+ emits: {
586
+ change: page => true
587
+ },
588
+
589
+ setup(props, ctx) {
590
+ const vui = useVui();
591
+ const elRef = vue.ref(null);
592
+ const router = vueRouter.useRouter();
593
+ const route = vueRouter.useRoute();
594
+ const internalValue = vue.ref(1);
595
+ const containerWidth = vue.ref(0);
596
+ const itemSize = vue.ref(0);
597
+ const capacityLength = vue.computed(() => {
598
+ const _itemSize = itemSize.value;
599
+ if (!_itemSize) return 0;
600
+ return Math.floor(containerWidth.value / _itemSize);
601
+ });
602
+ const colorScope = vueColorScheme.useScopeColorClass({
603
+ color: () => props.color || vui.setting('primaryScope')
604
+ });
605
+ const computedLength = vue.computed(() => vueUtils.resolveNumberish(props.length));
606
+ const computedTotalVisible = vue.computed(() => vueUtils.resolveNumberish(props.totalVisible));
607
+ const computedNumbersLength = vue.computed(() => capacityLength.value - 2 - 2);
608
+ const computedPage = vue.computed(() => {
609
+ const {
610
+ routeQuery
611
+ } = props;
612
+
613
+ if (routeQuery) {
614
+ return vueUtils.getRouteQuery(route.query, routeQuery, Number, 1);
615
+ }
616
+
617
+ return internalValue.value;
618
+ });
619
+
620
+ const _range = (from, to) => helpers.range(to - from, from);
621
+
622
+ const computedItems = vue.computed(() => {
623
+ const maxButtons = computedNumbersLength.value;
624
+ const totalVisible = computedTotalVisible.value;
625
+ const length = computedLength.value;
626
+ const pageValue = computedPage.value;
627
+ const maxLength = Math.min(Math.max(0, totalVisible || 0) || length, Math.max(0, maxButtons) || length, length);
628
+
629
+ if (length <= maxLength) {
630
+ return _range(1, length);
631
+ }
632
+
633
+ const even = maxLength % 2 === 0 ? 1 : 0;
634
+ const left = Math.floor(maxLength / 2);
635
+ const right = length - left + 1 + even;
636
+
637
+ if (pageValue > left && pageValue < right) {
638
+ const start = pageValue - left + 2;
639
+ const end = pageValue + left - 2 - even;
640
+ return [1, 'truncate', ..._range(start, end), 'truncate', length];
641
+ } else if (pageValue === left) {
642
+ const end = pageValue + left - 1 - even;
643
+ return [..._range(1, end), 'truncate', length];
644
+ } else if (pageValue === right) {
645
+ const start = pageValue - left + 1;
646
+ return [1, 'truncate', ..._range(start, length)];
647
+ } else {
648
+ return [..._range(1, left), 'truncate', ..._range(right, length)];
649
+ }
650
+ });
651
+ const isActive = vue.computed(() => computedLength.value > 1);
652
+ const isTransitioning = vue.computed(() => {
653
+ const {
654
+ routeQuery
655
+ } = props;
656
+ if (!routeQuery) return false; // @TODO
657
+ // return this.$location.isQueryOnlyTransitioning(routeQuery);
658
+
659
+ return false;
660
+ });
661
+ const isDisabled = vue.computed(() => props.disabled || isTransitioning.value);
662
+ const classes = vue.computed(() => [{
663
+ 'v-pagination--disabled': isDisabled.value,
664
+ 'v-pagination--dense': props.dense,
665
+ [`v-pagination--${props.align}`]: true
666
+ }, colorScope.value.className]);
667
+
668
+ async function setPage(value) {
669
+ if (isDisabled.value) return;
670
+ const {
671
+ beforeChange,
672
+ routeQuery
673
+ } = props;
674
+ const newPage = vueUtils.resolveNumberish(value);
675
+ if (computedPage.value === newPage) return;
676
+
677
+ if (beforeChange) {
678
+ try {
679
+ let result = beforeChange(newPage);
680
+ if (helpers.isPromise(result)) result = await result;
681
+ if (result === false) return;
682
+ } catch (e) {}
683
+ }
684
+
685
+ if (routeQuery) {
686
+ const to = createRoutableLocationByPage(newPage, routeQuery);
687
+ return router.push(to).then(failure => {
688
+ !failure && ctx.emit('change', newPage);
689
+ });
690
+ } else {
691
+ internalValue.value = newPage;
692
+ ctx.emit('update:modelValue', newPage);
693
+ ctx.emit('change', newPage);
694
+ }
695
+ }
696
+
697
+ function createPageInfo(source) {
698
+ const currentPage = computedPage.value;
699
+ const length = computedLength.value;
700
+ let number;
701
+ let page;
702
+ let active;
703
+ let disabled;
704
+
705
+ if (typeof source === 'number') {
706
+ number = true;
707
+ page = source;
708
+ active = currentPage === page;
709
+ disabled = false;
710
+ } else if (source === 'truncate') {
711
+ number = false;
712
+ active = false;
713
+ disabled = false;
714
+ } else {
715
+ number = false;
716
+ const isPrev = source === 'prev';
717
+ const ammount = isPrev ? -1 : 1;
718
+ page = currentPage + ammount;
719
+ active = false;
720
+ disabled = page < 1 || page > length;
721
+ }
722
+
723
+ return {
724
+ number,
725
+ page,
726
+ active,
727
+ disabled
728
+ };
729
+ }
730
+
731
+ function createRoutableLocationByPage(page, routeQuery) {
732
+ return vueUtils.getQueryMergedLocation({
733
+ [routeQuery]: page
734
+ }, route);
735
+ }
736
+
737
+ function genItem(source, index) {
738
+ const {
739
+ number,
740
+ page,
741
+ active,
742
+ disabled
743
+ } = createPageInfo(source);
744
+ const type = number ? 'num' : source; // const staticClass = `pagination__item`;
745
+
746
+ const classes = ['v-pagination__item', {
747
+ [`v-pagination__item--${type}`]: true,
748
+ 'v-pagination__item--active': active,
749
+ 'v-pagination__item--disabled': disabled
750
+ }];
751
+ const children = number ? page : (() => {
752
+ if (type === 'truncate') {
753
+ return vue.createVNode("span", null, [vue.createTextVNode("...")]);
754
+ }
755
+
756
+ const isPrev = type === 'prev';
757
+ const name = isPrev ? 'chevron-left' : 'chevron-right';
758
+ return vue.createVNode(VIcon, {
759
+ "class": "v-pagination__item__icon",
760
+ "name": name
761
+ }, null);
762
+ })();
763
+
764
+ const onClick = ev => {
765
+ ev.preventDefault();
766
+ if (page === undefined || active || disabled) return;
767
+ setPage(page);
768
+ };
769
+
770
+ const key = `${source}-${index}`;
771
+ const {
772
+ routeQuery
773
+ } = props;
774
+
775
+ if (page !== undefined && routeQuery) {
776
+ const to = createRoutableLocationByPage(page, routeQuery);
777
+ return vue.createVNode(vueRouter.RouterLink, {
778
+ "class": classes,
779
+ "to": to,
780
+ "key": key
781
+ }, _isSlot$8(children) ? children : {
782
+ default: () => [children]
783
+ });
784
+ } else {
785
+ return vue.createVNode("button", {
786
+ "class": classes,
787
+ "type": "button",
788
+ "value": page,
789
+ "onClick": onClick,
790
+ "key": key
791
+ }, [children]);
792
+ }
793
+ }
794
+
795
+ vue.watch(() => props.modelValue, modelValue => {
796
+ internalValue.value = vueUtils.resolveNumberish(modelValue);
797
+ }, {
798
+ immediate: true
799
+ });
800
+ return () => {
801
+ if (!isActive.value) return undefined;
802
+ const $items = ['prev', ...computedItems.value, 'next'].map((i, index) => genItem(i, index));
803
+ return vue.withDirectives(vue.createVNode("nav", {
804
+ "class": ['v-pagination', classes.value],
805
+ "ref": elRef
806
+ }, [$items]), [vueUtils.resizeDirectiveArgument(({
807
+ width
808
+ }) => {
809
+ const el = elRef.value;
810
+
811
+ if (el) {
812
+ const style = window.getComputedStyle(el, 'before');
813
+ const width = style.getPropertyValue('width');
814
+ const margin = style.getPropertyValue('margin');
815
+ const size = parseFloat(width) + parseFloat(margin) * 0.5;
816
+ itemSize.value = size;
817
+ }
818
+
819
+ containerWidth.value = width;
820
+ })]);
821
+ };
822
+ }
823
+
824
+ });
825
+
534
826
  function createListTileProps() {
535
827
  const icon = rawIconProp();
536
828
  return { ...vueUtils.navigationableProps,
@@ -651,6 +943,51 @@ const VDrawerLayout = vue.defineComponent({
651
943
 
652
944
  });
653
945
 
946
+ function _isSlot$7(s) {
947
+ return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !vue.isVNode(s);
948
+ }
949
+
950
+ const VHero = vue.defineComponent({
951
+ name: 'VHero',
952
+ props: {
953
+ color: {
954
+ type: String,
955
+ default: 'primary'
956
+ },
957
+ tag: {
958
+ type: String,
959
+ default: 'header'
960
+ },
961
+ hTag: {
962
+ type: String,
963
+ default: 'h1'
964
+ }
965
+ },
966
+
967
+ setup(props, ctx) {
968
+ return () => {
969
+ let _slot;
970
+
971
+ const TagName = props.tag;
972
+ const HTagName = props.hTag;
973
+ return vue.createVNode(vueAppLayout.VAppContainer, {
974
+ "pulled": true
975
+ }, {
976
+ default: () => [vue.createVNode(TagName, {
977
+ "class": ['v-hero', vueColorScheme.toScopeColorClass(props.color)]
978
+ }, {
979
+ default: () => [vue.createVNode(HTagName, {
980
+ "class": "v-hero__title"
981
+ }, _isSlot$7(_slot = vueUtils.renderSlotOrEmpty(ctx.slots, 'default')) ? _slot : {
982
+ default: () => [_slot]
983
+ })]
984
+ })]
985
+ });
986
+ };
987
+ }
988
+
989
+ });
990
+
654
991
  function _isSlot$6(s) {
655
992
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !vue.isVNode(s);
656
993
  }
@@ -1897,6 +2234,7 @@ exports.VSnackbar = vueKit.VSnackbar;
1897
2234
  exports.ICON_NAMES = iconFont.ICON_NAMES;
1898
2235
  exports.CONTROL_FIELD_VARIANTS = CONTROL_FIELD_VARIANTS;
1899
2236
  exports.CONTROL_SIZES = CONTROL_SIZES;
2237
+ exports.PAGINATION_ALIGNS = PAGINATION_ALIGNS;
1900
2238
  exports.VApp = VApp;
1901
2239
  exports.VButton = VButton;
1902
2240
  exports.VCard = VCard;
@@ -1906,12 +2244,14 @@ exports.VCheckbox = VCheckbox;
1906
2244
  exports.VCheckboxGroup = VCheckboxGroup;
1907
2245
  exports.VDrawerLayout = VDrawerLayout;
1908
2246
  exports.VForm = VForm;
2247
+ exports.VHero = VHero;
1909
2248
  exports.VIcon = VIcon;
1910
2249
  exports.VListTile = VListTile;
1911
2250
  exports.VNavigation = VNavigation;
1912
2251
  exports.VNavigationItem = VNavigationItem;
1913
2252
  exports.VOption = VOption;
1914
2253
  exports.VOptionGroup = VOptionGroup;
2254
+ exports.VPagination = VPagination;
1915
2255
  exports.VPaper = VPaper;
1916
2256
  exports.VRadio = VRadio;
1917
2257
  exports.VRadioGroup = VRadioGroup;
@@ -1953,6 +2293,7 @@ exports.defineFormSelectorComponent = defineFormSelectorComponent;
1953
2293
  exports.iconProps = iconProps;
1954
2294
  exports.installVuiPlugin = installVuiPlugin;
1955
2295
  exports.listTileEmits = listTileEmits;
2296
+ exports.paginationProps = paginationProps;
1956
2297
  exports.rawIconProp = rawIconProp;
1957
2298
  exports.renderNavigationItemInput = renderNavigationItemInput;
1958
2299
  exports.resolveNavigationItemInput = resolveNavigationItemInput;