UNPKG

@vrx-arco/use

Version:

<p align="center"> <img src="https://vrx-arco.github.io/arco-design-pro/favicon.svg" width="200" height="250"> </p>

244 lines (238 loc) 6.68 kB
'use strict'; var core = require('@vueuse/core'); var vue = require('vue'); // src/useShareBreakpoints/index.ts var useShareBreakpoints = () => { const _useShareBreakpoints = core.createSharedComposable(core.useBreakpoints); return _useShareBreakpoints({ sm: 576, md: 768, lg: 992, xl: 1200, xxl: 1600 }); }; // src/propsSlot/index.ts var propsSlot = (slots, props, key, slotKey) => { var _a, _b; return (_b = props[key]) != null ? _b : (_a = slots[slotKey || key]) == null ? void 0 : _a.call(slots); }; var useAutoProPagination = (originData, paginationProps) => { const defaultPageSize = vue.computed( () => { var _a; return ((_a = paginationProps.value) == null ? void 0 : _a.defaultPageSize) || 10; } ); const total = vue.computed(() => originData.value.length); const current = vue.ref(1); const pageSize = vue.ref(defaultPageSize.value || 10); const getPaginationList = () => { const pageRange = [0, 0]; pageRange[0] = (current.value - 1) * pageSize.value; pageRange[1] = pageRange[0] + pageSize.value; if (pageRange[1] > total.value) { pageRange[1] = total.value; } return originData.value.slice(...pageRange); }; const data = vue.computed(() => getPaginationList()); const pageChange = (value) => { current.value = value; getPaginationList(); }; const pageSizeChange = (value) => { current.value = 1; pageSize.value = value; getPaginationList(); }; return { data, total, current, pageSize, pageChange, pageSizeChange }; }; // src/useProPagination/useProPagination.ts var useProPagination = (data, pagination, paginationProps) => { if (pagination.value === true) { return useAutoProPagination(data, paginationProps); } const total = vue.computed(() => { var _a; return ((_a = pagination.value) == null ? void 0 : _a.total) || 0; }); const current = vue.computed({ get: () => { var _a; return ((_a = pagination.value) == null ? void 0 : _a.pageNum) || 1; }, set: (value) => { if (typeof pagination.value !== "object") { return; } pagination.value.pageNum = value; } }); const pageSize = vue.computed({ get: () => { var _a; return ((_a = pagination.value) == null ? void 0 : _a.pageSize) || 10; }, set: (value) => { if (typeof pagination.value !== "object") { return; } pagination.value.pageSize = value; } }); const pageChange = (value) => { current.value = value; }; const pageSizeChange = (value) => { current.value = 1; pageSize.value = value; }; return { total, current, pageSize, pageChange, pageSizeChange, data }; }; var useGrid = (useColumn, column, gutter) => { const getColumn = (column2) => useColumn ? Math.ceil(24 / column2) : column2; const { xxl, xl, lg, md, sm, smaller } = useShareBreakpoints(); const xs = smaller("sm"); const grid = vue.computed(() => { const grid2 = { xxl: xxl.value, xl: xl.value, lg: lg.value, md: md.value, sm: sm.value, xs: xs.value }; return Object.keys(grid2).find((key) => grid2[key]) || "span"; }); const gridProps = vue.computed(() => { if (typeof column.value === "number") { return { span: getColumn(column.value), gutter: vue.unref(gutter) }; } return { gutter: vue.unref(gutter), span: getColumn(column.value[grid.value]) || 6 }; }); return { gridProps, grid }; }; var controlVModel = (props, name, emit, init) => { const value = vue.ref(init()); return vue.computed({ get() { var _a; return (_a = props[name]) != null ? _a : value.value; }, set(v) { emit(`update:${name}`, v); value.value = v; } }); }; var isEmptyElement = (c) => c && (c.type === vue.Comment || c.type === vue.Fragment && c.children.length === 0 || c.type === vue.Text && c.children.trim() === ""); var filterEmptyChildren = (children = []) => { const res = []; children.forEach((child) => { if (Array.isArray(child)) { res.push(...child); return; } if ((child == null ? void 0 : child.type) === vue.Fragment) { res.push(...filterEmptyChildren(child.children)); return; } res.push(child); }); return res.filter((c) => !isEmptyElement(c)); }; var EmptyComponentContext = Symbol("EmptyComponent"); var useEmptyComponentProvide = () => { const empty = vue.ref(false); vue.provide(EmptyComponentContext, { empty }); return { empty }; }; var useEmptyComponentInject = () => vue.inject(EmptyComponentContext, { empty: vue.ref(false) }); var createTreeSelectFilterNode = (fieldNames) => { const filterTreeNode = (searchKey, nodeData) => { if (!searchKey) { return true; } const _fieldNames = vue.toValue(fieldNames); const value = nodeData[_fieldNames.title || "title"]; return String(value).includes(searchKey); }; return { fieldNames, filterTreeNode }; }; var useRangePickerObjectValue = (model, startKey, endKey) => { return vue.computed({ get: () => { const data = vue.toValue(model); const start = data[startKey]; const end = data[endKey]; if (start && end) { return [start, end]; } return []; }, set: (list = []) => { const data = vue.toValue(model); data[startKey] = list[0]; data[endKey] = list[1]; } }); }; function useAbortController(options) { const supportAbort = typeof AbortController === "function"; let contoller = null; const abort = () => { if (!supportAbort) { return; } contoller == null ? void 0 : contoller.abort(); contoller = new AbortController(); if (options == null ? void 0 : options.onabort) { contoller.signal.onabort = options.onabort; } }; abort(); vue.onBeforeUnmount(() => { contoller == null ? void 0 : contoller.abort(); contoller = null; }); return { abort, get signal() { return contoller == null ? void 0 : contoller.signal; } }; } exports.controlVModel = controlVModel; exports.createTreeSelectFilterNode = createTreeSelectFilterNode; exports.filterEmptyChildren = filterEmptyChildren; exports.propsSlot = propsSlot; exports.useAbortController = useAbortController; exports.useEmptyComponentInject = useEmptyComponentInject; exports.useEmptyComponentProvide = useEmptyComponentProvide; exports.useGrid = useGrid; exports.useProPagination = useProPagination; exports.useRangePickerObjectValue = useRangePickerObjectValue; exports.useShareBreakpoints = useShareBreakpoints;