From cb2323bd828c564aa0847d6f172c452893f80098 Mon Sep 17 00:00:00 2001 From: bobzel Date: Fri, 16 May 2025 14:03:23 -0400 Subject: made pdf buttons maintain scren size. --- src/client/util/SearchUtil.ts | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'src/client/util/SearchUtil.ts') diff --git a/src/client/util/SearchUtil.ts b/src/client/util/SearchUtil.ts index fc3bb99ab..17c4af9d1 100644 --- a/src/client/util/SearchUtil.ts +++ b/src/client/util/SearchUtil.ts @@ -8,6 +8,13 @@ import { DocOptions, FInfo } from '../documents/Documents'; export namespace SearchUtil { export type HighlightingResult = { [id: string]: { [key: string]: string[] } }; + /** + * Recursively search all Docs within the collection for the query string. + * @param {Doc} collectionDoc - The collection document to search within. + * @param {string} queryIn - The query string to search for. + * @param {boolean} matchKeyNames - Whether to match metadata field names in addition to field values + * @param {string[]} onlyKeys - Optional: restrict search to only look in the specified array of field names. + */ export function SearchCollection(collectionDoc: Opt, queryIn: string, matchKeyNames: boolean, onlyKeys?: string[]) { const blockedTypes = [DocumentType.PRESSLIDE, DocumentType.CONFIG, DocumentType.KVP, DocumentType.FONTICON, DocumentType.BUTTON, DocumentType.SCRIPTING]; const blockedKeys = matchKeyNames @@ -27,11 +34,13 @@ export namespace SearchUtil { const dtype = StrCast(doc.type) as DocumentType; if (dtype && !blockedTypes.includes(dtype) && !docIDs.includes(doc[Id]) && depth >= 0) { const hlights = new Set(); - (onlyKeys ?? SearchUtil.documentKeys(doc)).forEach( - key => - (val => (exact ? val === query.toLowerCase() : val.includes(query.toLowerCase())))( - matchKeyNames ? key : Field.toString(doc[key] as FieldType)) - && hlights.add(key) + const fieldsToSearch = onlyKeys ?? SearchUtil.documentKeys(doc); + fieldsToSearch.forEach( + key => { + const val = (matchKeyNames ? key : Field.toString(doc[key] as FieldType)).toLowerCase(); + const accept = (exact ? val === query.toLowerCase() : val.includes(query.toLowerCase())); + accept && hlights.add(key); + } ); // prettier-ignore blockedKeys.forEach(key => hlights.delete(key)); @@ -45,18 +54,17 @@ export namespace SearchUtil { return results; } /** - * @param {Doc} doc - doc for which keys are returned + * @param {Doc} doc - Doc to search for used field names * - * This method returns a list of a document doc's keys. + * An array of all field names used by the Doc or its prototypes. */ export function documentKeys(doc: Doc) { - const keys: { [key: string]: boolean } = {}; - Doc.GetAllPrototypes(doc).map(proto => - Object.keys(proto).forEach(key => { - keys[key] = false; - }) - ); - return Array.from(Object.keys(keys)); + return Object.keys(Doc.GetAllPrototypes(doc).reduce( + (keys, proto) => { + Object.keys(proto).forEach(keys.add); + return keys; + }, + new Set())); // prettier-ignore } /** -- cgit v1.2.3-70-g09d2 From 9eb4669477eb03fb404b11eec41e09a93ec15425 Mon Sep 17 00:00:00 2001 From: bobzel Date: Mon, 19 May 2025 10:32:35 -0400 Subject: fix crash from last. --- src/client/util/SearchUtil.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/client/util/SearchUtil.ts') diff --git a/src/client/util/SearchUtil.ts b/src/client/util/SearchUtil.ts index 17c4af9d1..2f23d07dc 100644 --- a/src/client/util/SearchUtil.ts +++ b/src/client/util/SearchUtil.ts @@ -59,9 +59,9 @@ export namespace SearchUtil { * An array of all field names used by the Doc or its prototypes. */ export function documentKeys(doc: Doc) { - return Object.keys(Doc.GetAllPrototypes(doc).reduce( + return Object.keys(Doc.GetAllPrototypes(doc).filter(proto => proto).reduce( (keys, proto) => { - Object.keys(proto).forEach(keys.add); + Object.keys(proto).forEach(keys.add.bind(keys)); return keys; }, new Set())); // prettier-ignore -- cgit v1.2.3-70-g09d2