refactor: Fix eslint warnings (#3698)
* Update dependencies and remove typescript version pinning (fixed upstream) * Fix esling warnings (disabled any and script lang checks) Rewrote clipboard copy (Fixes #3407) Run prettier --------- Co-authored-by: Oleg Lobanov <oleg@lobanov.me>
This commit is contained in:
1 parent
cc331383fb
commit
0201f9c5c4
37 files changed
+1085
-1026
No files matched your search
@@ -24,7 +24,7 @@ export async function validateLogin() {
|
||||
await renew(<string>localStorage.getItem("jwt"));
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("Invalid JWT token in storage"); // eslint-disable-line
|
||||
console.warn("Invalid JWT token in storage");
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ function loading(button: string) {
|
||||
);
|
||||
|
||||
if (el === undefined || el === null) {
|
||||
console.log("Error getting button " + button); // eslint-disable-line
|
||||
console.log("Error getting button " + button);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ function done(button: string) {
|
||||
);
|
||||
|
||||
if (el === undefined || el === null) {
|
||||
console.log("Error getting button " + button); // eslint-disable-line
|
||||
console.log("Error getting button " + button);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ function success(button: string) {
|
||||
);
|
||||
|
||||
if (el === undefined || el === null) {
|
||||
console.log("Error getting button " + button); // eslint-disable-line
|
||||
console.log("Error getting button " + button);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,39 +1,36 @@
|
||||
// Based on code by the following links:
|
||||
// https://stackoverflow.com/a/74528564
|
||||
// https://web.dev/articles/async-clipboard
|
||||
export function copy(text: string) {
|
||||
|
||||
interface ClipboardArgs {
|
||||
text?: string;
|
||||
data?: ClipboardItems;
|
||||
}
|
||||
|
||||
interface ClipboardOpts {
|
||||
permission?: boolean;
|
||||
}
|
||||
|
||||
export function copy(data: ClipboardArgs, opts?: ClipboardOpts) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
if (
|
||||
// Clipboard API requires secure context
|
||||
window.isSecureContext &&
|
||||
typeof navigator.clipboard !== "undefined" &&
|
||||
// @ts-ignore
|
||||
navigator.permissions !== "undefined"
|
||||
typeof navigator.clipboard !== "undefined"
|
||||
) {
|
||||
navigator.permissions
|
||||
// @ts-ignore
|
||||
.query({ name: "clipboard-write" })
|
||||
.then((permission) => {
|
||||
if (permission.state === "granted" || permission.state === "prompt") {
|
||||
// simple writeText should work for all modern browsers
|
||||
navigator.clipboard.writeText(text).then(resolve).catch(reject);
|
||||
} else {
|
||||
reject(new Error("Permission not granted!"));
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
// Firefox doesn't support clipboard-write permission
|
||||
if (navigator.userAgent.indexOf("Firefox") != -1) {
|
||||
navigator.clipboard.writeText(text).then(resolve).catch(reject);
|
||||
} else {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
if (opts?.permission) {
|
||||
getPermission("clipboard-write")
|
||||
.then(() => writeToClipboard(data).then(resolve).catch(reject))
|
||||
.catch(reject);
|
||||
} else {
|
||||
writeToClipboard(data).then(resolve).catch(reject);
|
||||
}
|
||||
} else if (
|
||||
document.queryCommandSupported &&
|
||||
document.queryCommandSupported("copy")
|
||||
document.queryCommandSupported("copy") &&
|
||||
data.text // old method only supports text
|
||||
) {
|
||||
const textarea = createTemporaryTextarea(text);
|
||||
const textarea = createTemporaryTextarea(data.text);
|
||||
const body = document.activeElement || document.body;
|
||||
try {
|
||||
body.appendChild(textarea);
|
||||
@@ -54,6 +51,35 @@ export function copy(text: string) {
|
||||
});
|
||||
}
|
||||
|
||||
function getPermission(name: string) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
typeof navigator.permissions !== "undefined" &&
|
||||
navigator.permissions
|
||||
// @ts-expect-error chrome specific api
|
||||
.query({ name })
|
||||
.then((permission) => {
|
||||
if (permission.state === "granted" || permission.state === "prompt") {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Error("Permission denied!"));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function writeToClipboard(data: ClipboardArgs) {
|
||||
if (data.text) {
|
||||
return navigator.clipboard.writeText(data.text);
|
||||
}
|
||||
if (data.data) {
|
||||
return navigator.clipboard.write(data.data);
|
||||
}
|
||||
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
reject(new Error("No data was supplied!"));
|
||||
});
|
||||
}
|
||||
|
||||
const styles = {
|
||||
fontSize: "12pt",
|
||||
position: "fixed",
|
||||
@@ -69,10 +95,10 @@ const styles = {
|
||||
background: "transparent",
|
||||
};
|
||||
|
||||
const createTemporaryTextarea = (text: string) => {
|
||||
function createTemporaryTextarea(text: string) {
|
||||
const textarea = document.createElement("textarea");
|
||||
textarea.value = text;
|
||||
textarea.setAttribute("readonly", "");
|
||||
Object.assign(textarea.style, styles);
|
||||
return textarea;
|
||||
};
|
||||
}
|
||||
@@ -6,13 +6,16 @@ export default function getRule(rules: string[]) {
|
||||
let result = null;
|
||||
const find = Array.prototype.find;
|
||||
|
||||
find.call(document.styleSheets, (styleSheet) => {
|
||||
result = find.call(styleSheet.cssRules, (cssRule) => {
|
||||
find.call(document.styleSheets, (styleSheet: CSSStyleSheet) => {
|
||||
result = find.call(styleSheet.cssRules, (cssRule: CSSRule) => {
|
||||
let found = false;
|
||||
|
||||
if (cssRule instanceof window.CSSStyleRule) {
|
||||
// faster than checking instanceof for every element
|
||||
if (cssRule.constructor.name === "CSSStyleRule") {
|
||||
for (let i = 0; i < rules.length; i++) {
|
||||
if (cssRule.selectorText.toLowerCase() === rules[i]) {
|
||||
if (
|
||||
(cssRule as CSSStyleRule).selectorText.toLowerCase() === rules[i]
|
||||
) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
@@ -24,5 +27,5 @@ export default function getRule(rules: string[]) {
|
||||
return result != null;
|
||||
});
|
||||
|
||||
return result;
|
||||
return result as CSSStyleRule | null;
|
||||
}
|
||||
Reference in new issue
Block a user