diff options
Diffstat (limited to 'src/ClientUtils.ts')
-rw-r--r-- | src/ClientUtils.ts | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/src/ClientUtils.ts b/src/ClientUtils.ts index e7aee1c2a..e1f490c1a 100644 --- a/src/ClientUtils.ts +++ b/src/ClientUtils.ts @@ -1,4 +1,4 @@ -import * as Color from 'color'; +import Color from 'color'; import * as React from 'react'; import { ColorResult } from 'react-color'; import * as rp from 'request-promise'; @@ -107,12 +107,12 @@ export namespace ClientUtils { default: return type.charAt(0).toUpperCase() + type.substring(1,3); } // prettier-ignore } - export function cleanDocumentType(type: DocumentType, colType: CollectionViewType) { + export function cleanDocumentType(type: DocumentType, colType?: CollectionViewType) { switch (type) { case DocumentType.PDF: return 'PDF'; case DocumentType.IMG: return 'Image'; case DocumentType.AUDIO: return 'Audio'; - case DocumentType.COL: return 'Collection:'+colType; + case DocumentType.COL: return 'Collection:'+ (colType ?? ""); case DocumentType.RTF: return 'Text'; default: return type.charAt(0).toUpperCase() + type.slice(1); } // prettier-ignore @@ -144,15 +144,20 @@ export namespace ClientUtils { export async function convertDataUri(imageUri: string, returnedFilename: string, nosuffix = false, replaceRootFilename: string | undefined = undefined) { try { const posting = ClientUtils.prepend('/uploadURI'); - const returnedUri = await rp.post(posting, { - body: { - uri: imageUri, - name: returnedFilename, - nosuffix, - replaceRootFilename, - }, - json: true, - }); + const returnedUri = await rp + .post(posting, { + body: { + uri: imageUri, + name: returnedFilename, + nosuffix, + replaceRootFilename, + }, + json: true, + }) + .catch(e => { + alert('Data URI Error: ' + e.toString()); + return undefined; + }); return returnedUri; } catch (e) { console.log('ConvertDataURI :' + e); @@ -165,7 +170,7 @@ export namespace ClientUtils { return { scale: 0, translateX: 1, translateY: 1 }; } const rect = ele.getBoundingClientRect(); - const scale = ele.offsetWidth === 0 && rect.width === 0 ? 1 : rect.width / ele.offsetWidth; + const scale = ele.offsetWidth === 0 && rect.width === 0 ? 1 : rect.width / (ele.offsetWidth || 1); const translateX = rect.left; const translateY = rect.top; @@ -212,7 +217,7 @@ export namespace ClientUtils { return { r: r, g: g, b: b, a: a }; } - const isTransparentFunctionHack = 'isTransparent(__value__)'; + export const isTransparentFunctionHack = 'isTransparent(__value__)'; export const noRecursionHack = '__noRecursion'; // special case filters @@ -223,11 +228,6 @@ export namespace ClientUtils { export function IsRecursiveFilter(val: string) { return !val.includes(noRecursionHack); } - export function HasFunctionFilter(val: string) { - if (val.includes(isTransparentFunctionHack)) return (color: string) => color !== '' && DashColor(color).alpha() !== 1; - // add other function filters here... - return undefined; - } export function toRGBAstr(col: { r: number; g: number; b: number; a?: number }) { return 'rgba(' + col.r + ',' + col.g + ',' + col.b + (col.a !== undefined ? ',' + col.a : '') + ')'; @@ -365,6 +365,15 @@ export namespace ClientUtils { } } +/** + * Removes specified keys from an object and returns the result in the 'omit' field of the return value. + * The keys that were removed ared retuned in the 'extract' field of the return value. + * @param obj - object to remove keys from + * @param keys - list of key field names to remove + * @param pattern - optional pattern to specify keys to removed + * @param addKeyFunc - optional function to call with object after keys have been removed + * @returns a tuple object containint 'omit' (oject after keys have been removed) and 'extact' (object containing omitted fields) + */ export function OmitKeys(obj: object, keys: string[], pattern?: string, addKeyFunc?: (dup: object) => void): { omit: { [key: string]: unknown }; extract: { [key: string]: unknown } } { const omit: { [key: string]: unknown } = { ...obj }; const extract: { [key: string]: unknown } = {}; @@ -590,7 +599,7 @@ export function StopEvent(e: React.PointerEvent | React.MouseEvent | React.Keybo export function setupMoveUpEvents( target: object, - e: React.PointerEvent, + e: React.PointerEvent | PointerEvent, moveEvent: (e: PointerEvent, down: number[], delta: number[]) => boolean, upEvent: (e: PointerEvent, movement: number[], isClick: boolean) => void, clickEvent: (e: PointerEvent, doubleTap?: boolean) => unknown, |