Add typing to pageUtils.ts.
This commit is contained in:
parent
a237443aca
commit
859717e482
|
@ -1,5 +1,5 @@
|
|||
import { MarginInline } from "./MarginInline.js";
|
||||
import { addClipboardNotifications } from "../pageUtils.js";
|
||||
import { addClipboardNotifications } from "../pageUtils";
|
||||
import { makeElement } from "../htmlUtils";
|
||||
import ClipboardJS from "clipboard";
|
||||
import i18next from "i18next";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { addClipboardNotifications } from "../pageUtils.js";
|
||||
import { addClipboardNotifications } from "../pageUtils";
|
||||
import { makeElement } from "../htmlUtils";
|
||||
import ClipboardJS from "clipboard";
|
||||
import FileSaver from 'file-saver';
|
||||
|
|
|
@ -16,7 +16,7 @@ Prism.highlightAll();
|
|||
import {
|
||||
changePage,
|
||||
renderPage,
|
||||
} from "./pageUtils.js";
|
||||
} from "./pageUtils";
|
||||
import { getSealStatus } from "./api/getSealStatus";
|
||||
import { makeElement } from "./htmlUtils";
|
||||
import { pageState } from "./globalPageState.ts";
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import { Page } from "./types/Page";
|
||||
import { PageState } from "./PageState";
|
||||
import { getSealStatus } from "./api/getSealStatus";
|
||||
import { lookupSelf } from "./api/lookupSelf";
|
||||
import { makeElement } from "./htmlUtils";
|
||||
import { pageState } from "./globalPageState.ts";
|
||||
import { pageState } from "./globalPageState";
|
||||
import ClipboardJS from "clipboard";
|
||||
import UIkit from 'uikit/dist/js/uikit.min.js';
|
||||
import i18next from 'i18next';
|
||||
|
||||
|
@ -15,7 +18,7 @@ async function prePageChecksReal() {
|
|||
throw new Error("Vault URL Not Set");
|
||||
}
|
||||
|
||||
let sealStatus = await getSealStatus();
|
||||
const sealStatus = await getSealStatus();
|
||||
if (sealStatus.sealed) {
|
||||
changePage("UNSEAL");
|
||||
throw new Error("Vault Sealed");
|
||||
|
@ -29,7 +32,7 @@ async function prePageChecksReal() {
|
|||
}
|
||||
}
|
||||
|
||||
export async function prePageChecks() {
|
||||
export async function prePageChecks(): Promise<boolean> {
|
||||
try {
|
||||
await prePageChecksReal();
|
||||
} catch (e) {
|
||||
|
@ -41,15 +44,15 @@ export async function prePageChecks() {
|
|||
|
||||
|
||||
|
||||
export function addClipboardNotifications(clipboard, timeout = 1000) {
|
||||
export function addClipboardNotifications(clipboard: ClipboardJS, timeout = 1000): void {
|
||||
clipboard.on('success', _ => {
|
||||
UIkit.notification(i18next.t("notification_copy_success"), {
|
||||
(UIkit as any).notification(i18next.t("notification_copy_success"), {
|
||||
status: 'success',
|
||||
timeout: timeout
|
||||
});
|
||||
});
|
||||
clipboard.on('error', function (e) {
|
||||
UIkit.notification(i18next.t("notification_copy_error", {
|
||||
clipboard.on('error', function (e: Error) {
|
||||
(UIkit as any).notification(i18next.t("notification_copy_error", {
|
||||
"error": e.message
|
||||
}), {
|
||||
status: 'danger',
|
||||
|
@ -58,12 +61,12 @@ export function addClipboardNotifications(clipboard, timeout = 1000) {
|
|||
});
|
||||
}
|
||||
|
||||
export function setErrorText(text) {
|
||||
let errorTextElement = document.querySelector("#errorText");
|
||||
export function setErrorText(text: string): void {
|
||||
const errorTextElement = document.querySelector("#errorText");
|
||||
if (errorTextElement) {
|
||||
document.querySelector("#errorText").innerText = `Error: ${text}`;
|
||||
(document.querySelector("#errorText") as HTMLElement).innerText = `Error: ${text}`;
|
||||
}
|
||||
UIkit.notification({
|
||||
(UIkit as any).notification({
|
||||
message: `Error: ${text}`,
|
||||
status: 'danger',
|
||||
pos: 'top-center',
|
||||
|
@ -71,9 +74,9 @@ export function setErrorText(text) {
|
|||
});
|
||||
}
|
||||
|
||||
export function changePage(page, shouldSwitch = true) {
|
||||
export function changePage(page: string, shouldSwitch = true): void {
|
||||
if (pageState.currentPage && shouldSwitch) {
|
||||
pageState.currentPage.cleanup();
|
||||
(pageState.currentPage as Page).cleanup();
|
||||
}
|
||||
pageState.currentPage = page;
|
||||
if (shouldSwitch) {
|
||||
|
@ -81,19 +84,19 @@ export function changePage(page, shouldSwitch = true) {
|
|||
}
|
||||
}
|
||||
|
||||
export function renderPage() {
|
||||
export function renderPage(): void {
|
||||
document.documentElement.dir = pageState.pageDirection;
|
||||
console.log("Rendering Page: ", pageState.currentPage.name);
|
||||
document.querySelector("#pageContent").innerHTML = "";
|
||||
setPageTitle(pageState.currentPage.name);
|
||||
pageState.currentPage.render();
|
||||
console.log("Rendering Page: ", (pageState.currentPage as Page).name);
|
||||
(document.querySelector("#pageContent") as HTMLElement).innerHTML = "";
|
||||
setPageTitle((pageState.currentPage as Page).name);
|
||||
(pageState.currentPage as Page).render();
|
||||
}
|
||||
|
||||
export function setPageTitle(title) {
|
||||
let pageTitle = document.getElementById("pageTitle");
|
||||
export function setPageTitle(title: string | HTMLElement): void {
|
||||
const pageTitle = (document.getElementById("pageTitle") as HTMLElement);
|
||||
pageTitle.innerHTML = "";
|
||||
if (typeof title === "string" || title instanceof String) {
|
||||
pageTitle.innerText = title;
|
||||
if (typeof title === "string") {
|
||||
pageTitle.innerText = title.toString();
|
||||
} else {
|
||||
pageTitle.appendChild(title);
|
||||
}
|
||||
|
@ -101,13 +104,12 @@ export function setPageTitle(title) {
|
|||
|
||||
function currentTitleSecretText() {
|
||||
let currentSecretText = pageState.currentSecret;
|
||||
currentSecretText += pageState.currentPage.titleSuffix;
|
||||
|
||||
currentSecretText += (pageState.currentPage as Page).titleSuffix;
|
||||
if (pageState.currentSecretVersion !== null) currentSecretText += ` (v${pageState.currentSecretVersion})`;
|
||||
return currentSecretText;
|
||||
}
|
||||
|
||||
export function setTitleElement(pageState) {
|
||||
export function setTitleElement(pageState: PageState): void {
|
||||
const titleElement = makeElement({
|
||||
tag: "div",
|
||||
children: [
|
||||
|
@ -149,12 +151,11 @@ export function setTitleElement(pageState) {
|
|||
]
|
||||
});
|
||||
setPageTitle(titleElement);
|
||||
return titleElement;
|
||||
}
|
||||
|
||||
export function setPageContent(content) {
|
||||
let pageContent = document.getElementById("pageContent");
|
||||
if (typeof content === "string" || content instanceof String) {
|
||||
export function setPageContent(content: string | HTMLElement): void {
|
||||
const pageContent = (document.getElementById("pageContent") as HTMLElement);
|
||||
if (typeof content === "string") {
|
||||
pageContent.innerHTML = content;
|
||||
} else {
|
||||
pageContent.innerHTML = "";
|
|
@ -1,5 +1,5 @@
|
|||
import { Page } from "../types/Page.js";
|
||||
import { changePage, prePageChecks, setErrorText } from "../pageUtils.js";
|
||||
import { changePage, prePageChecks, setErrorText } from "../pageUtils";
|
||||
import { getMounts } from "../api/getMounts";
|
||||
import { lookupSelf } from "../api/lookupSelf";
|
||||
import { makeElement } from "../htmlUtils";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Page } from "../../types/Page.js";
|
||||
import { changePage, setPageContent, setTitleElement } from "../../pageUtils.js";
|
||||
import { changePage, setPageContent, setTitleElement } from "../../pageUtils";
|
||||
import { deleteSecret } from "../../api/deleteSecret";
|
||||
import { makeElement } from "../../htmlUtils";
|
||||
import { pageState } from "../../globalPageState.ts";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Page } from "../../types/Page.js";
|
||||
import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils.js";
|
||||
import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils";
|
||||
import { createOrUpdateSecret } from "../../api/createOrUpdateSecret";
|
||||
import { makeElement } from "../../htmlUtils";
|
||||
import { pageState } from "../../globalPageState.ts";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { CopyableInputBox } from "../../elements/CopyableInputBox.js";
|
||||
import { Page } from "../../types/Page.js";
|
||||
import { changePage, setPageContent, setTitleElement } from "../../pageUtils.js";
|
||||
import { changePage, setPageContent, setTitleElement } from "../../pageUtils";
|
||||
import { getCapabilities } from "../../api/getCapabilities";
|
||||
import { getSecret } from "../../api/getSecret";
|
||||
import { makeElement } from "../../htmlUtils";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { CodeJar } from "codejar";
|
||||
import { Page } from "../../types/Page.js";
|
||||
import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils.js";
|
||||
import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils";
|
||||
import { createOrUpdateSecret } from "../../api/createOrUpdateSecret.js";
|
||||
import { getSecret } from "../../api/getSecret.js";
|
||||
import { makeElement } from "../../htmlUtils";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Page } from "../../types/Page.js";
|
||||
import { changePage, setPageContent, setTitleElement } from "../../pageUtils.js";
|
||||
import { changePage, setPageContent, setTitleElement } from "../../pageUtils";
|
||||
import { getSecretMetadata } from "../../api/getSecretMetadata.js";
|
||||
import { makeElement } from "../../htmlUtils";
|
||||
import { objectToMap } from "../../utils";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { DoesNotExistError } from "../../types/internalErrors.js";
|
||||
import { Page } from "../../types/Page.js";
|
||||
import { changePage, setErrorText, setTitleElement } from "../../pageUtils.js";
|
||||
import { changePage, setErrorText, setTitleElement } from "../../pageUtils";
|
||||
import { getSecrets } from "../../api/getSecrets";
|
||||
import { makeElement } from "../../htmlUtils";
|
||||
import { pageState } from "../../globalPageState.ts";
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Margin } from "../elements/Margin.js";
|
||||
import { MarginInline } from "../elements/MarginInline.js";
|
||||
import { Page } from "../types/Page.js";
|
||||
import { changePage, setErrorText, setPageContent } from "../pageUtils.js";
|
||||
import { changePage, setErrorText, setPageContent } from "../pageUtils";
|
||||
import { lookupSelf } from "../api/lookupSelf";
|
||||
import { makeElement } from "../htmlUtils";
|
||||
import { pageState } from "../globalPageState.ts";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Page } from "../types/Page.js";
|
||||
import { addClipboardNotifications, changePage, prePageChecks, setErrorText, setPageContent } from "../pageUtils.js";
|
||||
import { addClipboardNotifications, changePage, prePageChecks, setErrorText, setPageContent } from "../pageUtils";
|
||||
import { getCapabilitiesPath } from "../api/getCapabilities.js";
|
||||
import { makeElement } from "../htmlUtils";
|
||||
import { pageState } from "../globalPageState.ts";
|
||||
|
|
|
@ -2,7 +2,7 @@ import { CopyableInputBox } from "../elements/CopyableInputBox.js";
|
|||
import { Margin } from "../elements/Margin.js";
|
||||
import { Page } from "../types/Page.js";
|
||||
import { makeElement } from "../htmlUtils";
|
||||
import { setPageContent } from "../pageUtils.js";
|
||||
import { setPageContent } from "../pageUtils";
|
||||
import i18next from 'i18next';
|
||||
|
||||
const passwordLengthMin = 1;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Margin } from "../elements/Margin.js";
|
||||
import { Page } from "../types/Page.js";
|
||||
import { changePage, setPageContent } from "../pageUtils.js";
|
||||
import { changePage, setPageContent } from "../pageUtils";
|
||||
import { makeElement } from "../htmlUtils";
|
||||
import { pageState } from "../globalPageState.ts";
|
||||
import i18next from 'i18next';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Page } from "../types/Page.js";
|
||||
import { changePage, setPageContent } from "../pageUtils.js";
|
||||
import { changePage, setPageContent } from "../pageUtils";
|
||||
import { makeElement } from "../htmlUtils";
|
||||
import { pageState } from "../globalPageState.ts";
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import { Margin } from "../../elements/Margin.js";
|
|||
import { MarginInline } from "../../elements/MarginInline.js";
|
||||
import { Page } from "../../types/Page.js";
|
||||
import { addNewTOTP } from "../../api/addNewTOTP";
|
||||
import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils.js";
|
||||
import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils";
|
||||
import { makeElement } from "../../htmlUtils";
|
||||
import { pageState } from "../../globalPageState.ts";
|
||||
import i18next from 'i18next';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { CopyableInputBox } from "../../elements/CopyableInputBox.js";
|
||||
import { DoesNotExistError } from "../../types/internalErrors.js";
|
||||
import { Page } from "../../types/Page.js";
|
||||
import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils.js";
|
||||
import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils";
|
||||
import { getTOTPCode } from "../../api/getTOTPCode";
|
||||
import { getTOTPKeys } from "../../api/getTOTPKeys";
|
||||
import { makeElement } from "../../htmlUtils";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Page } from "../types/Page.js";
|
||||
import { changePage, setPageContent, setTitleElement } from "../pageUtils.js";
|
||||
import { changePage, setPageContent, setTitleElement } from "../pageUtils";
|
||||
import { makeElement } from "../htmlUtils";
|
||||
import { pageState } from "../globalPageState.ts";
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { CopyableModal } from "../../elements/CopyableModal.js";
|
||||
import { Margin } from "../../elements/Margin.js";
|
||||
import { Page } from "../../types/Page.js";
|
||||
import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils.js";
|
||||
import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils";
|
||||
import { makeElement } from "../../htmlUtils";
|
||||
import { pageState } from "../../globalPageState.ts";
|
||||
import { transitDecrypt } from "../../api/transitDecrypt";
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { CopyableModal } from "../../elements/CopyableModal.js";
|
||||
import { Margin } from "../../elements/Margin.js";
|
||||
import { Page } from "../../types/Page.js";
|
||||
import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils.js";
|
||||
import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils";
|
||||
import { makeElement } from "../../htmlUtils";
|
||||
import { pageState } from "../../globalPageState.ts";
|
||||
import { transitEncrypt } from "../../api/transitEncrypt";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { DoesNotExistError } from "../../types/internalErrors.js";
|
||||
import { Page } from "../../types/Page.js";
|
||||
import { changePage, setErrorText, setTitleElement } from "../../pageUtils.js";
|
||||
import { changePage, setErrorText, setTitleElement } from "../../pageUtils";
|
||||
import { getTransitKeys } from "../../api/getTransitKeys";
|
||||
import { makeElement } from "../../htmlUtils";
|
||||
import { pageState } from "../../globalPageState.ts";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Page } from "../../types/Page.js";
|
||||
import { changePage, setPageContent, setTitleElement } from "../../pageUtils.js";
|
||||
import { changePage, setPageContent, setTitleElement } from "../../pageUtils";
|
||||
import { makeElement } from "../../htmlUtils";
|
||||
import { pageState } from "../../globalPageState.ts";
|
||||
import i18next from 'i18next';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { MarginInline } from "../elements/MarginInline.js";
|
||||
import { Page } from "../types/Page.js";
|
||||
import { QRScanner } from "../elements/QRScanner.js";
|
||||
import { changePage, setErrorText, setPageContent } from "../pageUtils.js";
|
||||
import { changePage, setErrorText, setPageContent } from "../pageUtils";
|
||||
import { getSealStatus } from "../api/getSealStatus.js";
|
||||
import { makeElement } from "../htmlUtils";
|
||||
import { submitUnsealKey } from "../api/submitUnsealKey.js";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { changePage } from "../pageUtils.js";
|
||||
import { changePage } from "../pageUtils";
|
||||
|
||||
export class Page {
|
||||
constructor() {
|
||||
|
|
Loading…
Reference in a new issue