feat(web): update frontend TypeScript modules and API types
This commit updates the web frontend TypeScript modules: Core modules: - admin.ts: Admin panel functionality and user management - analytics.ts: Analytics dashboard and data visualization - api-explorer.ts: Interactive API documentation explorer - api.ts: Core API client with request/response handling - collections.ts: Book collection management UI - conflicts.ts: Sync conflict resolution interface - custom-section-builder.ts: Dynamic section builder for UI - docs.ts: Documentation viewer and navigation - dom.ts: DOM manipulation utilities and helpers - header.ts: Application header with navigation - library.ts: Library view and book grid management - linking.ts: Device-book linking interface - password_validation.ts: Client-side password strength validation - queue.ts: Device sync queue management UI - search.ts: Full-text search with Lunr integration - storage.ts: Local storage and cache management - theme.ts: Theme management and CSS variable updates - themeDropdown.ts: Theme selector dropdown component - toast.ts: Toast notification system - woodPaneling.ts: Visual theme effects - woodPanelingInit.ts: Visual effects initialization Type definitions: - api.d.ts: Updated TypeScript definitions for API responses These updates enhance the frontend with improved functionality for book management, device synchronization, and user experience.
This commit is contained in:
+85
-85
@@ -1,137 +1,137 @@
|
||||
function escapeHtml(text: string): string {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
const div = document.createElement("div");
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
function querySelector<T extends Element>(selector: string): T | null {
|
||||
return document.querySelector<T>(selector);
|
||||
return document.querySelector<T>(selector);
|
||||
}
|
||||
|
||||
function querySelectorAll<T extends Element>(selector: string): NodeListOf<T> {
|
||||
return document.querySelectorAll<T>(selector);
|
||||
return document.querySelectorAll<T>(selector);
|
||||
}
|
||||
|
||||
function getElementById<T extends HTMLElement>(id: string): T | null {
|
||||
return document.getElementById(id) as T | null;
|
||||
return document.getElementById(id) as T | null;
|
||||
}
|
||||
|
||||
function createElement<K extends keyof HTMLElementTagNameMap>(
|
||||
tagName: K,
|
||||
attributes?: Record<string, string>,
|
||||
children?: (string | Node)[]
|
||||
tagName: K,
|
||||
attributes?: Record<string, string>,
|
||||
children?: (string | Node)[],
|
||||
): HTMLElementTagNameMap[K] {
|
||||
const element = document.createElement(tagName);
|
||||
const element = document.createElement(tagName);
|
||||
|
||||
if (attributes) {
|
||||
Object.entries(attributes).forEach(([key, value]) => {
|
||||
if (key === 'className') {
|
||||
element.className = value;
|
||||
} else if (key === 'dataset') {
|
||||
Object.entries(JSON.parse(value)).forEach(([dataKey, dataValue]) => {
|
||||
element.dataset[dataKey] = String(dataValue);
|
||||
});
|
||||
} else {
|
||||
element.setAttribute(key, value);
|
||||
}
|
||||
if (attributes) {
|
||||
Object.entries(attributes).forEach(([key, value]) => {
|
||||
if (key === "className") {
|
||||
element.className = value;
|
||||
} else if (key === "dataset") {
|
||||
Object.entries(JSON.parse(value)).forEach(([dataKey, dataValue]) => {
|
||||
element.dataset[dataKey] = String(dataValue);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
element.setAttribute(key, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (children) {
|
||||
children.forEach(child => {
|
||||
if (typeof child === 'string') {
|
||||
element.appendChild(document.createTextNode(child));
|
||||
} else {
|
||||
element.appendChild(child);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (children) {
|
||||
children.forEach((child) => {
|
||||
if (typeof child === "string") {
|
||||
element.appendChild(document.createTextNode(child));
|
||||
} else {
|
||||
element.appendChild(child);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return element;
|
||||
return element;
|
||||
}
|
||||
|
||||
function showElement(element: HTMLElement | null): void {
|
||||
if (element) {
|
||||
element.classList.remove('hidden');
|
||||
}
|
||||
if (element) {
|
||||
element.classList.remove("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
function hideElement(element: HTMLElement | null): void {
|
||||
if (element) {
|
||||
element.classList.add('hidden');
|
||||
}
|
||||
if (element) {
|
||||
element.classList.add("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
function toggleElement(element: HTMLElement | null): void {
|
||||
if (element) {
|
||||
element.classList.toggle('hidden');
|
||||
}
|
||||
if (element) {
|
||||
element.classList.toggle("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
function setTextContent(element: HTMLElement | null, text: string): void {
|
||||
if (element) {
|
||||
element.textContent = text;
|
||||
}
|
||||
if (element) {
|
||||
element.textContent = text;
|
||||
}
|
||||
}
|
||||
|
||||
function setInnerHTML(element: HTMLElement | null, html: string): void {
|
||||
if (element) {
|
||||
element.innerHTML = html;
|
||||
}
|
||||
if (element) {
|
||||
element.innerHTML = html;
|
||||
}
|
||||
}
|
||||
|
||||
function addClass(element: HTMLElement | null, className: string): void {
|
||||
if (element) {
|
||||
element.classList.add(className);
|
||||
}
|
||||
if (element) {
|
||||
element.classList.add(className);
|
||||
}
|
||||
}
|
||||
|
||||
function removeClass(element: HTMLElement | null, className: string): void {
|
||||
if (element) {
|
||||
element.classList.remove(className);
|
||||
}
|
||||
if (element) {
|
||||
element.classList.remove(className);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleClass(element: HTMLElement | null, className: string): void {
|
||||
if (element) {
|
||||
element.classList.toggle(className);
|
||||
}
|
||||
if (element) {
|
||||
element.classList.toggle(className);
|
||||
}
|
||||
}
|
||||
|
||||
function hasClass(element: HTMLElement | null, className: string): boolean {
|
||||
return element ? element.classList.contains(className) : false;
|
||||
return element ? element.classList.contains(className) : false;
|
||||
}
|
||||
|
||||
(window as any).dom = {
|
||||
escapeHtml,
|
||||
querySelector,
|
||||
querySelectorAll,
|
||||
getElementById,
|
||||
createElement,
|
||||
showElement,
|
||||
hideElement,
|
||||
toggleElement,
|
||||
setTextContent,
|
||||
setInnerHTML,
|
||||
addClass,
|
||||
removeClass,
|
||||
toggleClass,
|
||||
hasClass
|
||||
escapeHtml,
|
||||
querySelector,
|
||||
querySelectorAll,
|
||||
getElementById,
|
||||
createElement,
|
||||
showElement,
|
||||
hideElement,
|
||||
toggleElement,
|
||||
setTextContent,
|
||||
setInnerHTML,
|
||||
addClass,
|
||||
removeClass,
|
||||
toggleClass,
|
||||
hasClass,
|
||||
};
|
||||
|
||||
export {
|
||||
escapeHtml,
|
||||
querySelector,
|
||||
querySelectorAll,
|
||||
getElementById,
|
||||
createElement,
|
||||
showElement,
|
||||
hideElement,
|
||||
toggleElement,
|
||||
setTextContent,
|
||||
setInnerHTML,
|
||||
addClass,
|
||||
removeClass,
|
||||
toggleClass,
|
||||
hasClass
|
||||
escapeHtml,
|
||||
querySelector,
|
||||
querySelectorAll,
|
||||
getElementById,
|
||||
createElement,
|
||||
showElement,
|
||||
hideElement,
|
||||
toggleElement,
|
||||
setTextContent,
|
||||
setInnerHTML,
|
||||
addClass,
|
||||
removeClass,
|
||||
toggleClass,
|
||||
hasClass,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user