commit e07ea9d407467d7987f8afa732a2972c08a4bf18
parent e50cc29313201e637ae403dbad6afe2eeaeac564
Author: triesap <137732411+triesap@users.noreply.github.com>
Date: Fri, 15 Nov 2024 00:48:35 +0000
apps-lib: add/edit document utils, locales, routes
Diffstat:
5 files changed, 35 insertions(+), 10 deletions(-)
diff --git a/apps-lib/src/lib/index.ts b/apps-lib/src/lib/index.ts
@@ -25,8 +25,8 @@ export { default as FillWhite } from "./el/fill_white.svelte";
export * from "./stores/ndk";
export * from "./stores/client";
export * from "./utils/routes";
-export * from "./utils/dom";
export * from "./utils/styles";
+export * from "./utils/document";
export * from "./utils/carousel";
export * from "./utils/numbers";
export * from "./utils/client";
diff --git a/apps-lib/src/lib/locales/en/common.json b/apps-lib/src/lib/locales/en/common.json
@@ -12,6 +12,7 @@
"authenticated": "Authenticated",
"available_balance": "Available balance",
"back": "Back",
+ "bag": "Bag",
"bags": "Bags",
"bank_account": "Bank account",
"business_name": "Business name",
@@ -45,6 +46,7 @@
"from": "From",
"hex": "Hex",
"highest_price": "Highest price",
+ "home": "Home",
"inbox": "Inbox",
"inflows": "Inflows",
"items": "Items",
@@ -127,6 +129,7 @@
"update": "Update",
"url": "URL",
"value": "Value",
+ "view": "View",
"wallet": "Wallet",
"website": "Website",
"year": "Year",
diff --git a/apps-lib/src/lib/utils/document.ts b/apps-lib/src/lib/utils/document.ts
@@ -0,0 +1,29 @@
+export const el_id = (id: string): HTMLElement | undefined => {
+ const el = document.getElementById(id);
+ return el ? el : undefined;
+};
+
+export const el_toggle = (id: string, toggle_class: string): void => {
+ const el = document.getElementById(id);
+ if (el) el.classList.toggle(toggle_class);
+};
+
+export const els_id_pref = (id_pref: string): Element[] | undefined => {
+ const els = document.querySelectorAll(`[id^="${id_pref}"]`);
+ if (els && els.length) return Array.from(els);
+ return undefined;
+};
+
+export const els_id_pref_index = (id_pref: string, num_index: number, orientation: `greater` | `lesser` = `greater`): Element[] | undefined => {
+ const els = document.querySelectorAll(`[id^="${`${id_pref}-`.replaceAll(`--`, `-`)}"]`);
+ if (els && els.length) return Array.from(els).filter(el => {
+ const match = el.id.match(/(?<=^|\-)[0-9]\d*(?=\-)/)
+ if (match) {
+ const num = parseInt(match[0], 10);
+ return orientation === `greater` ? num >= num_index : num <= num_index;
+ }
+ return false;
+ });
+ return undefined;
+};
+
diff --git a/apps-lib/src/lib/utils/dom.ts b/apps-lib/src/lib/utils/dom.ts
@@ -1,9 +0,0 @@
-export const el_id = (id: string): HTMLElement | undefined => {
- const el = document.getElementById(id);
- return el ? el : undefined;
-};
-
-export const el_toggle = (id: string, toggle_class: string): void => {
- const el = document.getElementById(id);
- if (el) el.classList.toggle(toggle_class);
-};
diff --git a/apps-lib/src/lib/utils/routes.ts b/apps-lib/src/lib/utils/routes.ts
@@ -8,6 +8,7 @@ export type NavigationRoute =
| "/models/nostr-relay/view"
| "/models/trade-product"
| "/models/trade-product/add"
+ | "/models/trade-product/view"
| "/settings"
| "/settings/nostr"
| "/test"
@@ -25,6 +26,7 @@ export function parse_route(route: string): NavigationRoute {
case "/models/nostr-relay/view":
case "/models/trade-product":
case "/models/trade-product/add":
+ case "/models/trade-product/view":
case "/settings":
case "/settings/nostr":
case "/test":