diff --git a/docs/.vitepress/theme/components/ConfigGenerator.vue b/docs/.vitepress/theme/components/ConfigGenerator.vue index 59608dd..b1032bf 100644 --- a/docs/.vitepress/theme/components/ConfigGenerator.vue +++ b/docs/.vitepress/theme/components/ConfigGenerator.vue @@ -168,6 +168,29 @@ const SECTIONS = data.sections.map(section => { return { title: section.title, blocks } }) +/** The words a field is found by: its section, flag table, label, key and description, in lower case. */ +const SEARCH_TEXT = new Map(data.sections.flatMap(section => section.fields.map(field => + [field.path, [section.title, field.group, field.label, field.path, field.html.replace(/<[^>]*>/g, '')].join(' ').toLowerCase()] +))) + +// With the form at module scope, so the filter is still applied after a Details link and back +const filter = ref('') + +/** The sections with only the fields that contain every word typed, or all of them while the box is empty. */ +const visibleSections = computed(() => { + const words = filter.value.toLowerCase().split(/\s+/).filter(Boolean) + if (words.length === 0) return SECTIONS + const matches = (field: GeneratorField) => words.every(word => SEARCH_TEXT.get(field.path)?.includes(word)) + return SECTIONS.flatMap(section => { + const blocks = section.blocks.flatMap((block): Block[] => { + if ('field' in block) return matches(block.field) ? [block] : [] + const fields = block.fields.filter(matches) + return fields.length ? [{ ...block, fields }] : [] + }) + return blocks.length ? [{ ...section, blocks }] : [] + }) +}) + const fieldId = (field: GeneratorField) => 'ipp-cg-' + field.path @@ -241,7 +264,20 @@ onMounted(() => { -
+
+ + +
+

No options match "{{ filter }}".

+ +

{{ section.title }}