UNPKG

tdesign-mobile-vue

Version:
162 lines (158 loc) 5.48 kB
/** * tdesign v1.15.0 * (c) 2026 TDesign Group * @license MIT */ import { _ as _typeof } from '../_chunks/dep-fe785552.mjs'; import { isVNode, defineComponent, ref, h, computed, createVNode, mergeProps } from 'vue'; import { CheckIcon, CopyIcon } from 'tdesign-icons-vue-next'; import { useContent } from '../hooks/tnode.mjs'; import { usePrefixClass } from '../hooks/useClass.mjs'; import props from './text-props.mjs'; import Ellipsis from './ellipsis.mjs'; import { copy } from '../_util/copy-to-clipboard.mjs'; import 'lodash-es'; import '../hooks/render-tnode.mjs'; import '../_common/js/utils/general.mjs'; import '../config-provider/useConfig.mjs'; import '../_chunks/dep-71bf849e.mjs'; import '../config-provider/context.mjs'; import '../_common/js/global-config/mobile/default-config.mjs'; import '../_common/js/global-config/mobile/locale/zh_CN.mjs'; import '../_chunks/dep-e4589fcf.mjs'; import '../_chunks/dep-9fdda17b.mjs'; import '../_chunks/dep-7fbd1cf5.mjs'; import '../_chunks/dep-0f7db25a.mjs'; import '../config-provider/type.mjs'; import './paragraph-props.mjs'; 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 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; currentContent = h(Tag, { style: styles }, [currentContent]); } wrap(strong, "strong"); wrap(underline, "u"); wrap(del, "del"); wrap(code, "code"); wrap(mark !== false, "mark", mark ? { backgroundColor: 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 content = computed(function () { return props2.content || (slots === null || slots === void 0 ? void 0 : slots.default()); }); var renderSuffix = function renderSuffix(suffix, copied) { if (typeof suffix === "function") { return suffix(h, { copied: copied }); } if (isVNode(suffix)) { return suffix; } return suffix; }; var renderCopy = function renderCopy(afterEllipsis) { var copyable = props2.copyable; var icon = null; var onCopy = function onCopy() {}; if (_typeof(copyable) === "object") { if (copyable.suffix && !isCopied.value) { icon = renderSuffix(copyable.suffix, isCopied.value); } if (typeof copyable.onCopy === "function") { onCopy = copyable.onCopy; } } if (!icon) { icon = isCopied.value ? createVNode(CheckIcon, null, null) : createVNode(CopyIcon, null, null); } return createVNode("span", { "class": "".concat(COMPONENT_NAME.value, "__copy"), "onClick": function onClick(e) { return onCopyClick(e, onCopy); } }, [icon]); }; var getChildrenText = function getChildrenText() { var copyable = props2.copyable; if (_typeof(copyable) === "object" && copyable !== null && copyable !== void 0 && copyable.text) { return copyable.text; } if (typeof content.value === "string") { return content.value; } if (Array.isArray(content.value)) { return content.value.map(function (v) { return v.children; }).join(""); } return ""; }; 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 _slot; var content2 = renderContent("default", "content"); return props2.ellipsis ? createVNode(Ellipsis, mergeProps(props2, { "class": classList.value, "renderCopy": props2.copyable ? function () { return renderCopy(true); } : null }), _isSlot(_slot = wrapperDecorations(props2, content2)) ? _slot : { default: function _default() { return [_slot]; } }) : createVNode("span", { "class": classList.value }, [wrapperDecorations(props2, content2), props2.copyable ? renderCopy() : null]); }; } }); export { _Text as default }; //# sourceMappingURL=text.mjs.map