UNPKG

xdesign-vue-next

Version:

XDesign Component for vue-next

149 lines (145 loc) 6.16 kB
/** * xdesign v1.0.6 * (c) 2023 xdesign * @license MIT */ import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { defineComponent, computed, createVNode, mergeProps } from 'vue'; import props from './props.js'; import isObject from 'lodash/isObject'; import _StickyItem from './sticky-item.js'; import { usePrefixClass } from '../hooks/useConfig.js'; import stickyItemProps from './sticky-item-props.js'; import { useChildComponentSlots } from '../hooks/slot.js'; import '../popup/index.js'; import '../popup/popup.js'; import '@babel/runtime/helpers/slicedToArray'; import '@popperjs/core'; import 'lodash/isFunction'; import 'lodash/debounce'; import 'lodash/isString'; import '../hooks/useVModel.js'; import 'lodash/kebabCase'; import '../utils/dom.js'; import '../_chunks/dep-3a1cce9f.js'; import 'lodash/isArray'; import '../utils/easing.js'; import '../_common/js/utils/set-style.js'; import '../popup/container.js'; import '@babel/runtime/helpers/toConsumableArray'; import '../popup/props.js'; import '../hooks/useResizeObserver.js'; import '../hooks/tnode.js'; import 'lodash/camelCase'; import '../utils/render-tnode.js'; import 'lodash/isEmpty'; import '../utils/withInstall.js'; import '../config-provider/useConfig.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 '@babel/runtime/helpers/typeof'; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } var _StickyTool = defineComponent({ name: "XStickyTool", props: _objectSpread({}, props), setup: function setup(props2) { var COMPONENT_NAME = usePrefixClass("sticky-tool"); var classes = computed(function () { return [COMPONENT_NAME.value, "".concat(COMPONENT_NAME.value, "--").concat(props2.shape)]; }); var styles = computed(function () { var styles2 = getOffset(); if (props2.width) styles2.width = typeof props2.width === "number" ? "".concat(props2.width, "px") : props2.width; return styles2; }); var getChildComponentByName = useChildComponentSlots(); var getList = function getList() { var _props2$list; var list; if ((_props2$list = props2.list) !== null && _props2$list !== void 0 && _props2$list.length) { list = props2.list; } else { var nodes = getChildComponentByName("StickyItem"); list = getListBySlots(nodes); } return list; }; var getListBySlots = function getListBySlots(nodes) { var arr = []; nodes === null || nodes === void 0 ? void 0 : nodes.forEach(function (node) { var list = (node === null || node === void 0 ? void 0 : node.props) || {}; var children = node === null || node === void 0 ? void 0 : node.children; if (!list && !children) return; if (children && isObject(children)) { for (var key in children) { if (key in stickyItemProps && !list[key]) { list[key] = children[key]; } } } arr.push(list); }); return arr; }; var getOffset = function getOffset() { var _props2$offset; var position = props2.offset ? [80, 24] : ["80px", "24px"]; (_props2$offset = props2.offset) === null || _props2$offset === void 0 ? void 0 : _props2$offset.forEach(function (item, index) { position[index] = isNaN(Number(item)) ? "calc( ".concat(position[index], "px + ").concat(item, ")") : "".concat(position[index] + item, "px"); }); var offsetStyle = {}; props2.placement.split("-").forEach(function (item, index) { if (item !== "center") { offsetStyle[item] = position[index]; } else { offsetStyle.top = "50%"; offsetStyle.transform = "translate(0, -50%)"; } }); return offsetStyle; }; var handleClick = function handleClick(context) { var _props2$onClick; (_props2$onClick = props2.onClick) === null || _props2$onClick === void 0 ? void 0 : _props2$onClick.call(props2, context); }; var handleHover = function handleHover(context) { var _props2$onHover; (_props2$onHover = props2.onHover) === null || _props2$onHover === void 0 ? void 0 : _props2$onHover.call(props2, context); }; var renderContent = function renderContent() { var list = getList(); var content = list.map(function (item, index) { var type = props2.type, shape = props2.shape, placement = props2.placement, popupProps = props2.popupProps; var itemProps = _objectSpread(_objectSpread({}, item), {}, { type: type, shape: shape, placement: placement, basePopupProps: popupProps, baseWidth: styles.value.width, onClick: handleClick, onHover: handleHover }); return createVNode(_StickyItem, mergeProps(itemProps, { "key": index }), null); }); return content; }; return function () { return createVNode("div", { "class": classes.value, "style": styles.value }, [renderContent()]); }; } }); export { _StickyTool as default }; //# sourceMappingURL=sticky-tool.js.map