@aplus-frontend/ui
Version:
84 lines (83 loc) • 2.99 kB
JavaScript
import { defineComponent as b, Text as f, isVNode as y, computed as m, createVNode as r, Fragment as k } from "vue";
import { ApCopyProps as T } from "./constans.mjs";
import { IconApAdLineCopy as h } from "@aplus-frontend/icon";
import "../../config-provider/index.mjs";
import { message as d } from "@aplus-frontend/antdv";
import { isNull as P, isUndefined as j, isString as A, isBoolean as N } from "lodash-unified";
import { useNamespace as V } from "../../config-provider/hooks/use-namespace.mjs";
import { useLocale as w } from "../../config-provider/hooks/use-locale.mjs";
const D = /* @__PURE__ */ b({
name: "CopyBtn",
props: T(),
setup(e, {
slots: p
}) {
const {
b: x,
e: l,
m: a
} = V("ap-copy"), {
t: s
} = w(), g = (t, n, C) => {
t.stopPropagation(), t.preventDefault(), t.stopImmediatePropagation(), navigator.clipboard.writeText(e.text || c() || "").then(() => {
d.success(n || s("ap.apCopy.copySuccess"));
}).catch(() => {
d.error(C || s("ap.apCopy.copyError"));
});
}, v = (t) => {
if (t.length === 1) {
const n = t[0];
if (n.type === f || n.type.toString() === "Symbol(Text)" || y(n) && typeof n.children == "string")
return !0;
}
return !1;
}, S = (t) => {
if (!t.length) return "";
const n = t[0];
return n.type === f || n.type.toString() === "Symbol(Text)" ? String(n.children) : y(n) && typeof n.children == "string" ? n.children : "";
}, c = () => {
const t = p.default?.();
return t && v(t) ? S(t) : null;
}, u = (t) => !(P(t) || j(t) || typeof t == "string" && t === ""), o = m(() => {
if (typeof e.textStyle == "string")
switch (e.textStyle) {
case "link":
return "text-link";
case "minor":
return "text-minor";
case "major":
return "text-major";
default:
return "text-major";
}
else if (typeof e.textStyle == "object")
return {
...e.textStyle
};
return {};
}), i = m(() => c() || e.text || "");
return () => r(k, null, [r("div", {
class: [x()]
}, [r("div", {
class: [l("text"), typeof o.value == "string" && a(o.value)],
style: typeof o.value != "string" && o.value,
title: typeof o.value == "string" ? i.value : "",
onClick: e.onClick ? () => e.onClick() : void 0
}, [u(i.value) ? e.link && A(e.link) ? r("a", {
href: e.link,
target: "_blank"
}, [i.value]) : N(e.link) ? r("span", {
class: a("text-link")
}, [i.value]) : i.value : "--"]), u(i.value) && !e.disableCopy ? r("div", {
class: [l("copy-btn"), "copy-btn"],
onClick: e.disableCopy ? void 0 : (t) => g(t, e.tipMessageSuccess, e.tipMessageError)
}, [r(h, {
size: e.size
}, null)]) : r("div", {
class: [l("copy-btn"), "copy-btn"]
}, null)])]);
}
});
export {
D as default
};