web_lib

Common web application libraries
git clone https://radroots.dev/git/web_lib.git
Log | Files | Refs | LICENSE

commit 0ffcb45b2d59e7019a4b4aac94fe1d19877d88a4
parent 429088bc03f67e8b203c6e165b795f3a62639f04
Author: triesap <137732411+triesap@users.noreply.github.com>
Date:   Fri,  4 Apr 2025 04:37:41 +0000

utils: edit app utils

Diffstat:
Mutils/package.json | 2+-
Mutils/src/*regex.ts | 6++++--
Mutils/src/*validation.ts | 15+++------------
Cutils/src/app/lib.ts -> utils/src/app/config.ts | 0
Dutils/src/app/document.ts | 51---------------------------------------------------
Autils/src/app/glyph.ts | 127+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dutils/src/app/i18n-icu.ts | 24------------------------
Dutils/src/app/i18n.ts | 34----------------------------------
Mutils/src/app/lib.ts | 82+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
Rutils/src/app/util/search.ts -> utils/src/app/search.ts | 0
Mutils/src/app/styles.ts | 63++++++++++++++++++++++-----------------------------------------
Dutils/src/app/types/app.ts | 77-----------------------------------------------------------------------------
Dutils/src/app/types/basis.ts | 14--------------
Dutils/src/app/types/component.ts | 245-------------------------------------------------------------------------------
Dutils/src/app/types/element.ts | 7-------
Dutils/src/app/types/geometry.ts | 16----------------
Dutils/src/app/types/glyph.ts | 125-------------------------------------------------------------------------------
Dutils/src/app/types/interface.ts | 214-------------------------------------------------------------------------------
Dutils/src/app/types/resolve.ts | 29-----------------------------
Dutils/src/app/types/view.ts | 33---------------------------------
Mutils/src/app/util.ts | 59++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Dutils/src/app/util/resolve-enum.ts | 166-------------------------------------------------------------------------------
Dutils/src/app/util/resolve.ts | 6------
Dutils/src/app/validation/view.ts | 27---------------------------
Mutils/src/geo.ts | 16++++++++++------
Autils/src/i18n.ts | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Mutils/src/index.ts | 74+++++++++++++++++++++++++++++++-------------------------------------------
Mutils/src/lib.ts | 4+---
Mutils/src/types.ts | 7+++++++
Mutils/src/unit.ts | 6+++---
30 files changed, 366 insertions(+), 1215 deletions(-)

diff --git a/utils/package.json b/utils/package.json @@ -36,7 +36,7 @@ "@sveltekit-i18n/parser-icu": "^1.0.8", "convert": "^5.5.1", "geohashing": "^2.0.1", - "nostr-geotags": "^0.7.1", + "nostr-geotags": "workspace:*", "nostr-tools": "^2.10.4", "sveltekit-i18n": "^2.4.2", "uuid": "^10.0.0", diff --git a/utils/src/*regex.ts b/utils/src/*regex.ts @@ -1,5 +1,3 @@ -import { FormField } from "$root"; - export const util_rxp = { product_key: /^[A-Za-z_]+$/, product_key_ch: /^[A-Za-z_]$/, @@ -67,6 +65,10 @@ export type FormFieldsKey = | `contact_name` | `profile_name` +export type FormField = { + validate: RegExp; + charset: RegExp; +}; export const form_fields: Record<FormFieldsKey, FormField> = { profile_name: { diff --git a/utils/src/*validation.ts b/utils/src/*validation.ts @@ -1,23 +1,14 @@ -import { GeolocationAddress, GeolocationPoint, parse_int, ResolveEnumArea_Unit, ResolveEnumQuantity_Unit, util_rxp } from "$root"; +import { GeolocationAddress, GeolocationPoint, parse_int, util_rxp } from "$root"; import { z } from "zod"; -export const vunion_area_unit: z.ZodUnion<[ - z.ZodLiteral<ResolveEnumArea_Unit>, - z.ZodLiteral<ResolveEnumArea_Unit>, - z.ZodLiteral<ResolveEnumArea_Unit>, - z.ZodLiteral<ResolveEnumArea_Unit>, -]> = z.union([ +export const vu_area_unit = z.union([ z.literal(`ac`), z.literal(`ft2`), z.literal(`ha`), z.literal(`m2`), ]); -export const vunion_mass_unit: z.ZodUnion<[ - z.ZodLiteral<ResolveEnumQuantity_Unit>, - z.ZodLiteral<ResolveEnumQuantity_Unit>, - z.ZodLiteral<ResolveEnumQuantity_Unit>, -]> = z.union([ +export const vu_mass_unit = z.union([ z.literal(`kg`), z.literal(`lb`), z.literal(`g`), diff --git a/utils/src/app/lib.ts b/utils/src/app/config.ts diff --git a/utils/src/app/document.ts b/utils/src/app/document.ts @@ -1,51 +0,0 @@ -import { sleep, ThemeLayer } from "$root"; - -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` | `not` = `greater`, inclusive: boolean = true): 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); - switch (orientation) { - case `greater`: { - if (inclusive) return num >= num_index; - else return num > num_index; - } - case `lesser`: { - if (inclusive) return num <= num_index; - else return num < num_index; - } - case `not`: { - return num !== num_index; - } - } - } - return false; - }); - return undefined; -}; - -export const el_focus = async (id: string, callback: () => Promise<void>, layer: ThemeLayer = 1): Promise<void> => { - const el = el_id(id); - el?.classList.add(`entry-layer-${layer}-highlight`); - el?.focus(); - await sleep(1200); - await callback(); - el?.classList.remove(`entry-layer-${layer}-highlight`); -}; diff --git a/utils/src/app/glyph.ts b/utils/src/app/glyph.ts @@ -0,0 +1,127 @@ +import type { GeometryCardinalDirection } from "$root"; + +export type GlyphKey = | + `video-camera` | + `device-mobile-camera` | + `crop` | + `map-trifold` | + `trash-simple` | + `backspace` | + `user-circle-check` | + `images-square` | + `bell` | + `columns` | + `bold` | + `article` | + `grid-four` | + `link-simple` | + `seal-check` | + `selection-foreground` | + `image-square` | + `image-broken` | + `funnel` | + `users-three` | + `note-blank` | + `user-circle-plus` | + `user-circle` | + `receipt` | + `invoice` | + `note` | + `arrow-left` | + `arrows-down-up` | + `basket` | + `arrow-right` | + `upload-simple` | + `printer` | + `download-simple` | + `list` | + `asterisk` | + `asterisk-simple` | + `subtitles-slash` | + `cardholder` | + `globe-x` | + `exclamation-mark` | + `network-x` | + `x-circle` | + `address-book-tabs` | + `paper-plane-tilt` | + `note-pencil` | + `share-fat` | + `folder` | + `trash` | + `plus-circle` | + `currency-${GlyphKeyCurrency}` | + `arrow-down` | + `caret-circle-down` | + `caret-circle-up` | + `shopping-bag-open` | + `coffee-bean` | + `compass` | + `map-pin-simple` | + `handbag-simple` | + `devices` | + `lock-key` | + `gear` | + `gear-fine` | + `bell-simple` | + `envelope` | + `house-line` | + `arrows-left-right` | + `list-plus` | + `squares-four` | + `list-plus` | + `app-window` | + `circle-notch` | + `subtract-square` | + `device-tablet-speaker` | + `weather-cloud` | + `warning` | + `circle-notch` | + `minus` | + `key` | + `arrow-u-up-left` | + `arrow-counter-clockwise` | + `circle` | + `check-circle` | + `circle-dashed` | + `dots-three` | + `cards-three` | + `lightning` | + `cards` | + `note-pencil` | + `tray` | + `calendar-dots` | + `notepad` | + `network` | + `calendar-blank` | + `chats-circle` | + `plant` | + `farm` | + `magnifying-glass` | + `chat-circle-dots` | + `dots-three-outline` | + `copy` | + `circles-four` | + `waveform` | + `film-strip` | + `arrow-up` | + `arrow-circle-up` | + `plus` | + `funnel-simple` | + `user` | + `camera` | + `check` | + `file` | + `share-network` | + `question` | + `minus-circle` | + `globe-simple` | + `globe` | + `warning-circle` | + `x` | + `info` | + `caret-${GeometryCardinalDirection}` | + `caret-up-down`; + +export type GlyphKeyCurrency = `dollar` | `eur`; +export type GlyphWeight = `bold` | `fill` diff --git a/utils/src/app/i18n-icu.ts b/utils/src/app/i18n-icu.ts @@ -1,23 +0,0 @@ -import i18n, { type Loader } from "@sveltekit-i18n/base"; -import type { Config, Parser } from "@sveltekit-i18n/parser-icu"; -import parser from "@sveltekit-i18n/parser-icu"; - -type LanguageConfig = { - default?: string; - value?: string; -}; -export const i18n_conf_icu = <T extends string>(opts: { - default_locale: T; - translations: Record<T, any>; - loaders: Loader.LoaderModule[] -}): i18n<Parser.Params<LanguageConfig>> => { - const { default_locale: initLocale, translations, loaders } = opts; - const config: Config<LanguageConfig> = { - initLocale, - fallbackLocale: initLocale, - translations, - parser: parser(), - loaders, - }; - return new i18n(config); -}; -\ No newline at end of file diff --git a/utils/src/app/i18n.ts b/utils/src/app/i18n.ts @@ -1,34 +0,0 @@ -import { Loader } from '@sveltekit-i18n/base'; -import i18n, { type Config } from 'sveltekit-i18n'; - -type LanguageConfig = { - default?: string; - value?: string; -}; - -export const i18n_conf = <T extends string>(opts: { - default_locale: T; - translations: Record<T, any>; - loaders: Loader.LoaderModule[] -}) => { - const { default_locale: initLocale, translations, loaders } = opts; - const config: Config<LanguageConfig> = { - initLocale, - fallbackLocale: initLocale, - translations, - loaders, - }; - return new i18n(config); -}; - - -const lib_config: Config<LanguageConfig> = { - initLocale: `en`, - fallbackLocale: `en`, - translations: {}, - loaders: [], -}; -const lib_i18n = new i18n(lib_config); - -export type I18nTranslateFunction = typeof lib_i18n.t; -export type I18nTranslateLocale = typeof lib_i18n.locale; diff --git a/utils/src/app/lib.ts b/utils/src/app/lib.ts @@ -1,30 +1,51 @@ -import type { AppLayoutKey } from "$root"; - -type ConfigWindow = { - layout: Record<AppLayoutKey, { - h: number; - }>; - debounce: { - search: number; - } -}; - -export const cfg_app: ConfigWindow = { - layout: { - ios0: { - h: 600 - }, - ios1: { - h: 750 - }, - webm0: { - h: 600 - }, - webm1: { - h: 750 - } - }, - debounce: { - search: 200 - }, -}; -\ No newline at end of file +import type { CallbackPromise, CallbackPromiseGeneric } from "$root"; + +export type IViewBasis<T extends object> = { + kv_init_prevent?: boolean; + lc_on_mount?: CallbackPromise; + lc_on_destroy?: CallbackPromise; +} & T; + + +export type LabelFieldKind = `link` | `on` | `shade`; +export type EntryStyle = `guide` | `line`; +export type ImageAspectRatio = `auto` | `1/1` | `4/3` | `16/9` | `3/4`; + +export type SvelteTransitionEasingFunction = (t: number) => number; + +export type LoadingBlades = 8 | 12; +export type LoadingDimension = GeometryDimension | `glyph-send-button`; //@todo remove + +export type LayerGlyphBasisKind = `_a` | `_d` | `_pl`; + +export interface SvelteTransitionConfig { + delay?: number; + duration?: number; + easing?: SvelteTransitionEasingFunction; + css?: (t: number, u: number) => string; + tick?: (t: number, u: number) => void; +} + +export type ElementCallbackValue = CallbackPromiseGeneric<{ value: string; pass: boolean; }>; +export type ElementCallbackValueKeydown<T extends HTMLElement> = CallbackPromiseGeneric<{ key: string; key_s: boolean; el: T }>; +export type ElementCallbackValueBlur<T extends HTMLElement> = CallbackPromiseGeneric<{ el: T }>; +export type ElementCallbackValueFocus<T extends HTMLElement> = CallbackPromiseGeneric<{ el: T }>; +export type ElementCallbackMount<T extends HTMLElement> = CallbackPromiseGeneric<{ el: T }>; + +export type GeometryScreenPositionHorizontal = `left` | `center` | `right`; +export type GeometryScreenPositionVertical = `top` | `center` | `bottom`; +export type GeometryScreenPosition = `${GeometryScreenPositionVertical}-${GeometryScreenPositionHorizontal}`; +export type GeometryCardinalDirection = `up` | `down` | `left` | `right`; +export type GeometryDimension = + `xs` | + `sm` | + `md` | + `lg` | + `xl`; +export type GeometryGlyphDimension = + | `${GeometryDimension}` + | `${GeometryDimension}-` + | `${GeometryDimension}--` + | `${GeometryDimension}+`; + +export type NavigationParamTuple<T extends string> = [T, string]; diff --git a/utils/src/app/util/search.ts b/utils/src/app/search.ts diff --git a/utils/src/app/styles.ts b/utils/src/app/styles.ts @@ -1,44 +1,26 @@ -import type { AppLayoutKey, GeometryGlyphDimension, IToastKind, LoadingDimension } from "$root"; +export type ThemeLayer = 0 | 1 | 2; -export const glyph_style_map: Map<GeometryGlyphDimension, { gl_1: number; dim_1?: number; }> = new Map([ - ["xs--", { gl_1: 12 }], - ["xs-", { gl_1: 12, dim_1: 17 }], - ["xs", { gl_1: 15, dim_1: 18 }], - ["xs+", { gl_1: 18, dim_1: 20 }], - ["sm-", { gl_1: 19, dim_1: 22 }], - ["sm", { gl_1: 20, dim_1: 24 }], - ["sm+", { gl_1: 21 }], - ["md-", { gl_1: 23 }], - ["md", { gl_1: 24 }], - ["md+", { gl_1: 26 }], - ["lg-", { gl_1: 27 }], - ["lg", { gl_1: 28 }], - ["xl", { gl_1: 30 }], - ["xl+", { gl_1: 40 }], -]); +export type AppConfigType = `farmer` | `personal` -export const loading_style_map: Map<LoadingDimension, { dim_1: number; gl_2: number }> = new Map([ - ["glyph-send-button", { dim_1: 20, gl_2: 20 }], - ["xs", { dim_1: 12, gl_2: 12 }], - ["sm", { dim_1: 16, gl_2: 16 }], - ["md", { dim_1: 20, gl_2: 20 }], - ["lg", { dim_1: 28, gl_2: 28 }], - ["xl", { dim_1: 36, gl_2: 36 }], -]); +export type AppLayoutKeyIOS = `ios0` | `ios1`; +export type AppLayoutKeyWeb = `webm0` | `webm1`; +export type AppLayoutKey = AppLayoutKeyIOS | AppLayoutKeyWeb; -export const toast_layout_map: Map<AppLayoutKey, string> = new Map([ - [`ios0`, `pt-8`], - [`ios1`, `pt-16`], - [`webm0`, `pt-8`], - [`webm1`, `pt-16`], -]); +export type AppLayoutIOS<T extends string> = `${T}_${AppLayoutKeyIOS}`; +export type AppLayoutWeb<T extends string> = `${T}_${AppLayoutKeyWeb}`; -export const toast_style_map: Map<IToastKind, { inner: string; outer: string }> = new Map([ - [ - `simple`, - { - inner: `justify-center`, - outer: `min-h-toast_min w-full px-4 rounded-2xl shadow-sm`, - }, - ], -]); -\ No newline at end of file +export type AppLayoutKeyHeight = + | `lo_bottom_button` + | `nav_tabs` + | `nav_page_header` + | `nav_page_toolbar`; + +export type AppLayoutKeyWidth = + | `lo` + | `lo_textdesc`; + +export type AppHeightsResponsiveIOS = AppLayoutIOS<AppLayoutKeyHeight>; +export type AppHeightsResponsiveWeb = AppLayoutWeb<AppLayoutKeyHeight>; + +export type AppWidthsResponsiveIOS = AppLayoutIOS<AppLayoutKeyWidth>; +export type AppWidthsResponsiveWeb = AppLayoutWeb<AppLayoutKeyWidth>; diff --git a/utils/src/app/types/app.ts b/utils/src/app/types/app.ts @@ -1,76 +0,0 @@ -import type { GeocoderReverseResult, GeolocationPoint, GeometryDimension, IClientGeolocationPosition, INavigationRoute, ISelectOption } from "$root"; - -export type ThemeLayer = 0 | 1 | 2; - -export type AppConfigType = `farmer` | `personal` - -export type AppLayoutKeyIOS = `ios0` | `ios1`; -export type AppLayoutKeyWeb = `webm0` | `webm1`; -export type AppLayoutKey = AppLayoutKeyIOS | AppLayoutKeyWeb; - -export type AppLayoutIOS<T extends string> = `${T}_${AppLayoutKeyIOS}`; -export type AppLayoutWeb<T extends string> = `${T}_${AppLayoutKeyWeb}`; - -export type AppLayoutKeyHeight = - | `lo_bottom_button` - | `nav_tabs` - | `nav_page_header` - | `nav_page_toolbar`; - -export type AppLayoutKeyWidth = - | `lo` - | `lo_textdesc`; - -export type AppHeightsResponsiveIOS = AppLayoutIOS<AppLayoutKeyHeight>; -export type AppHeightsResponsiveWeb = AppLayoutWeb<AppLayoutKeyHeight>; - -export type AppWidthsResponsiveIOS = AppLayoutIOS<AppLayoutKeyWidth>; -export type AppWidthsResponsiveWeb = AppLayoutWeb<AppLayoutKeyWidth>; - -export type CallbackPromiseFigureResult<Ti, Tr> = (value: Ti) => Promise<Tr | undefined>; -export type CallbackPromiseFull<Ti, Tr> = (value: Ti) => Promise<Tr>; -export type CallbackPromiseGeneric<T> = (value: T) => Promise<void>; -export type CallbackPromiseReturn<T> = () => Promise<T>; -export type CallbackPromiseResult<Tr> = () => Promise<Tr | undefined>; - -export type CallbackPromise = () => Promise<void>; -export type CallbackRoute<T extends string> = CallbackPromise | INavigationRoute<T>; - -export type ElementCallbackSelect = CallbackPromiseGeneric<ISelectOption<string>> - -export type EntryStyle = `guide` | `line`; - - -export type LoadingBlades = 8 | 12; -export type LoadingDimension = GeometryDimension | `glyph-send-button`; //@todo remove - -export type LayerGlyphBasisKind = `_a` | `_d` | `_pl`; - -export type NavigationRouteParamId = `id`; -export type NavigationRouteParamField = `field`; -export type NavigationRouteParamRef = `ref`; -export type NavigationRouteParamLat = `lat`; -export type NavigationRouteParamLng = `lng`; -export type NavigationRouteParamNostrPublicKey = `key_nostr`; -export type NavigationRouteParamKey = NavigationRouteParamId | NavigationRouteParamField | NavigationRouteParamRef | NavigationRouteParamLat | NavigationRouteParamLng | NavigationRouteParamNostrPublicKey; -export type NavigationParamTuple = [NavigationRouteParamKey, string]; -export type NavigationPreviousParam<T extends string> = { route: T, label?: string; params?: NavigationParamTuple[] } - -export type EasingFunction = (t: number) => number; - -export interface SvelteTransitionConfig { - delay?: number; - duration?: number; - easing?: EasingFunction; - css?: (t: number, u: number) => string; - tick?: (t: number, u: number) => void; -} - -export type LcGuiAlertCallback = CallbackPromiseFull<string, boolean>; -export type LcGuiConfirmCallback = CallbackPromiseFull<string | { message: string; ok?: string; cancel?: string }, boolean>; -export type LcGeocodeCurrentCallback = CallbackPromiseResult<IClientGeolocationPosition>; -export type LcGeocodeCallback = CallbackPromiseFull<GeolocationPoint, GeocoderReverseResult | undefined>; -export type LcPhotoAddCallback = CallbackPromiseResult<string>; -export type LcPhotoAddMultipleCallback = CallbackPromiseResult<string[]>; - -export type ImageAspectRatio = `auto` | `1/1` | `4/3` | `16/9` | `3/4`; -\ No newline at end of file diff --git a/utils/src/app/types/basis.ts b/utils/src/app/types/basis.ts @@ -1,13 +0,0 @@ -import type { CallbackPromise, CallbackPromiseReturn } from "$root"; - -export type IBasisOpt<T extends object> = T | undefined; - -export type IViewBasis<T extends object> = { - kv_init_prevent?: boolean; - lc_on_mount?: CallbackPromise; - lc_on_destroy?: CallbackPromise; -} & T; - -export type IViewBasisLoad<Tv extends object, Tl extends object> = IViewBasis<Tv> & { - lc_load: CallbackPromiseReturn<Tl | undefined>; -}; -\ No newline at end of file diff --git a/utils/src/app/types/component.ts b/utils/src/app/types/component.ts @@ -1,245 +0,0 @@ -import type { CallbackPromise, CallbackRoute, ElementCallbackMount, ElementCallbackSelect, ElementCallbackValue, ElementCallbackValueBlur, ElementCallbackValueKeydown, FormField, GeometryGlyphDimension, GeometryScreenPosition, GlyphKey, GlyphWeight, ICb, ICbG, ICbGOpt, ICbOpt, IClOpt, IDisabledOpt, IEntryWrap, IGl, IGlOpt, IIdGOpt, IIdOpt, ILabel, ILabelOpt, ILabelTup, ILoadingOpt, ILy, ILyOpt, INavigationRoutePreventRouteNav, LcGeocodeCallback, NavigationParamTuple } from "$root"; - -export type IToastKind = `simple`; - -export type IToast = IClOpt & - ILabel & IGlOpt & ILyOpt & { - styles?: IToastKind[]; - position?: GeometryScreenPosition; - }; - -export type IGlyph = ICbOpt & IIdOpt & ILyOpt & IClOpt & { - weight?: GlyphWeight; - key: GlyphKey; - dim?: GeometryGlyphDimension; -}; - -export type IInput<T extends string> = IIdGOpt<T> & IClOpt & ILyOpt & IDisabledOpt & { - placeholder?: string; - label?: string; - hidden?: boolean; - validate?: RegExp; - sync?: boolean; - field?: FormField; - field_constrain?: boolean; - callback?: ElementCallbackValue, - callback_keydown?: ElementCallbackValueKeydown<HTMLInputElement>, - callback_blur?: ElementCallbackValueBlur<HTMLInputElement>; - callback_focus?: ElementCallbackValueBlur<HTMLInputElement>; - callback_mount?: ElementCallbackMount<HTMLInputElement>; -}; - -export type IInputValue<T extends string> = Omit<IInput<T>, `id` | `sync`>; - -export type ISelectOption<T extends string> = IDisabledOpt & { - value: T; - label: string; -}; - -export type ISelect = IIdOpt & IClOpt & ILyOpt & { - callback?: ElementCallbackSelect; - sync?: boolean; - sync_init?: boolean; - options: { group?: string | true; entries: ISelectOption<string>[] }[]; - show_arrows?: 'l' | 'r'; -}; - -export type ITextArea = IIdOpt & IClOpt & ILyOpt & { - placeholder?: string; - label?: string; - hidden?: boolean; - validate?: RegExp; - sync?: true; - field?: FormField; - field_constrain?: boolean; - callback?: ElementCallbackValue, - callback_keydown?: ElementCallbackValueKeydown<HTMLTextAreaElement>, - callback_blur?: ElementCallbackValueBlur<HTMLTextAreaElement>; - callback_focus?: ElementCallbackValueBlur<HTMLTextAreaElement>; - callback_mount?: ElementCallbackMount<HTMLTextAreaElement>; -}; - -export type INavigationRoute<T extends string> = { - route: T | [T, NavigationParamTuple[]]; -}; - -export type IPageToolbar<T extends string> = ICbOpt & { - header?: IPageHeader<T>; -}; - -export type IPageHeader<T extends string> = { - label: string; - callback_route?: CallbackRoute<T>; -}; - -export type IGlyphCircle = { - classes_wrap: string; - glyph: IGlyph -}; - -export type ITrellis = ILy & - IClOpt & - ITrellisStyles & { - id?: string; - view?: string; - title?: ITrellisTitle; - description?: ITrellisDescription; - default_el?: ITrellisDefault; - list?: (ITrellisKind | undefined)[]; - hide_offset?: true; - }; - -export type ITrellisStyles = { - hide_rounded?: boolean; - hide_border_top?: boolean; - hide_border_bottom?: boolean; - set_title_background?: boolean; - set_default_background?: boolean; -}; - -export type ITrellisTitle = ICbOpt & - IClOpt & { - mod?: ITrellisBasisOffsetMod, - value: string | true; - link?: ICbOpt & - IClOpt & - IGlOpt & ILabelOpt; - }; - -export type ITrellisDescription = string | true; - -export type ITrellisBasisOffsetModKey = 'sm' | 'glyph'; -export type ITrellisBasisOffsetMod = ITrellisBasisOffsetModKey | (({ glyph: IGlyph } | { glyph_circle: IGlyphCircle }) & { - loading?: boolean; -}); - -export type ITrellisDefault = { - labels?: ITrellisDefaultLabel[]; - show_title?: boolean; -}; - -export type ITrellisDefaultLabel = ICbOpt & { - label: string; - classes?: string; -}; - -export type ITrellisKind = ( - | ITrellisKindTouch - | ITrellisKindInput - | ITrellisKindSelect -); - -export type ITrellisBasis = { - loading?: boolean; - hide_active?: boolean; - hide_field?: boolean; - offset?: ITrellisBasisOffset; - full_rounded?: boolean; -}; - -export type ITrellisBasisOffset = ICbGOpt<MouseEvent> & - IClOpt & { - mod?: ITrellisBasisOffsetMod; - classes?: string; - hide_space?: boolean; - hide_offset?: boolean; - }; - -export type ITrellisKindDisplay = { - display?: ITrellisKindDisplayValue; -} -export type ITrellisKindDisplayValue = ICbGOpt<MouseEvent> & ILoadingOpt & - (ITrellisKindDisplayValueIcon | ILabel); - - -export type ITrellisKindDisplayValueIcon = { - icon: { - classes?: string; - key: GlyphKey; - }; -}; -export type ITrellisKindTouch = ITrellisBasis & { - touch: ITrellisBasisTouch; -}; - -export type ITrellisBasisTouch = ICbGOpt<MouseEvent> & - ILabelTup & ITrellisKindDisplay & { - end?: ITrellisBasisTouchEnd; - }; - -export type ITrellisKindInput = ITrellisBasis & { - input: ITrellisBasisInput; -}; - -export type ITrellisBasisInput = { - basis: IInput<string>; - line_label?: { - classes?: string; - value: string; - }; - action?: { - visible: boolean; - loading?: boolean; - callback?: CallbackPromise; - glyph?: IGlyph - }; -}; - -export type ITrellisKindSelect = ITrellisBasis & { - select: ITrellisBasisSelect; -}; - -export type ITrellisBasisSelect = ICbGOpt<MouseEvent> & - ILabelTup & ITrellisKindDisplay & ILoadingOpt & { - end?: ITrellisBasisTouchEnd; - el: ISelect & { value: string; }; - }; - -export type ITrellisBasisTouchEnd = ICbGOpt<MouseEvent> & IGl; - -export type INavBasisPrev = IClOpt & ICbG< - HTMLLabelElement | null -> & IGlOpt & ILabelOpt & IDisabledOpt & { - loading?: boolean; -}; -export type INavBasisOption = IClOpt & ICbG< - HTMLLabelElement | null -> & IGlOpt & ILabelOpt & IDisabledOpt & { - loading?: boolean; -}; -export type INavBasis<T extends string> = { - prev: ICbOpt & ILoadingOpt & INavigationRoute<T> & INavigationRoutePreventRouteNav & { - label?: string; - kind?: 'arrow' - }; - title?: ICbOpt & ILabel; - option?: INavBasisOption; -}; - -export type IEntrySelect = ILoadingOpt & { - wrap: IEntryWrap; - el: ISelect; - hide_arrows?: boolean; -}; - -export type IButtonSimple = ILyOpt & { - label: string; - callback: CallbackPromise; - allow_propogation?: boolean; -}; - -export type IMapMarkerArea = { - show_display?: boolean; - no_drag?: boolean; - lc_geocode: LcGeocodeCallback; -} - -export type ILayoutTrellisLine = ILabelOpt & - IClOpt & { - notify?: IClOpt & - ICb & - ILabelOpt & - IGlOpt & { - glyph_first?: boolean; - }; - }; diff --git a/utils/src/app/types/element.ts b/utils/src/app/types/element.ts @@ -1,7 +0,0 @@ -import type { CallbackPromiseGeneric } from "$root"; - -export type ElementCallbackValue = CallbackPromiseGeneric<{ value: string; pass: boolean; }>; -export type ElementCallbackValueKeydown<T extends HTMLElement> = CallbackPromiseGeneric<{ key: string; key_s: boolean; el: T }>; -export type ElementCallbackValueBlur<T extends HTMLElement> = CallbackPromiseGeneric<{ el: T }>; -export type ElementCallbackValueFocus<T extends HTMLElement> = CallbackPromiseGeneric<{ el: T }>; -export type ElementCallbackMount<T extends HTMLElement> = CallbackPromiseGeneric<{ el: T }>; diff --git a/utils/src/app/types/geometry.ts b/utils/src/app/types/geometry.ts @@ -1,15 +0,0 @@ -export type GeometryScreenPositionHorizontal = `left` | `center` | `right`; -export type GeometryScreenPositionVertical = `top` | `center` | `bottom`; -export type GeometryScreenPosition = `${GeometryScreenPositionVertical}-${GeometryScreenPositionHorizontal}`; -export type GeometryCardinalDirection = `up` | `down` | `left` | `right`; -export type GeometryDimension = - `xs` | - `sm` | - `md` | - `lg` | - `xl`; -export type GeometryGlyphDimension = - | `${GeometryDimension}` - | `${GeometryDimension}-` - | `${GeometryDimension}--` - | `${GeometryDimension}+`; -\ No newline at end of file diff --git a/utils/src/app/types/glyph.ts b/utils/src/app/types/glyph.ts @@ -1,125 +0,0 @@ -import type { GeometryCardinalDirection } from "$root"; - -export type GlyphKey = | - `crop` | - `map-trifold` | - `trash-simple` | - `backspace` | - `user-circle-check` | - `images-square` | - `bell` | - `columns` | - `bold` | - `article` | - `grid-four` | - `link-simple` | - `seal-check` | - `selection-foreground` | - `image-square` | - `image-broken` | - `funnel` | - `users-three` | - `note-blank` | - `user-circle-plus` | - `user-circle` | - `receipt` | - `invoice` | - `note` | - `arrow-left` | - `arrows-down-up` | - `basket` | - `arrow-right` | - `upload-simple` | - `printer` | - `download-simple` | - `list` | - `asterisk` | - `asterisk-simple` | - `subtitles-slash` | - `cardholder` | - `globe-x` | - `exclamation-mark` | - `network-x` | - `x-circle` | - `address-book-tabs` | - `paper-plane-tilt` | - `note-pencil` | - `share-fat` | - `folder` | - `trash` | - `plus-circle` | - `currency-${GlyphKeyCurrency}` | - `arrow-down` | - `caret-circle-down` | - `caret-circle-up` | - `shopping-bag-open` | - `coffee-bean` | - `compass` | - `map-pin-simple` | - `handbag-simple` | - `devices` | - `lock-key` | - `gear` | - `gear-fine` | - `bell-simple` | - `envelope` | - `house-line` | - `arrows-left-right` | - `list-plus` | - `squares-four` | - `list-plus` | - `app-window` | - `circle-notch` | - `subtract-square` | - `device-tablet-speaker` | - `weather-cloud` | - `warning` | - `circle-notch` | - `minus` | - `key` | - `arrow-u-up-left` | - `arrow-counter-clockwise` | - `circle` | - `check-circle` | - `circle-dashed` | - `dots-three` | - `cards-three` | - `lightning` | - `cards` | - `note-pencil` | - `tray` | - `calendar-dots` | - `notepad` | - `network` | - `calendar-blank` | - `chats-circle` | - `plant` | - `farm` | - `magnifying-glass` | - `chat-circle-dots` | - `dots-three-outline` | - `copy` | - `circles-four` | - `waveform` | - `film-strip` | - `arrow-up` | - `arrow-circle-up` | - `plus` | - `funnel-simple` | - `user` | - `camera` | - `check` | - `file` | - `share-network` | - `question` | - `minus-circle` | - `globe-simple` | - `globe` | - `warning-circle` | - `x` | - `info` | - `caret-${GeometryCardinalDirection}` | - `caret-up-down`; - -export type GlyphKeyCurrency = `dollar` | `eur`; -export type GlyphWeight = `bold` | `fill` diff --git a/utils/src/app/types/interface.ts b/utils/src/app/types/interface.ts @@ -1,214 +0,0 @@ -import type { CallbackPromise, CallbackPromiseGeneric, EntryStyle, GlyphKey, IGlyph, IInput, IInputValue, ITextArea, LayerGlyphBasisKind, LoadingBlades, LoadingDimension, SvelteTransitionConfig, ThemeLayer } from "$root"; - -export type IDisabled = { - disabled: boolean | never; -}; - -export type IDisabledOpt = Partial<IDisabled>; - -export type IBasis<T> = { - basis: T; -}; - -export type ICb = { - callback: CallbackPromise | never; -}; - -export type ICbOpt = Partial<ICb>; - -export type ICbG<T> = { - callback: CallbackPromiseGeneric<T> | never; -}; - -export type ICbGOpt<T> = Partial<ICbG<T>>; - -export type ICl = { - classes: string | never; -}; - -export type IClOpt = Partial<ICl>; - -export type IClWrap = { - classes_wr: string | never; -}; - -export type IClOptWrap = Partial<IClWrap>; - -export type IId = { - id: string | never; -}; - -export type IIdOpt = Partial<IId>; - -export type IGl = { - glyph: IGlyph | never; -}; - -export type IGlOpt = Partial<IGl>; - -export type IGlyphKey = { - glyph: GlyphKey -}; - -export type ILy = { - layer: ThemeLayer | never; -}; - -export type ILyOpt = Partial<ILy>; - -export type ILableFieldsSwap = { - toggle: boolean; - on: IClOpt & { - value: string; - }, - off: IClOpt & { - value: string; - }, -}; - -export type ILabelSwap = { - swap: ILableFieldsSwap; -} - -export type ILabelTupFields = { - left?: ILableFields[]; - right?: ILableFields[]; -}; - -export type ILabelTup = { - label: ILabelTupFields; -}; - -export type LabelFieldKind = `link` | `on` | `shade`; - -export type ILableFields = & { - classes_wrap?: string - classes?: string; - kind?: LayerGlyphBasisKind; - hide_truncate?: boolean; - hide_active?: boolean; -} & ( - ({ - value: string; - } | ILabelSwap) - | IGl - ); - -export type ILabel = { - label: ILableFields; -}; - -export type ILabelOpt = Partial<ILabel>; - -export type ILoadSymbol = IClOpt & { - color?: 'white'; - blades?: LoadingBlades; - dim?: LoadingDimension; -}; - -export type IIdG<T extends string> = { - id: T | never; -}; - -export type FormField = { - validate: RegExp; - charset: RegExp; -}; - -export type IIdGOpt<T extends string> = Partial<IIdG<T>>; - -export type IIdWrap = { - id_wrap: string | never; -}; - -export type IIdWrapOpt = Partial<IIdWrap>; - -export type ILabelValue = { - label: IClOpt & { - value: string; - }; -}; - -export type ILabelDisplay = IIdWrapOpt & IClOpt & ILabelValue & ILyOpt & { - style?: EntryStyle; -}; - - -export type ILoading = { - loading: boolean | never; -}; - -export type ILoadingOpt = Partial<ILoading>; - -export type IEntryWrap = IClOpt & IIdOpt & ILyOpt & { - style?: EntryStyle; - style_a?: true; - no_pad?: true; - fade?: { - in?: SvelteTransitionConfig; - out?: SvelteTransitionConfig; - }; -} - -export type IEntryLine = ILoadingOpt & { - wrap?: IEntryWrap; - el: IInputValue<string>; - notify_inline?: { - glyph: GlyphKey | IGlyph; - }; -}; - -export type IEntryLineIdb = ILoadingOpt & { - wrap?: IEntryWrap; - el: IInput<string>; - notify_inline?: { - glyph: GlyphKey | IGlyph; - }; -}; - -export type IEntryMultiLine = { - wrap?: IEntryWrap; - el: ITextArea; - notify_inline?: { - glyph: GlyphKey | IGlyph; - }; -} - -export type IEnvelopeLower = { - visible: boolean; - close: CallbackPromise; - full_cover?: boolean; - label_close?: string | true; -}; - -export type IButtonRound = IClOpt & ILoadingOpt & { - label: string; - callback: CallbackPromise; -}; - -export type INavigationRoutePreventRouteNav = { - prevent_route?: { - callback: CallbackPromise; - }; -}; - -export type INavigationRoutePreventRoute = { - prevent_route: CallbackPromise; -}; - -export type IImageBlob = IIdOpt & { - data: Uint8Array | undefined; - alt?: string; -}; - -export type IImagePath = IClOpt & - ICbGOpt< - MouseEvent & { - currentTarget: EventTarget & HTMLImageElement; - } - > & - IIdOpt & { - path?: string; - alt?: string; - }; - diff --git a/utils/src/app/types/resolve.ts b/utils/src/app/types/resolve.ts @@ -1,29 +0,0 @@ -export type ResolveEnumAccount_Role = 'admin' | 'guest' | 'internal' | 'member'; -export type ResolveEnumArea_Unit = 'ac' | 'ft2' | 'ha' | 'm2'; -export type ResolveEnumAuth_Credential = 'email' | 'phone'; -export type ResolveEnumBudget_Item_Type = 'capital_investment' | 'equipment' | 'fees' | 'infrastructure' | 'insurance' | 'labor' | 'materials' | 'other' | 'supplies'; -export type ResolveEnumBudget_Spending_Type = 'equipment' | 'labor' | 'maintenance' | 'other' | 'supplies' | 'utilities'; -export type ResolveEnumPayment_Method = 'cash'; -export type ResolveEnumPayment_Period = 'biweekly' | 'hourly' | 'monthly' | 'weekly'; -export type ResolveEnumPayment_Status = 'confirmed' | 'pending'; -export type ResolveEnumQuantity_Unit = 'g' | 'kg' | 'lb' | 'ton'; -export type ResolveEnumWorker_Type = 'contractor' | 'laborer'; -export type ResolveAccountInfo = { id: string, created_at: string, updated_at: string, role: ResolveEnumAccount_Role, username: string, auth_ref: { credential: ResolveEnumAuth_Credential, email: { id: string, created_at: string, updated_at: string, address: string } }, profiles?: Array<{ id: string, created_at: string, updated_at: string, name: string, display_name?: string | null, primary: boolean, about?: string | null, emails: Array<{ id: string, created_at: string, updated_at: string, address: string }>, profile_photos?: Array<{ id: string, created_at: string, updated_at: string, primary: boolean, title?: string | null, description?: string | null, media_image: { id: string, created_at: string, updated_at: string, url: string } }> | null, nostr_keys: Array<{ id: string, created_at: string, updated_at: string, public_key: string }> }> | null, farms?: Array<{ id: string, created_at: string, updated_at: string, name: string, area?: number | null, area_unit: ResolveEnumArea_Unit, geolocation?: { id: string, created_at: string, updated_at: string, point: { type: string, coordinates: Array<number> }, polygon?: { type: string, coordinates: Array<Array<Array<number>>> } | null, address: { id: string, created_at: string, updated_at: string, primary: string, admin: string, country: string } } | null, farm_products?: Array<{ id: string, created_at: string, updated_at: string, name: string, farm_lot_products?: Array<{ id: string }> | null }> | null, farm_lots?: Array<{ id: string, created_at: string, updated_at: string, name?: string | null, area?: number | null, area_unit: ResolveEnumArea_Unit, geolocation: { id: string, created_at: string, updated_at: string, point: { type: string, coordinates: Array<number> }, polygon?: { type: string, coordinates: Array<Array<Array<number>>> } | null, address: { id: string, created_at: string, updated_at: string, primary: string, admin: string, country: string } }, farm_lot_products?: Array<{ id: string, created_at: string, updated_at: string, area_planted?: number | null, area_planted_unit: ResolveEnumArea_Unit, date_planted?: string | null, days_to_maturity?: number | null, farm_product: { id: string, created_at: string, updated_at: string, name: string, farm_lot_products?: Array<{ id: string }> | null }, farm_trade_products?: Array<{ id: string, created_at: string, updated_at: string, title: string, description: string, process?: string | null, trade_product_prices?: Array<{ id: string, created_at: string, updated_at: string, amount: number, currency: string, quantity_amount?: number | null, quantity_unit: ResolveEnumQuantity_Unit, quantity_label?: string | null }> | null, trade_product_quantitys?: Array<{ id: string, created_at: string, updated_at: string, amount?: number | null, unit: ResolveEnumQuantity_Unit, label?: string | null }> | null }> | null, farm_lot_harvests?: Array<{ id: string, created_at: string, updated_at: string, quantity_harvested: number, quantity_harvested_unit: ResolveEnumQuantity_Unit }> | null }> | null }> | null }> | null }; -export type ResolveAuthRefInfo = { credential: ResolveEnumAuth_Credential, email: { id: string, created_at: string, updated_at: string, address: string } }; -export type ResolveEmailInfo = { id: string, created_at: string, updated_at: string, address: string }; -export type ResolveProfileInfo = { id: string, created_at: string, updated_at: string, name: string, display_name?: string | null, primary: boolean, about?: string | null, emails: Array<{ id: string, created_at: string, updated_at: string, address: string }>, profile_photos?: Array<{ id: string, created_at: string, updated_at: string, primary: boolean, title?: string | null, description?: string | null, media_image: { id: string, created_at: string, updated_at: string, url: string } }> | null, nostr_keys: Array<{ id: string, created_at: string, updated_at: string, public_key: string }> }; -export type ResolveProfilePhotoInfo = { id: string, created_at: string, updated_at: string, primary: boolean, title?: string | null, description?: string | null, media_image: { id: string, created_at: string, updated_at: string, url: string } }; -export type ResolveMediaImageInfo = { id: string, created_at: string, updated_at: string, url: string }; -export type ResolveNostrKeyInfo = { id: string, created_at: string, updated_at: string, public_key: string }; -export type ResolveFarmInfo = { id: string, created_at: string, updated_at: string, name: string, area?: number | null, area_unit: ResolveEnumArea_Unit, geolocation?: { id: string, created_at: string, updated_at: string, point: { type: string, coordinates: Array<number> }, polygon?: { type: string, coordinates: Array<Array<Array<number>>> } | null, address: { id: string, created_at: string, updated_at: string, primary: string, admin: string, country: string } } | null, farm_products?: Array<{ id: string, created_at: string, updated_at: string, name: string, farm_lot_products?: Array<{ id: string }> | null }> | null, farm_lots?: Array<{ id: string, created_at: string, updated_at: string, name?: string | null, area?: number | null, area_unit: ResolveEnumArea_Unit, geolocation: { id: string, created_at: string, updated_at: string, point: { type: string, coordinates: Array<number> }, polygon?: { type: string, coordinates: Array<Array<Array<number>>> } | null, address: { id: string, created_at: string, updated_at: string, primary: string, admin: string, country: string } }, farm_lot_products?: Array<{ id: string, created_at: string, updated_at: string, area_planted?: number | null, area_planted_unit: ResolveEnumArea_Unit, date_planted?: string | null, days_to_maturity?: number | null, farm_product: { id: string, created_at: string, updated_at: string, name: string, farm_lot_products?: Array<{ id: string }> | null }, farm_trade_products?: Array<{ id: string, created_at: string, updated_at: string, title: string, description: string, process?: string | null, trade_product_prices?: Array<{ id: string, created_at: string, updated_at: string, amount: number, currency: string, quantity_amount?: number | null, quantity_unit: ResolveEnumQuantity_Unit, quantity_label?: string | null }> | null, trade_product_quantitys?: Array<{ id: string, created_at: string, updated_at: string, amount?: number | null, unit: ResolveEnumQuantity_Unit, label?: string | null }> | null }> | null, farm_lot_harvests?: Array<{ id: string, created_at: string, updated_at: string, quantity_harvested: number, quantity_harvested_unit: ResolveEnumQuantity_Unit }> | null }> | null }> | null }; -export type ResolveGeolocationInfo = { id: string, created_at: string, updated_at: string, point: { type: string, coordinates: Array<number> }, polygon?: { type: string, coordinates: Array<Array<Array<number>>> } | null, address: { id: string, created_at: string, updated_at: string, primary: string, admin: string, country: string } }; -export type ResolveAddressInfo = { id: string, created_at: string, updated_at: string, primary: string, admin: string, country: string }; -export type ResolveFarmLotInfo = { id: string, created_at: string, updated_at: string, name?: string | null, area?: number | null, area_unit: ResolveEnumArea_Unit, geolocation: { id: string, created_at: string, updated_at: string, point: { type: string, coordinates: Array<number> }, polygon?: { type: string, coordinates: Array<Array<Array<number>>> } | null, address: { id: string, created_at: string, updated_at: string, primary: string, admin: string, country: string } }, farm_lot_products?: Array<{ id: string, created_at: string, updated_at: string, area_planted?: number | null, area_planted_unit: ResolveEnumArea_Unit, date_planted?: string | null, days_to_maturity?: number | null, farm_product: { id: string, created_at: string, updated_at: string, name: string, farm_lot_products?: Array<{ id: string }> | null }, farm_trade_products?: Array<{ id: string, created_at: string, updated_at: string, title: string, description: string, process?: string | null, trade_product_prices?: Array<{ id: string, created_at: string, updated_at: string, amount: number, currency: string, quantity_amount?: number | null, quantity_unit: ResolveEnumQuantity_Unit, quantity_label?: string | null }> | null, trade_product_quantitys?: Array<{ id: string, created_at: string, updated_at: string, amount?: number | null, unit: ResolveEnumQuantity_Unit, label?: string | null }> | null }> | null, farm_lot_harvests?: Array<{ id: string, created_at: string, updated_at: string, quantity_harvested: number, quantity_harvested_unit: ResolveEnumQuantity_Unit }> | null }> | null }; -export type ResolveFarmLotProductInfo = { id: string, created_at: string, updated_at: string, area_planted?: number | null, area_planted_unit: ResolveEnumArea_Unit, date_planted?: string | null, days_to_maturity?: number | null, farm_product: { id: string, created_at: string, updated_at: string, name: string, farm_lot_products?: Array<{ id: string }> | null }, farm_trade_products?: Array<{ id: string, created_at: string, updated_at: string, title: string, description: string, process?: string | null, trade_product_prices?: Array<{ id: string, created_at: string, updated_at: string, amount: number, currency: string, quantity_amount?: number | null, quantity_unit: ResolveEnumQuantity_Unit, quantity_label?: string | null }> | null, trade_product_quantitys?: Array<{ id: string, created_at: string, updated_at: string, amount?: number | null, unit: ResolveEnumQuantity_Unit, label?: string | null }> | null }> | null, farm_lot_harvests?: Array<{ id: string, created_at: string, updated_at: string, quantity_harvested: number, quantity_harvested_unit: ResolveEnumQuantity_Unit }> | null }; -export type ResolveFarmProductInfo = { id: string, created_at: string, updated_at: string, name: string, farm_lot_products?: Array<{ id: string }> | null }; -export type ResolveFarmTradeProductInfo = { id: string, created_at: string, updated_at: string, title: string, description: string, process?: string | null, trade_product_prices?: Array<{ id: string, created_at: string, updated_at: string, amount: number, currency: string, quantity_amount?: number | null, quantity_unit: ResolveEnumQuantity_Unit, quantity_label?: string | null }> | null, trade_product_quantitys?: Array<{ id: string, created_at: string, updated_at: string, amount?: number | null, unit: ResolveEnumQuantity_Unit, label?: string | null }> | null }; -export type ResolveTradeProductPriceInfo = { id: string, created_at: string, updated_at: string, amount: number, currency: string, quantity_amount?: number | null, quantity_unit: ResolveEnumQuantity_Unit, quantity_label?: string | null }; -export type ResolveTradeProductQuantityInfo = { id: string, created_at: string, updated_at: string, amount?: number | null, unit: ResolveEnumQuantity_Unit, label?: string | null }; -export type ResolveFarmLotHarvestInfo = { id: string, created_at: string, updated_at: string, quantity_harvested: number, quantity_harvested_unit: ResolveEnumQuantity_Unit }; -export type ResolveGeometryPoint = { type: string, coordinates: Array<number> }; -export type ResolveGeometryPolygon = { type: string, coordinates: Array<Array<Array<number>>> }; diff --git a/utils/src/app/types/view.ts b/utils/src/app/types/view.ts @@ -1,33 +0,0 @@ -import { GeolocationAddress, GeolocationPoint, ResolveGeolocationInfo, ResolveProfileInfo } from "$root"; - -export type IViewSearchData = { - geolocations: ResolveGeolocationInfo[]; - profiles: ResolveProfileInfo[]; - nostr_relay: { id: string }[]; - farm_products: { id: string }[]; -}; - -export type IViewFarmsProductsAddSubmission = { - product: string; - process: string; - description: string; - price_amount: number; - price_currency: string; - price_quantity_unit: string; - photos: string[]; - quantity_amount: number; - quantity_unit: string; - quantity_label: string; - geolocation_point: GeolocationPoint; - geolocation_address: GeolocationAddress; -}; - -export type IViewFarmsAddSubmission = { - farm_name: string; - farm_area: number; - farm_area_unit: string; - farm_contact_name: string; - geolocation_point: GeolocationPoint; - geolocation_address: GeolocationAddress; -}; - diff --git a/utils/src/app/util.ts b/utils/src/app/util.ts @@ -1,4 +1,4 @@ -import type { AppLayoutKey, AppLayoutKeyIOS, AppLayoutKeyWeb, LabelFieldKind, NavigationParamTuple, ThemeLayer } from "$root"; +import { sleep, type AppLayoutKey, type AppLayoutKeyIOS, type AppLayoutKeyWeb, type LabelFieldKind, type NavigationParamTuple, type ThemeLayer } from "$root"; export const fmt_cl = (classes?: string): string => { return classes ? classes : ``; @@ -77,7 +77,7 @@ export const value_constrain_textarea = (regex_charset: RegExp, value: string): .join("\n"); }; -export const encode_query_params = (params_list: NavigationParamTuple[] = []): string => { +export const encode_query_params = <T extends string>(params_list: NavigationParamTuple<T>[] = []): string => { let query = ""; for (const [k, v] of params_list) { if (k && v) { @@ -88,7 +88,7 @@ export const encode_query_params = (params_list: NavigationParamTuple[] = []): s return query ? `?${query}` : ``; }; -export const encode_route = <T extends string>(route: T, params_list?: NavigationParamTuple[]): string => { +export const encode_route = <T extends string>(route: T, params_list?: NavigationParamTuple<T>[]): string => { const query = encode_query_params(params_list); if (!query) return route; return `${route === `/` ? `/` : route.replace(/\/+$/, ``)}${query}`; @@ -110,4 +110,54 @@ export const list_assign = (list_curr: string[], list_new: string[]): string[] = return Array.from( new Set([...list_curr, ...list_new]), ).filter((i) => !!i); -}; -\ No newline at end of file +}; + +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` | `not` = `greater`, inclusive: boolean = true): 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); + switch (orientation) { + case `greater`: { + if (inclusive) return num >= num_index; + else return num > num_index; + } + case `lesser`: { + if (inclusive) return num <= num_index; + else return num < num_index; + } + case `not`: { + return num !== num_index; + } + } + } + return false; + }); + return undefined; +}; + +export const el_focus = async (id: string, callback: () => Promise<void>, layer: ThemeLayer = 1): Promise<void> => { + const el = el_id(id); + el?.classList.add(`entry-layer-${layer}-highlight`); + el?.focus(); + await sleep(1200); + await callback(); + el?.classList.remove(`entry-layer-${layer}-highlight`); +}; diff --git a/utils/src/app/util/resolve-enum.ts b/utils/src/app/util/resolve-enum.ts @@ -1,165 +0,0 @@ -export type ResolveEnumAccountRoleKey = `Admin` | `Guest` | `Internal` | `Member`; - -export const parse_enum_account_role_key = (val: string): ResolveEnumAccountRoleKey | undefined => { - switch (val) { - case `admin`: - return `Admin`; - case `guest`: - return `Guest`; - case `internal`: - return `Internal`; - case `member`: - return `Member`; - default: - return undefined; - } -}; - -export type ResolveEnumAreaUnitKey = `Ac` | `Ft2` | `Ha` | `M2`; - -export const parse_enum_area_unit_key = (val: string): ResolveEnumAreaUnitKey | undefined => { - switch (val) { - case `ac`: - return `Ac`; - case `ft2`: - return `Ft2`; - case `ha`: - return `Ha`; - case `m2`: - return `M2`; - default: - return undefined; - } -}; - -export type ResolveEnumAuthCredentialKey = `Email` | `Phone`; - -export const parse_enum_auth_credential_key = (val: string): ResolveEnumAuthCredentialKey | undefined => { - switch (val) { - case `email`: - return `Email`; - case `phone`: - return `Phone`; - default: - return undefined; - } -}; - -export type ResolveEnumBudgetItemTypeKey = `CapitalInvestment` | `Equipment` | `Fees` | `Infrastructure` | `Insurance` | `Labor` | `Materials` | `Other` | `Supplies`; - -export const parse_enum_budget_item_type_key = (val: string): ResolveEnumBudgetItemTypeKey | undefined => { - switch (val) { - case `capitalinvestment`: - return `CapitalInvestment`; - case `equipment`: - return `Equipment`; - case `fees`: - return `Fees`; - case `infrastructure`: - return `Infrastructure`; - case `insurance`: - return `Insurance`; - case `labor`: - return `Labor`; - case `materials`: - return `Materials`; - case `other`: - return `Other`; - case `supplies`: - return `Supplies`; - default: - return undefined; - } -}; - -export type ResolveEnumBudgetSpendingTypeKey = `Equipment` | `Labor` | `Maintenance` | `Other` | `Supplies` | `Utilities`; - -export const parse_enum_budget_spending_type_key = (val: string): ResolveEnumBudgetSpendingTypeKey | undefined => { - switch (val) { - case `equipment`: - return `Equipment`; - case `labor`: - return `Labor`; - case `maintenance`: - return `Maintenance`; - case `other`: - return `Other`; - case `supplies`: - return `Supplies`; - case `utilities`: - return `Utilities`; - default: - return undefined; - } -}; - -export type ResolveEnumPaymentMethodKey = `Cash`; - -export const parse_enum_payment_method_key = (val: string): ResolveEnumPaymentMethodKey | undefined => { - switch (val) { - case `cash`: - return `Cash`; - default: - return undefined; - } -}; - -export type ResolveEnumPaymentPeriodKey = `Biweekly` | `Hourly` | `Monthly` | `Weekly`; - -export const parse_enum_payment_period_key = (val: string): ResolveEnumPaymentPeriodKey | undefined => { - switch (val) { - case `biweekly`: - return `Biweekly`; - case `hourly`: - return `Hourly`; - case `monthly`: - return `Monthly`; - case `weekly`: - return `Weekly`; - default: - return undefined; - } -}; - -export type ResolveEnumPaymentStatusKey = `Confirmed` | `Pending`; - -export const parse_enum_payment_status_key = (val: string): ResolveEnumPaymentStatusKey | undefined => { - switch (val) { - case `confirmed`: - return `Confirmed`; - case `pending`: - return `Pending`; - default: - return undefined; - } -}; - -export type ResolveEnumQuantityUnitKey = `G` | `Kg` | `Lb` | `Ton`; - -export const parse_enum_quantity_unit_key = (val: string): ResolveEnumQuantityUnitKey | undefined => { - switch (val) { - case `g`: - return `G`; - case `kg`: - return `Kg`; - case `lb`: - return `Lb`; - case `ton`: - return `Ton`; - default: - return undefined; - } -}; - -export type ResolveEnumWorkerTypeKey = `Contractor` | `Laborer`; - -export const parse_enum_worker_type_key = (val: string): ResolveEnumWorkerTypeKey | undefined => { - switch (val) { - case `contractor`: - return `Contractor`; - case `laborer`: - return `Laborer`; - default: - return undefined; - } -}; -\ No newline at end of file diff --git a/utils/src/app/util/resolve.ts b/utils/src/app/util/resolve.ts @@ -1,5 +0,0 @@ -import { ResolveAddressInfo } from "../types/resolve"; - -export const lib_address_fmt = (addr: ResolveAddressInfo): string => { - return `${addr.primary}, ${addr.admin}, ${addr.country}` -}; -\ No newline at end of file diff --git a/utils/src/app/validation/view.ts b/utils/src/app/validation/view.ts @@ -1,27 +0,0 @@ -import { form_fields, IViewFarmsAddSubmission, IViewFarmsProductsAddSubmission, util_rxp, vs_geolocation_address, vs_geolocation_point, zod_numf_pos, zod_numf_price, zod_numi_pos } from "$root"; -import { _env } from "src/_env"; -import { z } from "zod"; - -export const vs_view_farms_products_add_submission: z.ZodSchema<IViewFarmsProductsAddSubmission> = z.object({ - product: z.string().regex(form_fields.product_key.validate), - process: z.string().regex(form_fields.product_process.validate), - description: z.string().regex(form_fields.product_description.validate), - price_amount: zod_numf_price, - price_currency: z.string().regex(form_fields.price_currency.validate), - price_quantity_unit: z.string().regex(form_fields.quantity_unit.validate), - photos: z.array(z.string().regex(_env.PROD ? util_rxp.url_image_upload : util_rxp.url_image_upload_dev)), - quantity_amount: zod_numi_pos, - quantity_unit: z.string().regex(form_fields.quantity_unit.validate), - quantity_label: z.string().regex(form_fields.quantity_label.validate), - geolocation_point: vs_geolocation_point, - geolocation_address: vs_geolocation_address, -}); - -export const vs_view_farms_add_submission: z.ZodSchema<IViewFarmsAddSubmission> = z.object({ - farm_name: z.string().regex(form_fields.farm_name.validate), - farm_area: zod_numf_pos, - farm_area_unit: z.string().regex(form_fields.area_unit.validate), - farm_contact_name: z.string().regex(form_fields.contact_name.validate), - geolocation_point: vs_geolocation_point, - geolocation_address: vs_geolocation_address, -}); diff --git a/utils/src/geo.ts b/utils/src/geo.ts @@ -1,7 +1,11 @@ -import { GeolocationPointTuple, GeometryPoint, ResolveAddressInfo, ResolveGeometryPoint } from "$root"; +import { GeolocationPointTuple, GeometryPoint } from "$root"; import { decodeBase32, encodeBase32 } from "geohashing"; -export type GeolocationAddress = Omit<ResolveAddressInfo, "id" | "created_at" | "updated_at">; +export type GeolocationAddress = { + primary: string; + admin: string; + country: string; +}; export type GeolocationPoint = { lat: number; @@ -75,13 +79,13 @@ export const parse_geol_coords = (number: number): number => { return Math.round(number * 1e7) / 1e7; }; -export const parse_geolocation_address = (addr?: ResolveAddressInfo): GeolocationAddress | undefined => { +export const parse_geolocation_address = (addr?: GeolocationAddress): GeolocationAddress | undefined => { if (!addr) return undefined; const { primary, admin, country } = addr; return { primary, admin, country }; }; -export const parse_geolocation_point = (point?: ResolveGeometryPoint): GeolocationPoint | undefined => { +export const parse_geolocation_point = (point?: GeometryPoint): GeolocationPoint | undefined => { if (!point) return undefined; return { lat: point.coordinates[1], @@ -100,11 +104,11 @@ export const fmt_geocode_address = (geoc: GeocoderReverseResult): string => { return addr ? `${addr.primary}, ${addr.admin}, ${addr.country}` : ``; }; -export const fmt_geolocation_address = (addr: ResolveAddressInfo): string => { +export const fmt_geolocation_address = (addr: GeolocationAddress): string => { return `${addr.primary}, ${addr.admin}, ${addr.country}`; }; -export const fmt_geometry_point_coords = (point: ResolveGeometryPoint, locale: string): string => { +export const fmt_geometry_point_coords = (point: GeometryPoint, locale: string): string => { const lat = geol_lat_fmt(point.coordinates[0], `dms`, locale, 3); const lng = geol_lng_fmt(point.coordinates[1], `dms`, locale, 3); return `${lat}, ${lng}`; diff --git a/utils/src/i18n.ts b/utils/src/i18n.ts @@ -0,0 +1,51 @@ +import { Loader } from '@sveltekit-i18n/base'; +import type { Config as ConfigIcu, Parser as ParserIcu } from "@sveltekit-i18n/parser-icu"; +import parser_icu from "@sveltekit-i18n/parser-icu"; +import i18n, { type Config } from 'sveltekit-i18n'; + +type LanguageConfig = { + default?: string; + value?: string; +}; + +const lib_config: Config<LanguageConfig> = { + initLocale: `en`, + fallbackLocale: `en`, + translations: {}, + loaders: [], +}; + +const lib_i18n = new i18n(lib_config); +export type I18nTranslateFunction = typeof lib_i18n.t; +export type I18nTranslateLocale = typeof lib_i18n.locale; + +export const i18n_conf = <T extends string>(opts: { + default_locale: T; + translations: Record<T, any>; + loaders: Loader.LoaderModule[] +}) => { + const { default_locale: initLocale, translations, loaders } = opts; + const config: Config<LanguageConfig> = { + initLocale, + fallbackLocale: initLocale, + translations, + loaders, + }; + return new i18n(config); +}; + +export const i18n_conf_icu = <T extends string>(opts: { + default_locale: T; + translations: Record<T, any>; + loaders: Loader.LoaderModule[] +}): i18n<ParserIcu.Params<LanguageConfig>> => { + const { default_locale: initLocale, translations, loaders } = opts; + const config: ConfigIcu<LanguageConfig> = { + initLocale, + fallbackLocale: initLocale, + translations, + parser: parser_icu(), + loaders, + }; + return new i18n(config); +}; +\ No newline at end of file diff --git a/utils/src/index.ts b/utils/src/index.ts @@ -1,43 +1,31 @@ -export * from "./*regex.js" -export * from "./*validation.js" -export * from "./app/document.js" -export * from "./app/i18n-icu.js" -export * from "./app/i18n.js" -export * from "./app/lib.js" -export * from "./app/styles.js" -export * from "./app/types/app.js" -export * from "./app/types/basis.js" -export * from "./app/types/component.js" -export * from "./app/types/element.js" -export * from "./app/types/geometry.js" -export * from "./app/types/glyph.js" -export * from "./app/types/interface.js" -export * from "./app/types/resolve.js" -export * from "./app/types/view.js" -export * from "./app/util/resolve-enum.js" -export * from "./app/util/resolve.js" -export * from "./app/util/search.js" -export * from "./app/util.js" -export * from "./app/validation/view.js" -export * from "./browser.js" -export * from "./client/database.js" -export * from "./client/datastore.js" -export * from "./client/geo.js" -export * from "./client/gui.js" -export * from "./config.js" -export * from "./currency.js" -export * from "./error.js" -export * from "./geo.js" -export * from "./http.js" -export * from "./image.js" -export * from "./lib.js" -export * from "./list.js" -export * from "./model.js" -export * from "./number.js" -export * from "./object.js" -export * from "./response.js" -export * from "./time.js" -export * from "./trade.js" -export * from "./types.js" -export * from "./unit.js" -export * from "./uuid.js" +export * from "./*regex" +export * from "./*validation" +export * from "./app/config" +export * from "./app/glyph" +export * from "./app/lib" +export * from "./app/search" +export * from "./app/styles" +export * from "./app/util" +export * from "./browser" +export * from "./client/database" +export * from "./client/datastore" +export * from "./client/geo" +export * from "./client/gui" +export * from "./config" +export * from "./currency" +export * from "./error" +export * from "./geo" +export * from "./http" +export * from "./i18n" +export * from "./image" +export * from "./lib" +export * from "./list" +export * from "./model" +export * from "./number" +export * from "./object" +export * from "./response" +export * from "./time" +export * from "./trade" +export * from "./types" +export * from "./unit" +export * from "./uuid" diff --git a/utils/src/lib.ts b/utils/src/lib.ts @@ -1,5 +1,3 @@ -import { CallbackPromise } from "$root"; - export const ascii = { bullet: '•', dash: `—`, @@ -30,7 +28,7 @@ export const str_trunc = (val: string, max_length: number = 28): string => { return `${val.slice(0, max_length - 3)}...`; }; -export const exe_iter = async (callback: CallbackPromise, num: number = 1, delay: number = 400): Promise<void> => { +export const exe_iter = async (callback: () => Promise<void>, num: number = 1, delay: number = 400): Promise<void> => { try { const iter_fn = (count: number) => { if (count > 0) { diff --git a/utils/src/types.ts b/utils/src/types.ts @@ -27,3 +27,10 @@ export type ResultSecretKey = { secret_key: string; }; export type FileBytesFormat = `kb` | `mb` | `gb`; export type FileMimeType = string; export type FilePath = { file_path: string; file_name: string; mime_type: FileMimeType; } + +export type CallbackPromise = () => Promise<void>; +export type CallbackPromiseFigureResult<Ti, Tr> = (value: Ti) => Promise<Tr | undefined>; +export type CallbackPromiseFull<Ti, Tr> = (value: Ti) => Promise<Tr>; +export type CallbackPromiseGeneric<T> = (value: T) => Promise<void>; +export type CallbackPromiseReturn<T> = () => Promise<T>; +export type CallbackPromiseResult<Tr> = () => Promise<Tr | undefined>; diff --git a/utils/src/unit.ts b/utils/src/unit.ts @@ -1,10 +1,10 @@ -import type { vunion_area_unit, vunion_mass_unit } from "$root"; +import type { vu_area_unit, vu_mass_unit } from "$root"; import { z } from "zod"; -export type AreaUnit = z.infer<typeof vunion_area_unit>; +export type AreaUnit = z.infer<typeof vu_area_unit>; export const area_units: AreaUnit[] = [`ac`, `ha`, `ft2`, `m2`] as const; -export type MassUnit = z.infer<typeof vunion_mass_unit>; +export type MassUnit = z.infer<typeof vu_mass_unit>; export const mass_units: MassUnit[] = [`kg`, `lb`, `g`] as const; export function parse_mass_unit_default(val?: string): MassUnit {