tdesign-mobile-vue
Version:
tdesign-mobile-vue
162 lines (158 loc) • 5.44 kB
JavaScript
/**
* tdesign v1.15.0
* (c) 2026 TDesign Group
* @license MIT
*/
import _typeof from '@babel/runtime/helpers/typeof';
import { isVNode, defineComponent, ref, h, computed, createVNode, mergeProps } from 'vue';
import { CheckIcon, CopyIcon } from 'tdesign-icons-vue-next';
import { useContent } from '../hooks/tnode.js';
import { usePrefixClass } from '../hooks/useClass.js';
import props from './text-props.js';
import Ellipsis from './ellipsis.js';
import { copy } from '../_util/copy-to-clipboard.js';
import 'lodash-es';
import '../hooks/render-tnode.js';
import '../_common/js/utils/general.js';
import '../config-provider/useConfig.js';
import '@babel/runtime/helpers/defineProperty';
import '../config-provider/context.js';
import '../_common/js/global-config/mobile/default-config.js';
import '../_common/js/global-config/mobile/locale/zh_CN.js';
import '../_chunks/dep-b2370385.js';
import '../_chunks/dep-d631e92f.js';
import 'dayjs';
import '../_chunks/dep-a85a47ac.js';
import '../config-provider/type.js';
import './paragraph-props.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 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.js.map