xdesign-vue-next
Version:
XDesign Component for vue-next
525 lines (506 loc) • 19.6 kB
JavaScript
/**
* xdesign v1.0.6
* (c) 2023 xdesign
* @license MIT
*/
import { openBlock, createElementBlock, createElementVNode, defineComponent, toRefs, ref, computed, watch, createVNode, mergeProps } from 'vue';
import { _ as __unplugin_components_3 } from '../_chunks/dep-17236cae.js';
import { _ as __unplugin_components_2$1 } from '../_chunks/dep-9beabfae.js';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import isNaN from 'lodash/isNaN';
import { usePrefixClass } from '../hooks/useConfig.js';
import { InputNumber } from '../input-number/index.js';
import { Select } from '../select/index.js';
import { InputAdornment } from '../input-adornment/index.js';
import props from './props.js';
import usePaginationClasses from './usePaginationClasses.js';
import useMoreAction from './useMoreAction.js';
import useVModel from '../hooks/useVModel.js';
import useDefaultValue from '../hooks/useDefaultValue.js';
import { useTNodeJSX } from '../hooks/tnode.js';
import isObject from 'lodash/isObject';
import { useConfig } from '../config-provider/useConfig.js';
import '../input-number/input-number.js';
import '../_chunks/dep-36abe4f1.js';
import '../_chunks/dep-05bc6eb4.js';
import '../_chunks/dep-6c2da407.js';
import '@babel/runtime/helpers/defineProperty';
import '../button/index.js';
import '../button/button.js';
import '@babel/runtime/helpers/toConsumableArray';
import '../loading/index.js';
import '../loading/directive.js';
import '../loading/plugin.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/set-style.js';
import '../_common/js/utils/helper.js';
import 'lodash/isString';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import 'lodash/isArray';
import '../utils/dom.js';
import '../_chunks/dep-3a1cce9f.js';
import 'lodash/isFunction';
import '../utils/easing.js';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../loading/props.js';
import '../hooks/useTeleport.js';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/en_US.js';
import '../utils/withInstall.js';
import '../button/props.js';
import '../hooks/useRipple.js';
import '../hooks/useKeepAnimation.js';
import '../utils/set-style.js';
import '../hooks/useDisabled.js';
import 'lodash/isBoolean';
import '../input/index.js';
import '../input/input.js';
import '../_chunks/dep-fb0628ce.js';
import '../_chunks/dep-eade0dcf.js';
import '../input/props.js';
import '../form/hooks.js';
import '../input/useInput.js';
import '../form/const.js';
import '../input/useLengthLimit.js';
import '../_common/js/log/log.js';
import '../input/useInputEventHandler.js';
import '../input/useInputWidth.js';
import '../input/input-group.js';
import '../input/input-group-props.js';
import '../input-number/props.js';
import '../input-number/useInputNumber.js';
import '../hooks/useCommonClassName.js';
import '../_common/js/input-number/number.js';
import '../_common/js/input-number/large-number.js';
import '../select/select.js';
import 'lodash/pick';
import 'lodash/debounce';
import 'lodash/get';
import 'lodash/intersection';
import '../common-components/fake-arrow.js';
import '../select-input/index.js';
import '../select-input/select-input.js';
import '../popup/index.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../popup/container.js';
import '../popup/props.js';
import '../hooks/useResizeObserver.js';
import '../select-input/props.js';
import '../select-input/useSingle.js';
import '../select-input/useMultiple.js';
import '../tag-input/index.js';
import '../tag-input/tag-input.js';
import '../tag-input/props.js';
import '../tag-input/hooks/useTagScroll.js';
import '../tag-input/useTagList.js';
import '../tag/index.js';
import '../tag/tag.js';
import '../_chunks/dep-ae5efda0.js';
import '../tag/props.js';
import '../tag/check-tag.js';
import '../tag/check-tag-props.js';
import '../tag-input/hooks/useHover.js';
import '../tag-input/hooks/useDragSorter.js';
import '../select-input/useOverlayInnerStyle.js';
import '@babel/runtime/helpers/typeof';
import '../select/select-panel.js';
import 'lodash/omit';
import '../select/option.js';
import '../select/option-props.js';
import '../checkbox/index.js';
import '../checkbox/checkbox.js';
import '../checkbox/props.js';
import '../checkbox/constants.js';
import '../checkbox/hooks/useCheckboxLazyLoad.js';
import '../_common/js/utils/observe.js';
import '../checkbox/hooks/useKeyboard.js';
import '../checkbox/group.js';
import '../checkbox/checkbox-group-props.js';
import '../hooks/slot.js';
import '../select/helper.js';
import '../select/optionGroup.js';
import '../select/option-group-props.js';
import '../select/props.js';
import '../select/hooks/usePanelVirtualScroll.js';
import '../hooks/useVirtualScroll.js';
import '../select/hooks/useSelectOptions.js';
import '../input-adornment/input-adornment.js';
import '../input-adornment/props.js';
const _hoisted_1$4 = {
class: "x-icon",
viewBox: "0 0 24 24",
width: "1.1em",
height: "1.1em"
};
const _hoisted_2$4 = /*#__PURE__*/createElementVNode("path", {
fill: "currentColor",
d: "M4.5 10.5c-.825 0-1.5.675-1.5 1.5s.675 1.5 1.5 1.5S6 12.825 6 12s-.675-1.5-1.5-1.5Zm15 0c-.825 0-1.5.675-1.5 1.5s.675 1.5 1.5 1.5S21 12.825 21 12s-.675-1.5-1.5-1.5Zm-7.5 0c-.825 0-1.5.675-1.5 1.5s.675 1.5 1.5 1.5s1.5-.675 1.5-1.5s-.675-1.5-1.5-1.5Z"
}, null, -1 /* HOISTED */);
const _hoisted_3$4 = [
_hoisted_2$4
];
function render$4(_ctx, _cache) {
return (openBlock(), createElementBlock("svg", _hoisted_1$4, _hoisted_3$4))
}
var __unplugin_components_5 = { name: 'ri-more-line', render: render$4 };
/* vite-plugin-components disabled */
const _hoisted_1$3 = {
class: "x-icon",
viewBox: "0 0 24 24",
width: "1.1em",
height: "1.1em"
};
const _hoisted_2$3 = /*#__PURE__*/createElementVNode("path", {
fill: "currentColor",
d: "m10.086 12l-4.793 4.793l1.414 1.414L12.914 12L6.707 5.793L5.293 7.207L10.086 12ZM17 6v12h-2V6h2Z"
}, null, -1 /* HOISTED */);
const _hoisted_3$3 = [
_hoisted_2$3
];
function render$3(_ctx, _cache) {
return (openBlock(), createElementBlock("svg", _hoisted_1$3, _hoisted_3$3))
}
var __unplugin_components_7 = { name: 'ri-skip-right-line', render: render$3 };
/* vite-plugin-components disabled */
const _hoisted_1$2 = {
class: "x-icon",
viewBox: "0 0 24 24",
width: "1.1em",
height: "1.1em"
};
const _hoisted_2$2 = /*#__PURE__*/createElementVNode("path", {
fill: "currentColor",
d: "m19.164 12l-6.207-6.207l-1.414 1.414L16.336 12l-4.793 4.793l1.414 1.414L19.164 12Zm-5.65 0L7.307 5.793L5.893 7.207L10.686 12l-4.793 4.793l1.414 1.414L13.514 12Z"
}, null, -1 /* HOISTED */);
const _hoisted_3$2 = [
_hoisted_2$2
];
function render$2(_ctx, _cache) {
return (openBlock(), createElementBlock("svg", _hoisted_1$2, _hoisted_3$2))
}
var __unplugin_components_4 = { name: 'ri-arrow-right-double-line', render: render$2 };
/* vite-plugin-components disabled */
const _hoisted_1$1 = {
class: "x-icon",
viewBox: "0 0 24 24",
width: "1.1em",
height: "1.1em"
};
const _hoisted_2$1 = /*#__PURE__*/createElementVNode("path", {
fill: "currentColor",
d: "m4.836 12l6.207 6.207l1.414-1.414L7.664 12l4.793-4.793l-1.414-1.414L4.836 12Zm5.65 0l6.207 6.207l1.414-1.414L13.314 12l4.793-4.793l-1.414-1.414L10.486 12Z"
}, null, -1 /* HOISTED */);
const _hoisted_3$1 = [
_hoisted_2$1
];
function render$1(_ctx, _cache) {
return (openBlock(), createElementBlock("svg", _hoisted_1$1, _hoisted_3$1))
}
var __unplugin_components_2 = { name: 'ri-arrow-left-double-line', render: render$1 };
/* vite-plugin-components disabled */
const _hoisted_1 = {
class: "x-icon",
viewBox: "0 0 24 24",
width: "1.1em",
height: "1.1em"
};
const _hoisted_2 = /*#__PURE__*/createElementVNode("path", {
fill: "currentColor",
d: "m13.914 12l4.793-4.793l-1.414-1.414L11.086 12l6.207 6.207l1.414-1.414L13.914 12ZM7 18V6h2v12H7Z"
}, null, -1 /* HOISTED */);
const _hoisted_3 = [
_hoisted_2
];
function render(_ctx, _cache) {
return (openBlock(), createElementBlock("svg", _hoisted_1, _hoisted_3))
}
var __unplugin_components_0 = { name: 'ri-skip-left-line', render };
/* vite-plugin-components disabled */
var _excluded = ["pageCount"];
var min = 1;
var _Pagination = defineComponent({
name: "XPagination",
props: props,
setup: function setup(props2) {
var _toRefs = toRefs(props2),
modelValue = _toRefs.modelValue,
pageSize = _toRefs.pageSize,
current = _toRefs.current;
var renderTNodeJSX = useTNodeJSX();
var _useVModel = useVModel(current, modelValue, props2.defaultCurrent, props2.onCurrentChange, "current"),
_useVModel2 = _slicedToArray(_useVModel, 2),
innerCurrent = _useVModel2[0],
setInnerCurrent = _useVModel2[1];
var _useDefaultValue = useDefaultValue(pageSize, props2.defaultPageSize, props2.onPageSizeChange, "pageSize"),
_useDefaultValue2 = _slicedToArray(_useDefaultValue, 2),
innerPageSize = _useDefaultValue2[0],
setInnerPageSize = _useDefaultValue2[1];
var _useConfig = useConfig("pagination"),
t = _useConfig.t,
globalConfig = _useConfig.globalConfig;
var COMPONENT_NAME = usePrefixClass("pagination");
var _usePaginationClasses = usePaginationClasses(props2, innerCurrent, innerPageSize, COMPONENT_NAME),
pageCount = _usePaginationClasses.pageCount,
CLASS_MAP = _objectWithoutProperties(_usePaginationClasses, _excluded);
var _useMoreAction = useMoreAction(props2, pageCount, innerCurrent),
prevMore = _useMoreAction.prevMore,
isPrevMoreShow = _useMoreAction.isPrevMoreShow,
curPageLeftCount = _useMoreAction.curPageLeftCount,
nextMore = _useMoreAction.nextMore,
isNextMoreShow = _useMoreAction.isNextMoreShow,
curPageRightCount = _useMoreAction.curPageRightCount;
var jumpIndex = ref(innerCurrent.value);
var isFolded = computed(function () {
return pageCount.value > props2.maxPageBtn;
});
var sizeOptions = computed(function () {
var pageSizeOptions = props2.pageSizeOptions;
var options = pageSizeOptions.map(function (option) {
return isObject(option) ? option : {
label: t(globalConfig.value.itemsPerPage, {
size: option
}),
value: Number(option)
};
});
return options.sort(function (a, b) {
return a.value - b.value;
});
});
var isMidEllipsis = computed(function () {
return props2.pageEllipsisMode === "mid";
});
var pages = computed(function () {
var array = [];
var start;
var end;
if (isFolded.value) {
if (isPrevMoreShow.value && isNextMoreShow.value) {
start = innerCurrent.value - curPageLeftCount.value;
end = innerCurrent.value + curPageRightCount.value;
} else {
var foldedStart = isMidEllipsis.value ? 2 : 1;
var foldedEnd = isMidEllipsis.value ? pageCount.value - 1 : pageCount.value;
start = isPrevMoreShow.value ? pageCount.value - props2.foldedMaxPageBtn + 1 : foldedStart;
end = isPrevMoreShow.value ? foldedEnd : props2.foldedMaxPageBtn;
}
} else {
start = 1;
end = pageCount.value;
}
for (var i = start; i <= end; i++) {
array.push(i);
}
return array;
});
watch(function () {
return pageCount.value;
}, function () {
if (innerCurrent.value > pageCount.value) innerCurrent.value = 1;
});
watch(function () {
return innerCurrent.value;
}, function (val) {
return jumpIndex.value = val;
});
var toPage = function toPage(pageIndex, isTriggerChange) {
if (props2.disabled) {
return;
}
var current2 = pageIndex;
if (pageIndex < min) {
current2 = min;
} else if (pageIndex > pageCount.value) {
current2 = pageCount.value;
}
if (innerCurrent.value !== current2) {
var prev = innerCurrent.value;
var pageInfo = {
current: current2,
previous: prev,
pageSize: innerPageSize.value
};
setInnerCurrent(current2, pageInfo);
if (isTriggerChange !== false) {
var _props2$onChange;
(_props2$onChange = props2.onChange) === null || _props2$onChange === void 0 ? void 0 : _props2$onChange.call(props2, pageInfo);
}
}
};
var handlePageChange = function handlePageChange(type) {
var pageChangeMap = {
prevPage: function prevPage() {
return toPage(innerCurrent.value - 1);
},
nextPage: function nextPage() {
return toPage(innerCurrent.value + 1);
},
prevMorePage: function prevMorePage() {
return toPage(innerCurrent.value - props2.foldedMaxPageBtn);
},
nextMorePage: function nextMorePage() {
return toPage(innerCurrent.value + props2.foldedMaxPageBtn);
}
};
pageChangeMap[type]();
};
var onSelectorChange = function onSelectorChange(e) {
var _props2$onChange2;
if (props2.disabled) {
return;
}
var pageSize2 = parseInt(e, 10);
var pageCount2 = 1;
if (pageSize2 > 0) {
pageCount2 = Math.max(Math.ceil(props2.total / pageSize2), 1);
}
var isIndexChange = false;
if (innerCurrent.value > pageCount2) {
isIndexChange = true;
}
var pageInfo = {
current: isIndexChange ? pageCount2 : innerCurrent.value,
previous: innerCurrent.value,
pageSize: pageSize2
};
(_props2$onChange2 = props2.onChange) === null || _props2$onChange2 === void 0 ? void 0 : _props2$onChange2.call(props2, pageInfo);
setInnerPageSize(pageSize2, pageInfo);
if (isIndexChange) {
toPage(pageCount2, false);
}
};
var onJumperChange = function onJumperChange(val) {
var currentIndex = Math.trunc(+val);
if (isNaN(currentIndex)) return;
jumpIndex.value = currentIndex;
toPage(currentIndex);
};
return function () {
var total = props2.total,
pageSizeOptions = props2.pageSizeOptions,
size = props2.size,
disabled = props2.disabled,
showPageSize = props2.showPageSize;
if (pageCount.value < 1) return null;
var Jumper = createVNode("div", {
"class": CLASS_MAP.jumperClass.value
}, [t(globalConfig.value.jumpTo), createVNode(InputAdornment, {
"append": "/ ".concat(pageCount.value, " ").concat(t(globalConfig.value.page))
}, {
"default": function _default() {
return [createVNode(InputNumber, {
"class": CLASS_MAP.jumperInputClass.value,
"modelValue": jumpIndex.value,
"onUpdate:modelValue": function onUpdateModelValue($event) {
return jumpIndex.value = $event;
},
"onBlur": onJumperChange,
"onEnter": onJumperChange,
"max": pageCount.value,
"min": min,
"size": size,
"disabled": disabled,
"theme": "normal",
"placeholder": ""
}, null)];
}
})]);
return createVNode("div", {
"class": CLASS_MAP.paginationClass.value
}, [renderTNodeJSX("totalContent", createVNode("div", {
"class": CLASS_MAP.totalClass.value
}, [t(globalConfig.value.total, {
total: total
})])), showPageSize && pageSizeOptions.length > 0 && createVNode(Select, mergeProps({
"size": size,
"value": innerPageSize,
"disabled": disabled,
"class": CLASS_MAP.sizerClass.value,
"autoWidth": true,
"onChange": onSelectorChange,
"options": sizeOptions.value
}, props2.selectProps), null), props2.showFirstAndLastPageBtn ? createVNode("div", {
"class": CLASS_MAP.preBtnClass.value,
"onClick": function onClick() {
return toPage(1);
},
"disabled": props2.disabled || props2.current === min
}, [createVNode(__unplugin_components_0, null, null)]) : null, props2.showPreviousAndNextBtn ? createVNode("div", {
"class": CLASS_MAP.preBtnClass.value,
"onClick": function onClick() {
return handlePageChange("prevPage");
},
"disabled": disabled || innerCurrent.value === min
}, [createVNode(__unplugin_components_2$1, null, null)]) : null, props2.showPageNumber && props2.theme === "default" ? createVNode("ul", {
"class": CLASS_MAP.btnWrapClass.value
}, [isFolded.value && isMidEllipsis.value && createVNode("li", {
"class": CLASS_MAP.getButtonClass(1),
"onClick": function onClick() {
return toPage(min);
}
}, [min]), isFolded.value && isPrevMoreShow.value && isMidEllipsis.value ? createVNode("li", {
"class": CLASS_MAP.btnMoreClass.value,
"onClick": function onClick() {
return handlePageChange("prevMorePage");
},
"onMouseOver": function onMouseOver() {
return prevMore.value = true;
},
"onMouseOut": function onMouseOut() {
return prevMore.value = false;
}
}, [prevMore.value ? createVNode(__unplugin_components_2, null, null) : createVNode(__unplugin_components_5, null, null)]) : null, pages.value.map(function (i) {
return createVNode("li", {
"class": CLASS_MAP.getButtonClass(i),
"key": i,
"onClick": function onClick() {
return toPage(i);
}
}, [i]);
}), isFolded.value && isNextMoreShow.value && isMidEllipsis.value ? createVNode("li", {
"class": CLASS_MAP.btnMoreClass.value,
"onClick": function onClick() {
return handlePageChange("nextMorePage");
},
"onMouseOver": function onMouseOver() {
return nextMore.value = true;
},
"onMouseOut": function onMouseOut() {
return nextMore.value = false;
}
}, [nextMore.value ? createVNode(__unplugin_components_4, null, null) : createVNode(__unplugin_components_5, null, null)]) : null, isFolded.value && isMidEllipsis.value ? createVNode("li", {
"class": CLASS_MAP.getButtonClass(pageCount.value),
"onClick": function onClick() {
return toPage(pageCount.value);
}
}, [pageCount.value]) : null]) : null, props2.theme === "simple" && Jumper, props2.showPreviousAndNextBtn ? createVNode("div", {
"class": CLASS_MAP.nextBtnClass.value,
"onClick": function onClick() {
return handlePageChange("nextPage");
},
"disabled": disabled || innerCurrent.value === pageCount.value
}, [createVNode(__unplugin_components_3, null, null)]) : null, props2.showFirstAndLastPageBtn ? createVNode("div", {
"class": CLASS_MAP.nextBtnClass.value,
"onClick": function onClick() {
return toPage(pageCount.value);
},
"disabled": disabled || innerCurrent.value === pageCount.value
}, [createVNode(__unplugin_components_7, null, null)]) : null, props2.theme === "default" && props2.showJumper && Jumper]);
};
}
});
export { _Pagination as default };
//# sourceMappingURL=pagination.js.map