@vectara/vectara-ui
Version:
Vectara's design system, codified as a React and Sass component library
28 lines (27 loc) • 1.49 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import copy from "copy-to-clipboard";
export const copyToClipboard = (value) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c;
try {
// Some older browsers don't support navigator.clipboard.writeText and there are
// other cases where it might not be available, e.g. over an http connection.
if ((_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText) {
yield ((_c = (_b = navigator.clipboard) === null || _b === void 0 ? void 0 : _b.writeText) === null || _c === void 0 ? void 0 : _c.call(_b, value));
}
else {
copy(value);
}
}
catch (error) {
console.error("Failed to copy to clipboard with error:\n", error, `Tried to copy: ${value}\n`);
throw error;
}
});