var t = ` ` import Preview from './preview.js' export default { components: { Preview }, props: ['uri', 'small', 'initialQuery'], emits: ['finder-selection'], data() { return { query: '', items: [], selected: 0, preview: true, } }, methods: { handleSelection(selected) { this.$emit('finder-selection', selected !== null ? this.filteredItems[selected] : null); }, selectUp() { if (this.selected !== 0) { this.selected -= 1; this.scrollIntoView(`item${this.selected}`) } }, selectDown() { if (this.selected !== this.filteredItems.length - 1) { this.selected += 1; this.scrollIntoView(`item${this.selected}`) } }, scrollIntoView(id) { document.getElementById(id).scrollIntoView({ block: 'nearest' }); }, fetchRaw(uri) { this.query = ''; this.selected = 0; fetch(uri) .then(response => response.text()) .then(text => { const PATTERN = /^(.*?):(.*?):\s*(?:\x1b\[0;36m(.*?)\x1b\[0m\s*)?(.*)$/ this.items = text.trim().split('\n').map(line => { const matches = PATTERN.exec(line); if (!matches) return null; const Filename = matches[1]; const Linenum = parseInt(matches[2], 10); const Colored = matches[3] || ''; const Content = matches[4]; const SearchStr = Colored ? `${Colored} ${Content}`.toLowerCase() : Content.toLowerCase(); return { Filename, Linenum, Colored, Content, SearchStr }; }).filter(Boolean); }); }, }, computed: { itemsLength() { return this.items.length; }, filteredItems() { this.selected = 0; const maxItems = 300; const queryWords = this.query.toLowerCase().split(' '); return !this.query ? this.items.slice(0, maxItems) : this.items.filter(item => (queryWords.every(queryWord => item.SearchStr.includes(queryWord)))).slice(0, maxItems); }, }, created() { this.preview = this.small ? false : this.preview; this.fetchRaw(this.uri); this.$nextTick(() => { this.query = this.initialQuery ? this.initialQuery : ''; this.$refs.queryInput.focus(); }); }, template: t }