commit 556d8259964b7588915521e027e77330c82386c7
parent 729c9239718d00a43cb55dd9746cd2f75a6979f8
Author: triesap <137732411+triesap@users.noreply.github.com>
Date: Tue, 29 Apr 2025 04:29:00 +0000
utils: add/edit utils
Diffstat:
8 files changed, 69 insertions(+), 13 deletions(-)
diff --git a/utils/src/*regex.ts b/utils/src/*regex.ts
@@ -38,8 +38,10 @@ export const util_rxp = {
ws_proto: /^(wss:\/\/|ws:\/\/)/,
quantity_unit: /^(kg|lb|g)$/,
quantity_unit_ch: /[A-Za-z]$/,
- url_image_upload: /^blob:https:\/\/domain\.tld\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,
- url_image_upload_dev: /^blob:http:\/\/localhost:\d+\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,
+ url_image_upload: /^file:\/\/.*\.(png|jpg|jpeg|gif|webp|bmp|svg)$/,
+ ///^blob:https:\/\/domain\.tld\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,
+ url_image_upload_dev: /^file:\/\/.*\.(png|jpg|jpeg|gif|webp|bmp|svg)$/,
+ // /^blob:http:\/\/localhost:\d+\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,
country_code_a2: /^[A-Za-z]{2}$/,
addr_primary: /[a-zA-Z0-9., ]$/,
addr_admin: /[a-zA-Z0-9., ]$/,
diff --git a/utils/src/app/lib.ts b/utils/src/app/lib.ts
@@ -2,8 +2,8 @@ import type { CallbackPromise, CallbackPromiseGeneric } from "$root";
export type IViewBasis<T extends object> = {
kv_init_prevent?: boolean;
- lc_on_mount?: CallbackPromise;
- lc_on_destroy?: CallbackPromise;
+ on_mount?: CallbackPromise;
+ on_destroy?: CallbackPromise;
} & T;
diff --git a/utils/src/app/styles.ts b/utils/src/app/styles.ts
@@ -18,6 +18,7 @@ export type AppLayoutKeyHeight =
export type AppLayoutKeyWidth =
| `lo`
+ | `lo_line_entry`
| `lo_textdesc`;
export type AppHeightsResponsiveIOS = AppLayoutIOS<AppLayoutKeyHeight>;
diff --git a/utils/src/geo.ts b/utils/src/geo.ts
@@ -1,11 +1,6 @@
-import { type GeolocationPointTuple, type GeometryPoint } from "$root";
+import { LocationBasis, type GeolocationPointTuple, type GeometryPoint } from "$root";
import { decodeBase32, encodeBase32 } from "geohashing";
-export type GeolocationBasis = {
- point: GeolocationPoint;
- address?: GeolocationAddress;
-}
-
export type GeolocationAddress = {
primary: string;
admin: string;
@@ -98,6 +93,22 @@ export const parse_geolocation_point = (point?: GeometryPoint): GeolocationPoint
};
};
+export const geo_point_to_geometry = (point?: GeolocationPoint): GeometryPoint | undefined => {
+ if (!point) return undefined;
+ return {
+ type: 'Point',
+ coordinates: [point.lng, point.lat]
+ };
+};
+
+export const location_basis_to_geo_point = (basis?: LocationBasis): GeolocationPoint | undefined => {
+ if (!basis) return undefined;
+ return {
+ lat: basis.point.lat,
+ lng: basis.point.lng
+ };
+};
+
export const parse_geocode_address = (geoc?: GeocoderReverseResult): GeolocationAddress | undefined => {
if (!geoc) return undefined;
const { name: primary, admin1_name: admin, country_id: country } = geoc;
@@ -238,19 +249,22 @@ export const geo_bounds_calc = (lat: number, lng: number, distance_km: number):
};
};
-export const location_gcs_to_geolocation_basis = ({
+export const location_gcs_to_location_basis = ({
+ id,
lat,
lng,
gc_name: primary,
gc_admin1_name: admin,
gc_country_id: country,
}: {
+ id: string;
lat: number;
lng: number;
gc_name?: string;
gc_admin1_name?: string;
gc_country_id?: string;
-}): GeolocationBasis => ({
+}): LocationBasis => ({
+ id,
point: {
lat,
lng,
diff --git a/utils/src/index.ts b/utils/src/index.ts
@@ -21,6 +21,8 @@ export * from "./lib"
export * from "./list"
export * from "./listings/order"
export * from "./model"
+export * from "./models/farm"
+export * from "./models/location"
export * from "./number"
export * from "./object"
export * from "./response"
diff --git a/utils/src/models/farm.ts b/utils/src/models/farm.ts
@@ -0,0 +1,20 @@
+import type { LocationBasis } from "$root";
+
+export type FarmExtended = {
+ farm: FarmBasis;
+ location?: LocationBasis;
+ lots?: FarmLotBasis[];
+};
+
+export type FarmBasis = {
+ id: string;
+ name: string;
+ area?: string;
+ area_unit?: string;
+};
+
+export type FarmLotBasis = {
+ id: string;
+ location?: LocationBasis;
+};
+
diff --git a/utils/src/models/location.ts b/utils/src/models/location.ts
@@ -0,0 +1,7 @@
+import { GeolocationAddress, GeolocationPoint } from "$root";
+
+export type LocationBasis = {
+ id: string;
+ point: GeolocationPoint;
+ address?: GeolocationAddress;
+};
+\ No newline at end of file
diff --git a/utils/src/trade.ts b/utils/src/trade.ts
@@ -43,8 +43,11 @@ const trade_quantity_default: TradeQuantity[] = [
},
];
+const TRADE_PROCESS_DEFAULT = `natural`;
+
+//@todo
const trade_process_default: string[] = [
- `natural`,
+ TRADE_PROCESS_DEFAULT,
`dried`,
`roasted`
];
@@ -60,6 +63,7 @@ export type TradeParam = {
flavor: string[];
}>;
};
+
export const trade: TradeParam = {
default: {
quantity: trade_quantity_default,
@@ -207,6 +211,11 @@ export function parse_trade_key(val?: string): TradeKey | undefined {
};
};
+export const trade_key_default_process = (val?: string): string => {
+ const key = parse_trade_key(val);
+ if (!key) return TRADE_PROCESS_DEFAULT;
+ return trade.key[key].process[0];
+};
export function parse_trade_mass_tuple(val?: string): [number, MassUnit, string] | undefined {
if (!val) return;