2019-06-20 19:37:28 +07:00
|
|
|
import { SyntheticEvent } from 'react';
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-10-27 21:49:30 +07:00
|
|
|
export const copyToClipBoardUtility = (str: string): ((e: SyntheticEvent<HTMLElement>) => void) => (
|
|
|
|
event: SyntheticEvent<HTMLElement>
|
|
|
|
): void => {
|
2019-02-03 17:23:33 +07:00
|
|
|
event.preventDefault();
|
2019-06-20 19:37:28 +07:00
|
|
|
|
2019-02-03 17:23:33 +07:00
|
|
|
const node = document.createElement('div');
|
|
|
|
node.innerText = str;
|
|
|
|
if (document.body) {
|
|
|
|
document.body.appendChild(node);
|
2019-06-20 19:37:28 +07:00
|
|
|
|
2019-02-03 17:23:33 +07:00
|
|
|
const range = document.createRange();
|
2019-06-20 19:37:28 +07:00
|
|
|
const selection = window.getSelection() as Selection;
|
2019-02-03 17:23:33 +07:00
|
|
|
range.selectNodeContents(node);
|
|
|
|
selection.removeAllRanges();
|
|
|
|
selection.addRange(range);
|
|
|
|
document.execCommand('copy');
|
|
|
|
document.body.removeChild(node);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export function getCLISetConfigRegistry(command: string, scope: string, registryUrl: string): string {
|
2019-04-14 05:17:21 +07:00
|
|
|
return `${command} ${scope}registry ${registryUrl}`;
|
2019-02-03 17:23:33 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getCLISetRegistry(command: string, registryUrl: string): string {
|
|
|
|
return `${command} --registry ${registryUrl}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getCLIChangePassword(command: string, registryUrl: string): string {
|
|
|
|
return `${command} profile set password --registry ${registryUrl}`;
|
|
|
|
}
|