1
0
Fork 0

Move makeElement to z-makeelement library.

This commit is contained in:
Kitteh 2021-05-16 18:17:12 +01:00
parent c71f3f26a8
commit c71e530f3f
39 changed files with 40 additions and 104 deletions

View file

@ -39,6 +39,7 @@
"webpack": "^5.37.0", "webpack": "^5.37.0",
"webpack-cli": "^4.7.0", "webpack-cli": "^4.7.0",
"webpack-dev-server": "^3.11.2", "webpack-dev-server": "^3.11.2",
"z-makeelement": "^1.0.1",
"z-pagerouter": "^1.0.1" "z-pagerouter": "^1.0.1"
} }
} }

View file

@ -1,6 +1,6 @@
import { MarginInline } from "./MarginInline"; import { MarginInline } from "./MarginInline";
import { addClipboardNotifications } from "../pageUtils"; import { addClipboardNotifications } from "../pageUtils";
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
import ClipboardJS from "clipboard"; import ClipboardJS from "clipboard";
import i18next from "i18next"; import i18next from "i18next";

View file

@ -1,5 +1,5 @@
import { addClipboardNotifications } from "../pageUtils"; import { addClipboardNotifications } from "../pageUtils";
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
import ClipboardJS from "clipboard"; import ClipboardJS from "clipboard";
import FileSaver from "file-saver"; import FileSaver from "file-saver";
import UIkit from "uikit"; import UIkit from "uikit";

View file

@ -1,4 +1,4 @@
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
import i18next from "i18next"; import i18next from "i18next";
export function FileUploadInput(name: string): Element { export function FileUploadInput(name: string): Element {

View file

@ -1,4 +1,4 @@
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
export function ListItem(children: Element[] | Element): HTMLElement { export function ListItem(children: Element[] | Element): HTMLElement {
return makeElement({ return makeElement({

View file

@ -1,4 +1,4 @@
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
export function Margin(children: Element | Element[]): Element { export function Margin(children: Element | Element[]): Element {
return makeElement({ return makeElement({

View file

@ -1,4 +1,4 @@
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
export function MarginInline(children: Element | Element[]): Element { export function MarginInline(children: Element | Element[]): Element {
return makeElement({ return makeElement({

View file

@ -1,6 +1,6 @@
import { ListItem } from "./ListItem"; import { ListItem } from "./ListItem";
import { PageRouter } from "z-pagerouter"; import { PageRouter } from "z-pagerouter";
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
import i18next from "i18next"; import i18next from "i18next";
export function NavBar(router: PageRouter): HTMLElement { export function NavBar(router: PageRouter): HTMLElement {

View file

@ -1,4 +1,4 @@
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
export function Option(label: string, value: string): HTMLElement { export function Option(label: string, value: string): HTMLElement {
return makeElement({ return makeElement({

View file

@ -1,5 +1,5 @@
import { Margin } from "./Margin"; import { Margin } from "./Margin";
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
import QrScanner from "qr-scanner"; import QrScanner from "qr-scanner";
/* eslint-disable import/no-unresolved */ /* eslint-disable import/no-unresolved */

View file

@ -1,6 +1,6 @@
import { PageRouter } from "z-pagerouter"; import { PageRouter } from "z-pagerouter";
import { PageState } from "../PageState"; import { PageState } from "../PageState";
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
function currentTitleSecretText(state: PageState, suffix = ""): string { function currentTitleSecretText(state: PageState, suffix = ""): string {
let currentSecretText = state.currentSecret; let currentSecretText = state.currentSecret;

View file

@ -1,4 +1,4 @@
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
type TileParams = { type TileParams = {
condition?: boolean; condition?: boolean;

View file

@ -1,70 +1,3 @@
import { getObjectKeys } from "./utils";
type optionsFunctionsObject = {
[key: string]: (e: Element, arg: unknown) => void;
};
const optionsFunctions: optionsFunctionsObject = {
class: (e: Element, arg: string | string[]) => {
if (!Array.isArray(arg)) {
arg = String(arg).split(" ");
}
e.classList.add(...arg);
},
id: (e: Element, arg: string) => (e.id = arg),
html: (e: Element, arg: string) => (e.innerHTML = arg),
onclick: (e: Element, arg: () => void) => ((e as HTMLButtonElement).onclick = arg),
attributes: setElementAttributes,
text: (e: Element, arg: string) => ((e as HTMLParagraphElement).innerText = arg),
children: (e: Element, arg: Element | Element[]) => {
if (Array.isArray(arg)) {
arg.forEach((child) => {
if (child != null) e.appendChild(child);
});
} else {
if (arg != null) e.appendChild(arg);
}
},
thenRun: (e: Element, arg: (e: Element) => void) => arg(e),
};
interface ElementInfo {
condition?: boolean;
tag: string;
class?: string | string[];
id?: string;
html?: string;
attributes?: Record<string, string>;
children?: Element | Element[];
text?: string;
thenRun?: (e: Element) => void;
onclick?: () => void;
[propName: string]: unknown;
}
export function makeElement(elementInfo: ElementInfo): HTMLElement {
if ("condition" in elementInfo) {
if (!elementInfo.condition) {
return null;
}
}
const element = document.createElement(elementInfo.tag);
for (const key of Object.getOwnPropertyNames(elementInfo)) {
if (getObjectKeys(optionsFunctions).includes(key)) {
optionsFunctions[key](element, elementInfo[key]);
}
}
return element;
}
export function setElementAttributes(element: Element, attributes: Record<string, string>): void {
for (const key of Object.getOwnPropertyNames(attributes)) {
element.setAttribute(key, attributes[key]);
}
}
export const fileToBase64 = (file: File): Promise<string> => export const fileToBase64 = (file: File): Promise<string> =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const reader = new FileReader(); const reader = new FileReader();

View file

@ -23,7 +23,7 @@ import { NavBar } from "./elements/NavBar";
import { PageRouter } from "z-pagerouter"; import { PageRouter } from "z-pagerouter";
import { formatDistance } from "./formatDistance"; import { formatDistance } from "./formatDistance";
import { getSealStatus } from "./api/sys/getSealStatus"; import { getSealStatus } from "./api/sys/getSealStatus";
import { makeElement } from "./htmlUtils"; import { makeElement } from "z-makeelement";
import { pageList } from "./allPages"; import { pageList } from "./allPages";
import { pageState } from "./globalPageState"; import { pageState } from "./globalPageState";
import { playground } from "./playground"; import { playground } from "./playground";

View file

@ -2,7 +2,7 @@ import { MountType, getMounts } from "../api/sys/getMounts";
import { Page } from "../types/Page"; import { Page } from "../types/Page";
import { getCapabilitiesPath } from "../api/sys/getCapabilities"; import { getCapabilitiesPath } from "../api/sys/getCapabilities";
import { lookupSelf } from "../api/sys/lookupSelf"; import { lookupSelf } from "../api/sys/lookupSelf";
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
import { prePageChecks, setErrorText } from "../pageUtils"; import { prePageChecks, setErrorText } from "../pageUtils";
import { sortedObjectMap } from "../utils"; import { sortedObjectMap } from "../utils";
import i18next from "i18next"; import i18next from "i18next";

View file

@ -1,7 +1,7 @@
import { Page } from "../../types/Page"; import { Page } from "../../types/Page";
import { SecretTitleElement } from "../../elements/SecretTitleElement"; import { SecretTitleElement } from "../../elements/SecretTitleElement";
import { deleteSecret } from "../../api/kv/deleteSecret"; import { deleteSecret } from "../../api/kv/deleteSecret";
import { makeElement } from "../../htmlUtils"; import { makeElement } from "z-makeelement";
import i18next from "i18next"; import i18next from "i18next";
export class KeyValueDeletePage extends Page { export class KeyValueDeletePage extends Page {

View file

@ -1,7 +1,7 @@
import { Page } from "../../types/Page"; import { Page } from "../../types/Page";
import { SecretTitleElement } from "../../elements/SecretTitleElement"; import { SecretTitleElement } from "../../elements/SecretTitleElement";
import { createOrUpdateSecret } from "../../api/kv/createOrUpdateSecret"; import { createOrUpdateSecret } from "../../api/kv/createOrUpdateSecret";
import { makeElement } from "../../htmlUtils"; import { makeElement } from "z-makeelement";
import { setErrorText } from "../../pageUtils"; import { setErrorText } from "../../pageUtils";
import i18next from "i18next"; import i18next from "i18next";

View file

@ -3,7 +3,7 @@ import { Page } from "../../types/Page";
import { SecretTitleElement } from "../../elements/SecretTitleElement"; import { SecretTitleElement } from "../../elements/SecretTitleElement";
import { getCapabilities } from "../../api/sys/getCapabilities"; import { getCapabilities } from "../../api/sys/getCapabilities";
import { getSecret } from "../../api/kv/getSecret"; import { getSecret } from "../../api/kv/getSecret";
import { makeElement } from "../../htmlUtils"; import { makeElement } from "z-makeelement";
import { sortedObjectMap } from "../../utils"; import { sortedObjectMap } from "../../utils";
import { undeleteSecret } from "../../api/kv/undeleteSecret"; import { undeleteSecret } from "../../api/kv/undeleteSecret";
import Prism from "prismjs"; import Prism from "prismjs";

View file

@ -3,7 +3,7 @@ import { Page } from "../../types/Page";
import { SecretTitleElement } from "../../elements/SecretTitleElement"; import { SecretTitleElement } from "../../elements/SecretTitleElement";
import { createOrUpdateSecret } from "../../api/kv/createOrUpdateSecret"; import { createOrUpdateSecret } from "../../api/kv/createOrUpdateSecret";
import { getSecret } from "../../api/kv/getSecret"; import { getSecret } from "../../api/kv/getSecret";
import { makeElement } from "../../htmlUtils"; import { makeElement } from "z-makeelement";
import { setErrorText } from "../../pageUtils"; import { setErrorText } from "../../pageUtils";
import { sortedObjectMap, verifyJSONString } from "../../utils"; import { sortedObjectMap, verifyJSONString } from "../../utils";
import i18next from "i18next"; import i18next from "i18next";

View file

@ -1,7 +1,7 @@
import { Page } from "../../types/Page"; import { Page } from "../../types/Page";
import { SecretTitleElement } from "../../elements/SecretTitleElement"; import { SecretTitleElement } from "../../elements/SecretTitleElement";
import { getSecretMetadata } from "../../api/kv/getSecretMetadata"; import { getSecretMetadata } from "../../api/kv/getSecretMetadata";
import { makeElement } from "../../htmlUtils"; import { makeElement } from "z-makeelement";
import { objectToMap } from "../../utils"; import { objectToMap } from "../../utils";
import i18next from "i18next"; import i18next from "i18next";

View file

@ -2,7 +2,7 @@ import { DoesNotExistError } from "../../types/internalErrors";
import { Page } from "../../types/Page"; import { Page } from "../../types/Page";
import { SecretTitleElement } from "../../elements/SecretTitleElement"; import { SecretTitleElement } from "../../elements/SecretTitleElement";
import { getSecrets } from "../../api/kv/getSecrets"; import { getSecrets } from "../../api/kv/getSecrets";
import { makeElement } from "../../htmlUtils"; import { makeElement } from "z-makeelement";
import { setErrorText } from "../../pageUtils"; import { setErrorText } from "../../pageUtils";
import i18next from "i18next"; import i18next from "i18next";

View file

@ -2,7 +2,7 @@ import { Margin } from "../elements/Margin";
import { MarginInline } from "../elements/MarginInline"; import { MarginInline } from "../elements/MarginInline";
import { Page } from "../types/Page"; import { Page } from "../types/Page";
import { lookupSelf } from "../api/sys/lookupSelf"; import { lookupSelf } from "../api/sys/lookupSelf";
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
import { setErrorText } from "../pageUtils"; import { setErrorText } from "../pageUtils";
import { usernameLogin } from "../api/auth/usernameLogin"; import { usernameLogin } from "../api/auth/usernameLogin";
import i18next from "i18next"; import i18next from "i18next";

View file

@ -1,7 +1,7 @@
import { Page } from "../types/Page"; import { Page } from "../types/Page";
import { addClipboardNotifications, prePageChecks, setErrorText } from "../pageUtils"; import { addClipboardNotifications, prePageChecks, setErrorText } from "../pageUtils";
import { getCapabilitiesPath } from "../api/sys/getCapabilities"; import { getCapabilitiesPath } from "../api/sys/getCapabilities";
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
import { renewSelf } from "../api/sys/renewSelf"; import { renewSelf } from "../api/sys/renewSelf";
import { sealVault } from "../api/sys/sealVault"; import { sealVault } from "../api/sys/sealVault";
import ClipboardJS from "clipboard"; import ClipboardJS from "clipboard";

View file

@ -1,7 +1,7 @@
import { Margin } from "../../elements/Margin"; import { Margin } from "../../elements/Margin";
import { Option } from "../../elements/Option"; import { Option } from "../../elements/Option";
import { Page } from "../../types/Page"; import { Page } from "../../types/Page";
import { makeElement } from "../../htmlUtils"; import { makeElement } from "z-makeelement";
import { newMount } from "../../api/sys/newMount"; import { newMount } from "../../api/sys/newMount";
import { setErrorText } from "../../pageUtils"; import { setErrorText } from "../../pageUtils";
import i18next from "i18next"; import i18next from "i18next";

View file

@ -1,6 +1,6 @@
import { Margin } from "../../elements/Margin"; import { Margin } from "../../elements/Margin";
import { Page } from "../../types/Page"; import { Page } from "../../types/Page";
import { makeElement } from "../../htmlUtils"; import { makeElement } from "z-makeelement";
import { newMount } from "../../api/sys/newMount"; import { newMount } from "../../api/sys/newMount";
import { setErrorText } from "../../pageUtils"; import { setErrorText } from "../../pageUtils";
import i18next from "i18next"; import i18next from "i18next";

View file

@ -1,6 +1,6 @@
import { Margin } from "../../elements/Margin"; import { Margin } from "../../elements/Margin";
import { Page } from "../../types/Page"; import { Page } from "../../types/Page";
import { makeElement } from "../../htmlUtils"; import { makeElement } from "z-makeelement";
import { newMount } from "../../api/sys/newMount"; import { newMount } from "../../api/sys/newMount";
import { setErrorText } from "../../pageUtils"; import { setErrorText } from "../../pageUtils";
import i18next from "i18next"; import i18next from "i18next";

View file

@ -1,6 +1,6 @@
import { Page } from "../types/Page"; import { Page } from "../types/Page";
import { Tile } from "../elements/Tile"; import { Tile } from "../elements/Tile";
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
import i18next from "i18next"; import i18next from "i18next";
export class NewSecretsEnginePage extends Page { export class NewSecretsEnginePage extends Page {

View file

@ -2,7 +2,7 @@ import { CopyableInputBox, CopyableInputBoxType } from "../elements/CopyableInpu
import { Margin } from "../elements/Margin"; import { Margin } from "../elements/Margin";
import { Option } from "../elements/Option"; import { Option } from "../elements/Option";
import { Page } from "../types/Page"; import { Page } from "../types/Page";
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
import i18next from "i18next"; import i18next from "i18next";
const passwordLengthMin = 1; const passwordLengthMin = 1;

View file

@ -1,6 +1,6 @@
import { Margin } from "../elements/Margin"; import { Margin } from "../elements/Margin";
import { Page } from "../types/Page"; import { Page } from "../types/Page";
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
import { reloadNavBar } from "../elements/NavBar"; import { reloadNavBar } from "../elements/NavBar";
import i18next from "i18next"; import i18next from "i18next";

View file

@ -1,5 +1,5 @@
import { Page } from "../types/Page"; import { Page } from "../types/Page";
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
export class SetVaultURLPage extends Page { export class SetVaultURLPage extends Page {
constructor() { constructor() {

View file

@ -3,7 +3,7 @@ import { MarginInline } from "../../elements/MarginInline";
import { Page } from "../../types/Page"; import { Page } from "../../types/Page";
import { SecretTitleElement } from "../../elements/SecretTitleElement"; import { SecretTitleElement } from "../../elements/SecretTitleElement";
import { addNewTOTP } from "../../api/totp/addNewTOTP"; import { addNewTOTP } from "../../api/totp/addNewTOTP";
import { makeElement } from "../../htmlUtils"; import { makeElement } from "z-makeelement";
import { setErrorText } from "../../pageUtils"; import { setErrorText } from "../../pageUtils";
import i18next from "i18next"; import i18next from "i18next";

View file

@ -4,7 +4,7 @@ import { Page } from "../../types/Page";
import { SecretTitleElement } from "../../elements/SecretTitleElement"; import { SecretTitleElement } from "../../elements/SecretTitleElement";
import { getTOTPCode } from "../../api/totp/getTOTPCode"; import { getTOTPCode } from "../../api/totp/getTOTPCode";
import { getTOTPKeys } from "../../api/totp/getTOTPKeys"; import { getTOTPKeys } from "../../api/totp/getTOTPKeys";
import { makeElement } from "../../htmlUtils"; import { makeElement } from "z-makeelement";
import { objectToMap } from "../../utils"; import { objectToMap } from "../../utils";
import { setErrorText } from "../../pageUtils"; import { setErrorText } from "../../pageUtils";
import i18next from "i18next"; import i18next from "i18next";

View file

@ -2,7 +2,7 @@ import { Margin } from "../../elements/Margin";
import { Option } from "../../elements/Option"; import { Option } from "../../elements/Option";
import { Page } from "../../types/Page"; import { Page } from "../../types/Page";
import { SecretTitleElement } from "../../elements/SecretTitleElement"; import { SecretTitleElement } from "../../elements/SecretTitleElement";
import { makeElement } from "../../htmlUtils"; import { makeElement } from "z-makeelement";
import { newTransitKey } from "../../api/transit/newTransitKey"; import { newTransitKey } from "../../api/transit/newTransitKey";
import { setErrorText } from "../../pageUtils"; import { setErrorText } from "../../pageUtils";
import i18next from "i18next"; import i18next from "i18next";

View file

@ -3,7 +3,8 @@ import { FileUploadInput } from "../../elements/FileUploadInput";
import { Margin } from "../../elements/Margin"; import { Margin } from "../../elements/Margin";
import { Page } from "../../types/Page"; import { Page } from "../../types/Page";
import { SecretTitleElement } from "../../elements/SecretTitleElement"; import { SecretTitleElement } from "../../elements/SecretTitleElement";
import { fileToBase64, makeElement } from "../../htmlUtils"; import { fileToBase64 } from "../../htmlUtils";
import { makeElement } from "z-makeelement";
import { setErrorText } from "../../pageUtils"; import { setErrorText } from "../../pageUtils";
import { transitDecrypt } from "../../api/transit/transitDecrypt"; import { transitDecrypt } from "../../api/transit/transitDecrypt";
import i18next from "i18next"; import i18next from "i18next";

View file

@ -3,7 +3,8 @@ import { FileUploadInput } from "../../elements/FileUploadInput";
import { Margin } from "../../elements/Margin"; import { Margin } from "../../elements/Margin";
import { Page } from "../../types/Page"; import { Page } from "../../types/Page";
import { SecretTitleElement } from "../../elements/SecretTitleElement"; import { SecretTitleElement } from "../../elements/SecretTitleElement";
import { fileToBase64, makeElement } from "../../htmlUtils"; import { fileToBase64 } from "../../htmlUtils";
import { makeElement } from "z-makeelement";
import { setErrorText } from "../../pageUtils"; import { setErrorText } from "../../pageUtils";
import { transitEncrypt } from "../../api/transit/transitEncrypt"; import { transitEncrypt } from "../../api/transit/transitEncrypt";
import i18next from "i18next"; import i18next from "i18next";

View file

@ -4,7 +4,7 @@ import { Option } from "../../elements/Option";
import { Page } from "../../types/Page"; import { Page } from "../../types/Page";
import { SecretTitleElement } from "../../elements/SecretTitleElement"; import { SecretTitleElement } from "../../elements/SecretTitleElement";
import { getTransitKey } from "../../api/transit/getTransitKey"; import { getTransitKey } from "../../api/transit/getTransitKey";
import { makeElement } from "../../htmlUtils"; import { makeElement } from "z-makeelement";
import { objectToMap } from "../../utils"; import { objectToMap } from "../../utils";
import { setErrorText } from "../../pageUtils"; import { setErrorText } from "../../pageUtils";
import { transitRewrap } from "../../api/transit/transitRewrap"; import { transitRewrap } from "../../api/transit/transitRewrap";

View file

@ -2,7 +2,7 @@ import { DoesNotExistError } from "../../types/internalErrors";
import { Page } from "../../types/Page"; import { Page } from "../../types/Page";
import { SecretTitleElement } from "../../elements/SecretTitleElement"; import { SecretTitleElement } from "../../elements/SecretTitleElement";
import { getTransitKeys } from "../../api/transit/getTransitKeys"; import { getTransitKeys } from "../../api/transit/getTransitKeys";
import { makeElement } from "../../htmlUtils"; import { makeElement } from "z-makeelement";
import { setErrorText } from "../../pageUtils"; import { setErrorText } from "../../pageUtils";
import i18next from "i18next"; import i18next from "i18next";

View file

@ -2,7 +2,7 @@ import { Page } from "../../types/Page";
import { SecretTitleElement } from "../../elements/SecretTitleElement"; import { SecretTitleElement } from "../../elements/SecretTitleElement";
import { Tile } from "../../elements/Tile"; import { Tile } from "../../elements/Tile";
import { getTransitKey } from "../../api/transit/getTransitKey"; import { getTransitKey } from "../../api/transit/getTransitKey";
import { makeElement } from "../../htmlUtils"; import { makeElement } from "z-makeelement";
import i18next from "i18next"; import i18next from "i18next";
export class TransitViewSecretPage extends Page { export class TransitViewSecretPage extends Page {

View file

@ -2,7 +2,7 @@ import { MarginInline } from "../elements/MarginInline";
import { Page } from "../types/Page"; import { Page } from "../types/Page";
import { QRScanner, QRScannerType } from "../elements/QRScanner"; import { QRScanner, QRScannerType } from "../elements/QRScanner";
import { SealStatusType, getSealStatus } from "../api/sys/getSealStatus"; import { SealStatusType, getSealStatus } from "../api/sys/getSealStatus";
import { makeElement } from "../htmlUtils"; import { makeElement } from "z-makeelement";
import { setErrorText } from "../pageUtils"; import { setErrorText } from "../pageUtils";
import { submitUnsealKey } from "../api/sys/submitUnsealKey"; import { submitUnsealKey } from "../api/sys/submitUnsealKey";
import i18next from "i18next"; import i18next from "i18next";