UNPKG

tdesign-vue-next

Version:
202 lines (198 loc) 7.05 kB
/** * tdesign v1.15.2 * (c) 2025 tdesign * @license MIT */ import { defineComponent, ref, computed, createVNode, mergeProps, isVNode } from 'vue'; import _typeof from '@babel/runtime/helpers/typeof'; import 'lodash-es'; import '@babel/runtime/helpers/toConsumableArray'; import '../_chunks/dep-e604a5ce.js'; import { a as useContent } from '../_chunks/dep-1d44782f.js'; import { u as usePrefixClass } from '../_chunks/dep-79c44a11.js'; import '@babel/runtime/helpers/slicedToArray'; import '../_chunks/dep-7324137b.js'; import '@babel/runtime/helpers/defineProperty'; import props from './text-props.js'; import copy from './utils/copy-to-clipboard.js'; import { CheckIcon, CopyIcon } from 'tdesign-icons-vue-next'; import Ellipsis from './components/ellipsis.js'; import { Tooltip } from '../tooltip/index.js'; import { Button } from '../button/index.js'; import { useConfig } from '../config-provider/hooks/useConfig.js'; import '../_chunks/dep-7fac49fa.js'; import '../_chunks/dep-1f7ad104.js'; import '../_chunks/dep-6c13cc0e.js'; import '../config-provider/utils/context.js'; import '../_chunks/dep-3b49fbbe.js'; import 'dayjs'; import '@babel/runtime/helpers/createClass'; import '@babel/runtime/helpers/classCallCheck'; import './paragraph-props.js'; import '../tooltip/tooltip.js'; import '../tooltip/props.js'; import '../popup/props.js'; import '../popup/index.js'; import '../popup/popup.js'; import '@popperjs/core'; import '../_chunks/dep-b9ab7399.js'; import '../_chunks/dep-3ba91e12.js'; import '../_chunks/dep-34e44a4e.js'; import '../popup/container.js'; import '../_chunks/dep-82e44120.js'; import '../_chunks/dep-37a2e7c8.js'; import '../tooltip/utils/index.js'; import '../button/button.js'; import '../loading/index.js'; import '../loading/directive.js'; import '../loading/plugin.js'; import '../_chunks/dep-199af351.js'; import '../loading/icon/gradient.js'; import '../_chunks/dep-a72765fe.js'; import '@babel/runtime/helpers/objectWithoutProperties'; import '../loading/props.js'; import '../button/props.js'; import '../_chunks/dep-5360ac56.js'; import '../_chunks/dep-7b209207.js'; function _isSlot(s) { return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s); } var _Text = defineComponent({ name: "TTypographyText", props: props, setup: function setup(props2, _ref) { var slots = _ref.slots; var COMPONENT_NAME = usePrefixClass("typography"); var _useConfig = useConfig("typography"), globalConfig = _useConfig.globalConfig; var isCopied = ref(false); var renderContent = useContent(); var wrapperDecorations = function wrapperDecorations(_ref2, content2) { var code = _ref2.code, underline = _ref2.underline, del = _ref2["delete"], strong = _ref2.strong, keyboard = _ref2.keyboard, mark = _ref2.mark, italic = _ref2.italic; var currentContent = content2; function wrap(needed, Tag) { var styles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; if (!needed) return; var _currentContent = function () { return currentContent; }(); currentContent = createVNode(Tag, { "style": styles }, _isSlot(currentContent) ? currentContent : { "default": function _default() { return [_currentContent]; } }); } wrap(strong, "strong"); wrap(underline, "u"); wrap(del, "del"); wrap(code, "code"); wrap(mark !== false, "mark", mark ? { color: mark } : {}); wrap(keyboard, "kbd"); wrap(italic, "i"); return currentContent; }; var classList = computed(function () { var theme = props2.theme, disabled = props2.disabled; var prefix = COMPONENT_NAME.value; var list = [prefix]; if (disabled) { list.push("".concat(prefix, "--disabled")); } else if (theme && ["primary", "secondary", "success", "warning", "error"].includes(theme)) { list.push("".concat(prefix, "--").concat(theme)); } return list; }); var tooltipText = computed(function () { var _copyable$tooltipProp; var copyable = props2.copyable; if (isCopied.value) return globalConfig.value.copiedText;else if (_typeof(copyable) === "object") return (_copyable$tooltipProp = copyable.tooltipProps) === null || _copyable$tooltipProp === void 0 ? void 0 : _copyable$tooltipProp.content; return null; }); var content = computed(function () { return props2.content || (slots === null || slots === void 0 ? void 0 : slots["default"]()); }); var renderCopy = function renderCopy() { var copyable = props2.copyable; if (!copyable) return; var icon = isCopied.value ? function () { return createVNode(CheckIcon, null, null); } : function () { return createVNode(CopyIcon, null, null); }; var tooltipConf = { theme: "default" }; var onCopy = function onCopy() {}; if (_typeof(copyable) === "object") { if (copyable.suffix && !isCopied.value) { icon = copyable.suffix; } if (copyable.tooltipProps) { tooltipConf = copyable.tooltipProps; } if (typeof copyable.onCopy === "function") { onCopy = copyable.onCopy; } } return createVNode(Tooltip, mergeProps(tooltipConf, { "content": tooltipText.value }), { "default": function _default() { return [createVNode(Button, { "icon": icon, "shape": "square", "theme": "primary", "variant": "text", "onClick": function onClick(e) { return onCopyClick(e, onCopy); } }, null)]; } }); }; var getChildrenText = function getChildrenText() { if (typeof content.value === "string") { return content.value; } else if (Array.isArray(content.value)) { return content.value.map(function (v) { return v.children; }).join(""); } }; var onCopyClick = function onCopyClick(e, cb) { e.preventDefault(); e.stopPropagation(); isCopied.value = true; setTimeout(function () { isCopied.value = false; }, 1500); copy(getChildrenText()); cb === null || cb === void 0 || cb(); }; return function () { var content2 = renderContent("default", "content"); return props2.ellipsis ? createVNode(Ellipsis, mergeProps(props2, { "class": classList.value }), { "default": function _default() { return [wrapperDecorations(props2, content2), props2.copyable ? renderCopy() : null]; } }) : createVNode("span", { "class": classList.value }, [wrapperDecorations(props2, content2), props2.copyable ? renderCopy() : null]); }; } }); export { _Text as default }; //# sourceMappingURL=text.js.map