UNPKG

tdesign-vue

Version:
239 lines (235 loc) 8.43 kB
/** * tdesign v1.15.0 * (c) 2026 tdesign * @license MIT */ import { h as helper } from '../_chunks/dep-53490f85.js'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import _typeof from '@babel/runtime/helpers/typeof'; import { defineComponent, ref, computed, h } from '@vue/composition-api'; import { CheckIcon, CopyIcon } from 'tdesign-icons-vue'; import { usePrefixClass, useConfig } from '../config-provider/useConfig.js'; import { useContent } from '../hooks/tnode.js'; import copyText from '../utils/clipboard.js'; import props from './text-props.js'; import Ellipsis from './components/ellipsis.js'; import { Tooltip } from '../tooltip/index.js'; import { Button } from '../button/index.js'; import '../config-provider/context.js'; import 'lodash-es'; import '../_common/js/global-config/default-config.js'; import '../_common/js/global-config/locale/zh_CN.js'; import '../_chunks/dep-e5d497fb.js'; import '../_chunks/dep-1618e1d6.js'; import 'dayjs'; import '../_common/js/global-config/t.js'; import '@babel/runtime/helpers/slicedToArray'; import '../hooks/render-tnode.js'; import 'clipboard'; import './paragraph-props.js'; import '../tooltip/tooltip.js'; import '../tooltip/props.js'; import '../popup/props.js'; import '../popup/popup.js'; import '@babel/runtime/helpers/toConsumableArray'; import '@popperjs/core'; import '../utils/dom.js'; import 'vue'; import 'raf'; import '../utils/easing.js'; import '../utils/render-tnode.js'; import '@babel/runtime/helpers/readOnlyError'; import '../utils/helper.js'; import '@babel/runtime/helpers/objectWithoutProperties'; import '../_common/js/utils/setStyle.js'; import '../popup/container.js'; import '../config-provider/config-receiver.js'; import '../utils/mixins.js'; import '../utils/event.js'; import '../popup/utils.js'; import '../utils/map-props.js'; import '../utils/withInstall.js'; import '../button/button.js'; 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/helper.js'; import '../utils/transfer-dom.js'; import '../loading/props.js'; import '../config.js'; import '../button/props.js'; import '../utils/ripple.js'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var _Text = defineComponent({ name: "TTypographyText", props: props, setup: function setup(props2) { var COMPONENT_NAME = usePrefixClass("typography"); var _useConfig = useConfig("typography"), globalConfig = _useConfig.globalConfig; var isCopied = ref(false); var renderContent = useContent(); var wrapperDecorations = function wrapperDecorations(_ref, content) { var code = _ref.code, underline = _ref.underline, del = _ref["delete"], strong = _ref.strong, keyboard = _ref.keyboard, mark = _ref.mark, italic = _ref.italic; var currentContent = content; 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 tooltipText = computed(function () { var _copyable$tooltipProp; var copyable = props2.copyable; if (isCopied.value) return globalConfig.value.copiedText; if (_typeof(copyable) === "object") return (_copyable$tooltipProp = copyable.tooltipProps) === null || _copyable$tooltipProp === void 0 ? void 0 : _copyable$tooltipProp.content; return null; }); var contentNode = computed(function () { return renderContent("default", "content"); }); var getChildrenText = function getChildrenText() { var copyable = props2.copyable; if (_typeof(copyable) === "object" && copyable.text) { return copyable.text; } var node = contentNode.value; if (typeof node === "string") { return node; } if (Array.isArray(node)) { return node.map(function (v) { if (typeof v === "string") return v; if (v !== null && v !== void 0 && v.children) return v.children; if (v !== null && v !== void 0 && v.text) return v.text; return ""; }).join(""); } return ""; }; var onCopyClick = function onCopyClick(e, cb) { e.preventDefault(); e.stopPropagation(); isCopied.value = true; setTimeout(function () { isCopied.value = false; }, 1500); copyText(getChildrenText()); cb === null || cb === void 0 || cb(); }; return { isCopied: isCopied, classList: classList, tooltipText: tooltipText, contentNode: contentNode, wrapperDecorations: wrapperDecorations, onCopyClick: onCopyClick }; }, methods: { renderCopy: function renderCopy(afterEllipsis) { var _this = this; var h = this.$createElement; var copyable = this.copyable; var icon = this.isCopied ? function () { return h(CheckIcon); } : function () { return h(CopyIcon); }; var tooltipConf = { theme: "default", hideEmptyPopup: true }; var onCopy = function onCopy() {}; if (_typeof(copyable) === "object") { var copyableConfig = copyable; if (copyableConfig.suffix && !this.isCopied) { icon = copyableConfig.suffix; } if (copyableConfig.tooltipProps) { tooltipConf = copyableConfig.tooltipProps; } if (typeof copyableConfig.onCopy === "function") { onCopy = copyableConfig.onCopy; } } return h(Tooltip, helper([{}, { "props": _objectSpread(_objectSpread({}, tooltipConf), {}, { content: this.tooltipText }) }]), [afterEllipsis ? h("span", { "on": { "click": function click(e) { return _this.onCopyClick(e, onCopy); } } }, [icon()]) : h(Button, helper([{}, { "props": { icon: icon, shape: "square", theme: "primary", variant: "text" } }, { "on": { "click": function click(e) { return _this.onCopyClick(e, onCopy); } } }]))]); } }, render: function render() { var _this2 = this; var h = arguments[0]; var content = this.contentNode; return this.ellipsis ? h(Ellipsis, helper([{}, { "props": this.$props }, { "class": this.classList, "attrs": { "renderCopy": this.copyable ? function () { return _this2.renderCopy(true); } : null } }]), [this.wrapperDecorations(this.$props, content)]) : h("span", { "class": this.classList }, [this.wrapperDecorations(this.$props, content), this.copyable ? this.renderCopy() : null]); } }); export { _Text as default }; //# sourceMappingURL=text.js.map