mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 01:15:22 +00:00
384c987389
* clean up routes and useless components * component clean up * removed redux from routes * rename file * moved useDeepEffect hook with others * removed redux, fleet, app_constants dirs; added types to utilities * style cleanup * typo fix * removed unused ts-ignore comments * removed redux packages!!! * formatting * fixed typing for simple search function * updated frontend readme
41 lines
946 B
TypeScript
41 lines
946 B
TypeScript
// @ts-nocheck - may need to be reworked
|
|
import select from "select";
|
|
|
|
const removeSelectedText = () => {
|
|
return global.window.getSelection().removeAllRanges();
|
|
};
|
|
|
|
export const copyText = (elementSelector: string) => {
|
|
const { document } = global;
|
|
|
|
const element = document.querySelector(elementSelector);
|
|
const input = element.querySelector("input");
|
|
input.type = "text";
|
|
input.disabled = false;
|
|
|
|
select(input);
|
|
|
|
const canCopy = document.queryCommandEnabled("copy");
|
|
|
|
if (!canCopy) {
|
|
return false;
|
|
}
|
|
|
|
document.execCommand("copy");
|
|
input.type = "password";
|
|
input.disabled = true;
|
|
removeSelectedText();
|
|
return true;
|
|
};
|
|
|
|
export const stringToClipboard = (string) => {
|
|
const { navigator } = global;
|
|
|
|
return navigator.clipboard.writeText(string);
|
|
};
|
|
|
|
export const COPY_TEXT_SUCCESS = "Text copied to clipboard";
|
|
export const COPY_TEXT_ERROR = "Text not copied. Please copy manually.";
|
|
|
|
export default copyText;
|