UNPKG

tdesign-vue-next

Version:
309 lines (304 loc) 10.1 kB
/** * tdesign v1.19.2 * (c) 2026 tdesign * @license MIT */ import { defineComponent, ref, computed, createVNode, mergeProps, isVNode, h } from 'vue'; import _typeof from '@babel/runtime/helpers/typeof'; import 'lodash-es'; import '@babel/runtime/helpers/toConsumableArray'; import '../_chunks/dep-c68ea098.js'; import { a as useContent } from '../_chunks/dep-7bdccf65.js'; import { u as usePrefixClass } from '../_chunks/dep-e8dd47a9.js'; import '@babel/runtime/helpers/slicedToArray'; import '../_chunks/dep-91fc762d.js'; import '@babel/runtime/helpers/defineProperty'; import props from './text-props.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-f0f392fb.js'; import '../_chunks/dep-d518fdfb.js'; import '../_chunks/dep-8d4d971b.js'; import '../config-provider/utils/context.js'; import '../_chunks/dep-509ddbe3.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-98d89c71.js'; import '../_chunks/dep-ef7a41ce.js'; import '../_chunks/dep-e332908e.js'; import '../popup/container.js'; import '../_chunks/dep-d5fc4caa.js'; import '../_chunks/dep-ae3e94b6.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-2a7145b5.js'; import '../loading/icon/gradient.js'; import '../_chunks/dep-fbf70ecb.js'; import '@babel/runtime/helpers/objectWithoutProperties'; import '../loading/props.js'; import '../button/props.js'; import '../_chunks/dep-2ba9b7d0.js'; import '../_chunks/dep-d67d6f8a.js'; var defaultMessage = "Copy to clipboard: #{key}, Enter"; var format = function format(message) { var copyKey = (/mac os x/i.test(navigator.userAgent) ? "\u2318" : "Ctrl") + "+C"; return message.replace(/#{\s*key\s*}/g, copyKey); }; var deselectCurrent = function deselectCurrent() { var selection = document.getSelection(); if (!selection.rangeCount) { return function () {}; } var active = document.activeElement; var ranges = []; for (var i = 0; i < selection.rangeCount; i++) { ranges.push(selection.getRangeAt(i)); } var tagName = active.tagName.toUpperCase(); switch (tagName) { case "INPUT": case "TEXTAREA": active.blur(); break; default: active = null; break; } selection.removeAllRanges(); return function () { selection.type === "Caret" && selection.removeAllRanges(); if (!selection.rangeCount) { ranges.forEach(function (range) { selection.addRange(range); }); } active && active.focus(); }; }; var copy = function copy(text, options) { var message, reselectPrevious, range, selection, mark, success = false; if (!options) { options = {}; } try { reselectPrevious = deselectCurrent(); range = document.createRange(); selection = document.getSelection(); mark = document.createElement("span"); mark.textContent = text; mark.style.all = "unset"; mark.style.position = "fixed"; mark.style.top = "0"; mark.style.clip = "rect(0, 0, 0, 0)"; mark.style.whiteSpace = "pre"; mark.style.webkitUserSelect = "text"; mark.style.userSelect = "text"; mark.addEventListener("copy", function (e) { e.stopPropagation(); if (options.format) { e.preventDefault(); e.clipboardData.clearData(); e.clipboardData.setData(options.format, text); } if (options.onCopy) { e.preventDefault(); options.onCopy(e.clipboardData); } }); document.body.appendChild(mark); range.selectNodeContents(mark); selection.addRange(range); var successful = document.execCommand("copy"); if (!successful) { throw new Error("copy command was unsuccessful"); } success = true; } catch (err) { try { window.clipboardData.setData(options.format || "text", text); options.onCopy && options.onCopy(window.clipboardData); success = true; } catch (err2) { message = format("message" in options ? options.message : defaultMessage); window.prompt(message, text); } } finally { if (selection) { if (typeof selection.removeRange == "function") { selection.removeRange(range); } else { selection.removeAllRanges(); } } if (mark) { document.body.removeChild(mark); } reselectPrevious(); } return success; }; 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.js.map