diff options
Diffstat (limited to 'src/client/util/SearchUtil.ts')
-rw-r--r-- | src/client/util/SearchUtil.ts | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/client/util/SearchUtil.ts b/src/client/util/SearchUtil.ts index fff2737b6..609fedfa9 100644 --- a/src/client/util/SearchUtil.ts +++ b/src/client/util/SearchUtil.ts @@ -1,5 +1,5 @@ import { ObservableMap } from 'mobx'; -import { Doc, DocListCast, Field, Opt } from '../../fields/Doc'; +import { Doc, DocListCast, Field, FieldType, Opt } from '../../fields/Doc'; import { Id } from '../../fields/FieldSymbols'; import { StrCast } from '../../fields/Types'; import { DocumentType } from '../documents/DocumentTypes'; @@ -8,16 +8,16 @@ import { DocOptions, FInfo } from '../documents/Documents'; export namespace SearchUtil { export type HighlightingResult = { [id: string]: { [key: string]: string[] } }; - export function SearchCollection(collectionDoc: Opt<Doc>, query: string, matchKeyNames: boolean, onlyKeys?: string[]) { + export function SearchCollection(collectionDoc: Opt<Doc>, queryIn: string, matchKeyNames: boolean, onlyKeys?: string[]) { const blockedTypes = [DocumentType.PRESELEMENT, DocumentType.CONFIG, DocumentType.KVP, DocumentType.FONTICON, DocumentType.BUTTON, DocumentType.SCRIPTING]; const blockedKeys = matchKeyNames ? [] : Object.entries(DocOptions) - .filter(([key, info]: [string, FInfo]) => !info?.searchable()) + .filter(([, info]: [string, FInfo]) => !info?.searchable()) .map(([key]) => key); - const exact = query.startsWith('='); - query = query.toLowerCase().split('=').lastElement(); + const exact = queryIn.startsWith('='); + const query = queryIn.toLowerCase().split('=').lastElement(); const results = new ObservableMap<Doc, string[]>(); if (collectionDoc) { @@ -30,7 +30,7 @@ export namespace SearchUtil { (onlyKeys ?? SearchUtil.documentKeys(doc)).forEach( key => (val => (exact ? val === query.toLowerCase() : val.includes(query.toLowerCase())))( - matchKeyNames ? key : Field.toString(doc[key] as Field)) + matchKeyNames ? key : Field.toString(doc[key] as FieldType)) && hlights.add(key) ); // prettier-ignore blockedKeys.forEach(key => hlights.delete(key)); @@ -51,7 +51,11 @@ export namespace SearchUtil { */ export function documentKeys(doc: Doc) { const keys: { [key: string]: boolean } = {}; - Doc.GetAllPrototypes(doc).map(proto => Object.keys(proto).forEach(key => (keys[key] = false))); + Doc.GetAllPrototypes(doc).map(proto => + Object.keys(proto).forEach(key => { + keys[key] = false; + }) + ); return Array.from(Object.keys(keys)); } @@ -62,16 +66,18 @@ export namespace SearchUtil { * This method iterates through an array of docs and all docs within those docs, calling * the function func on each doc. */ - export function foreachRecursiveDoc(docs: Doc[], func: (depth: number, doc: Doc) => void) { + export function foreachRecursiveDoc(docsIn: Doc[], func: (depth: number, doc: Doc) => void) { + let docs = docsIn; let newarray: Doc[] = []; - var depth = 0; + let depth = 0; const visited: Doc[] = []; while (docs.length > 0) { newarray = []; + // eslint-disable-next-line no-loop-func docs.filter(d => d && !visited.includes(d)).forEach(d => { visited.push(d); const fieldKey = Doc.LayoutFieldKey(d); - const annos = !Field.toString(Doc.LayoutField(d) as Field).includes('CollectionView'); + const annos = !Field.toString(Doc.LayoutField(d) as FieldType).includes('CollectionView'); const data = d[annos ? fieldKey + '_annotations' : fieldKey]; data && newarray.push(...DocListCast(data)); const sidebar = d[fieldKey + '_sidebar']; |