tdesign-vue-next
Version:
TDesign Component for vue-next
200 lines (196 loc) • 7.04 kB
JavaScript
/**
* tdesign v1.19.2
* (c) 2026 tdesign
* @license MIT
*/
import { isVNode, defineComponent, ref, h, computed, createVNode, mergeProps } from 'vue';
import { _ as _typeof } from '../_chunks/dep-e1c62679.mjs';
import { u as usePrefixClass, b as useContent } from '../_chunks/dep-fbeb2963.mjs';
import props from './text-props.mjs';
import { k as copy } from '../_chunks/dep-feed89df.mjs';
import { CheckIcon, CopyIcon } from 'tdesign-icons-vue-next';
import Ellipsis from './components/ellipsis.mjs';
import { Tooltip } from '../tooltip/index.mjs';
import { Button } from '../button/index.mjs';
import { useConfig } from '../config-provider/hooks/useConfig.mjs';
import 'lodash-es';
import '../_chunks/dep-47c3cae9.mjs';
import '../_chunks/dep-b0b422fe.mjs';
import '../_chunks/dep-edab0e6a.mjs';
import '../_chunks/dep-f558ebb8.mjs';
import '../_chunks/dep-76dddedf.mjs';
import '../_chunks/dep-d92220c4.mjs';
import '../config-provider/utils/context.mjs';
import '../_chunks/dep-e0ab6d55.mjs';
import '../_chunks/dep-5b510fcd.mjs';
import '../_chunks/dep-75f265c4.mjs';
import '../_chunks/dep-67ffcfeb.mjs';
import '../_chunks/dep-466a8f31.mjs';
import '../_chunks/dep-ba214d75.mjs';
import '../_chunks/dep-e66c0337.mjs';
import './paragraph-props.mjs';
import '../tooltip/tooltip.mjs';
import '../tooltip/props.mjs';
import '../popup/props.mjs';
import '../popup/index.mjs';
import '../popup/popup.mjs';
import '@popperjs/core';
import '../popup/container.mjs';
import './style/css.mjs';
import '../tooltip/utils/index.mjs';
import '../button/button.mjs';
import '../loading/index.mjs';
import '../loading/directive.mjs';
import '../loading/plugin.mjs';
import '../loading/loading.mjs';
import '../loading/icon/gradient.mjs';
import '../_chunks/dep-58979704.mjs';
import '../_chunks/dep-c231a5b4.mjs';
import '../loading/props.mjs';
import '../button/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 _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;
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;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(afterEllipsis) {
var copyable = props2.copyable;
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 [afterEllipsis ? createVNode("span", {
"onClick": function onClick(e) {
return onCopyClick(e, onCopy);
}
}, [icon()]) : createVNode(Button, {
"icon": icon,
"shape": "square",
"theme": "primary",
"variant": "text",
"onClick": function onClick(e) {
return onCopyClick(e, onCopy);
}
}, null)];
}
});
};
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;
} 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 _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