UNPKG

@sheerid/jslib-nightly

Version:

SheerID JavaScript Library

132 lines (130 loc) 5.1 kB
/** * WARNING: This file is intended to be used within MySheerID. * This file is not intended for use in other contexts and there are no guarantees about its behavior outside of MySheerID. */ /** * VERSION: 2.230.0-alpha.0 * BUILD_TIMESTAMP: 1778694697559 * BUILD_DATE: Wed May 13 2026 17:51:37 GMT+0000 (Coordinated Universal Time) * BUILD_COMMIT: 7af1c105d5485ac4ed1190c56d492bb4590667a9 */ import { W as T, R as w, j as m } from "../_mysheerid-preview.js"; var y, h; function R() { return h || (h = 1, y = function() { var a = document.getSelection(); if (!a.rangeCount) return function() { }; for (var e = document.activeElement, c = [], r = 0; r < a.rangeCount; r++) c.push(a.getRangeAt(r)); switch (e.tagName.toUpperCase()) { // .toUpperCase handles XHTML case "INPUT": case "TEXTAREA": e.blur(); break; default: e = null; break; } return a.removeAllRanges(), function() { a.type === "Caret" && a.removeAllRanges(), a.rangeCount || c.forEach(function(u) { a.addRange(u); }), e && e.focus(); }; }), y; } var g, v; function D() { if (v) return g; v = 1; var a = R(), e = { "text/plain": "Text", "text/html": "Url", default: "Text" }, c = "Copy to clipboard: #{key}, Enter"; function r(n) { var o = (/mac os x/i.test(navigator.userAgent) ? "⌘" : "Ctrl") + "+C"; return n.replace(/#{\s*key\s*}/g, o); } function u(n, o) { var s, b, C, d, l, t, p = !1; o || (o = {}), s = o.debug || !1; try { C = a(), d = document.createRange(), l = document.getSelection(), t = document.createElement("span"), t.textContent = n, t.ariaHidden = "true", t.style.all = "unset", t.style.position = "fixed", t.style.top = 0, t.style.clip = "rect(0, 0, 0, 0)", t.style.whiteSpace = "pre", t.style.webkitUserSelect = "text", t.style.MozUserSelect = "text", t.style.msUserSelect = "text", t.style.userSelect = "text", t.addEventListener("copy", function(i) { if (i.stopPropagation(), o.format) if (i.preventDefault(), typeof i.clipboardData > "u") { s && console.warn("unable to use e.clipboardData"), s && console.warn("trying IE specific stuff"), window.clipboardData.clearData(); var f = e[o.format] || e.default; window.clipboardData.setData(f, n); } else i.clipboardData.clearData(), i.clipboardData.setData(o.format, n); o.onCopy && (i.preventDefault(), o.onCopy(i.clipboardData)); }), document.body.appendChild(t), d.selectNodeContents(t), l.addRange(d); var x = document.execCommand("copy"); if (!x) throw new Error("copy command was unsuccessful"); p = !0; } catch (i) { s && console.error("unable to copy using execCommand: ", i), s && console.warn("trying IE specific stuff"); try { window.clipboardData.setData(o.format || "text", n), o.onCopy && o.onCopy(window.clipboardData), p = !0; } catch (f) { s && console.error("unable to copy using clipboardData: ", f), s && console.error("falling back to prompt"), b = r("message" in o ? o.message : c), window.prompt(b, n); } } finally { l && (typeof l.removeRange == "function" ? l.removeRange(d) : l.removeAllRanges()), t && document.body.removeChild(t), C(); } return p; } return g = u, g; } var S = D(); const E = /* @__PURE__ */ T(S), k = 2e3, _ = "sid-to-clipboard__notification-text sid-to-clipboard__notification-text--hidden", N = "sid-to-clipboard__notification-text sid-to-clipboard__notification-text--visible"; class U extends w.Component { notificationTimeout; timeoutRef; // VS Code wants "Timer" but tsc wants "number". TODO - figure out a fix to be more specific here. constructor(e) { super(e), this.doCopy = this.doCopy.bind(this), this.state = { isShowing: !1 }, e.notificationTimeout ? this.notificationTimeout = e.notificationTimeout : this.notificationTimeout = k; } componentWillUnmount() { clearTimeout(this.timeoutRef); } doCopy() { const { textToCopy: e } = this.props; E(e), this.setState(() => ({ isShowing: !0 })), clearTimeout(this.timeoutRef), this.timeoutRef = setTimeout(() => { this.setState(() => ({ isShowing: !1 })); }, this.notificationTimeout); } render() { const { isShowing: e } = this.state, { notificationText: c, children: r } = this.props; return /* @__PURE__ */ m.jsxs("div", { className: "sid-to-clipboard", children: [ /* @__PURE__ */ m.jsx( "div", { className: `${e ? N : _}`, role: "status", "aria-live": "polite", "aria-atomic": !0, children: e && (c || "Copied") } ), /* @__PURE__ */ m.jsx( "div", { onClick: this.doCopy, onKeyPress: this.doCopy, role: "button", tabIndex: 0, className: "sid-to-clipboard__clickable-text sid-link", children: r || "Copy" } ) ] }); } } export { U as C };