From: blake Date: Tue, 12 May 2020 21:50:08 +0000 (-0500) Subject: LP#1848524: Docs: refreshed antora lunr search component from upstream X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=7427a21eb8b3ef4fab558081550506f08b00961d;p=evergreen%2Fequinox.git LP#1848524: Docs: refreshed antora lunr search component from upstream Signed-off-by: blake Signed-off-by: Galen Charlton --- diff --git a/docs-antora/ui/ui-lunr/js/vendor/lunr.js b/docs-antora/ui/ui-lunr/js/vendor/lunr.js index 8f0c4a10cc..c3537658a6 100644 --- a/docs-antora/ui/ui-lunr/js/vendor/lunr.js +++ b/docs-antora/ui/ui-lunr/js/vendor/lunr.js @@ -1,6 +1,6 @@ /** - * lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 2.3.3 - * Copyright (C) 2018 Oliver Nightingale + * lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 2.3.8 + * Copyright (C) 2019 Oliver Nightingale * @license MIT */ @@ -54,10 +54,10 @@ var lunr = function (config) { return builder.build() } -lunr.version = "2.3.3" +lunr.version = "2.3.8" /*! * lunr.utils - * Copyright (C) 2018 Oliver Nightingale + * Copyright (C) 2019 Oliver Nightingale */ /** @@ -177,7 +177,7 @@ lunr.FieldRef.prototype.toString = function () { } /*! * lunr.Set - * Copyright (C) 2018 Oliver Nightingale + * Copyright (C) 2019 Oliver Nightingale */ /** @@ -389,7 +389,7 @@ lunr.Token.prototype.clone = function (fn) { } /*! * lunr.tokenizer - * Copyright (C) 2018 Oliver Nightingale + * Copyright (C) 2019 Oliver Nightingale */ /** @@ -424,7 +424,7 @@ lunr.tokenizer = function (obj, metadata) { }) } - var str = obj.toString().trim().toLowerCase(), + var str = obj.toString().toLowerCase(), len = str.length, tokens = [] @@ -465,7 +465,7 @@ lunr.tokenizer = function (obj, metadata) { lunr.tokenizer.separator = /[\s\-]+/ /*! * lunr.Pipeline - * Copyright (C) 2018 Oliver Nightingale + * Copyright (C) 2019 Oliver Nightingale */ /** @@ -509,8 +509,8 @@ lunr.Pipeline.registeredFunctions = Object.create(null) * or mutate (or add) metadata for a given token. * * A pipeline function can indicate that the passed token should be discarded by returning - * null. This token will not be passed to any downstream pipeline functions and will not be - * added to the index. + * null, undefined or an empty string. This token will not be passed to any downstream pipeline + * functions and will not be added to the index. * * Multiple tokens can be returned by returning an array of tokens. Each token will be passed * to any downstream pipeline functions and all will returned tokens will be added to the index. @@ -673,9 +673,9 @@ lunr.Pipeline.prototype.run = function (tokens) { for (var j = 0; j < tokens.length; j++) { var result = fn(tokens[j], j, tokens) - if (result === void 0 || result === '') continue + if (result === null || result === void 0 || result === '') continue - if (result instanceof Array) { + if (Array.isArray(result)) { for (var k = 0; k < result.length; k++) { memo.push(result[k]) } @@ -732,7 +732,7 @@ lunr.Pipeline.prototype.toJSON = function () { } /*! * lunr.Vector - * Copyright (C) 2018 Oliver Nightingale + * Copyright (C) 2019 Oliver Nightingale */ /** @@ -929,7 +929,7 @@ lunr.Vector.prototype.toJSON = function () { /* eslint-disable */ /*! * lunr.stemmer - * Copyright (C) 2018 Oliver Nightingale + * Copyright (C) 2019 Oliver Nightingale * Includes code from - http://tartarus.org/~martin/PorterStemmer/js.txt */ @@ -1151,7 +1151,7 @@ lunr.stemmer = (function(){ lunr.Pipeline.registerFunction(lunr.stemmer, 'stemmer') /*! * lunr.stopWordFilter - * Copyright (C) 2018 Oliver Nightingale + * Copyright (C) 2019 Oliver Nightingale */ /** @@ -1316,7 +1316,7 @@ lunr.stopWordFilter = lunr.generateStopWordFilter([ lunr.Pipeline.registerFunction(lunr.stopWordFilter, 'stopWordFilter') /*! * lunr.trimmer - * Copyright (C) 2018 Oliver Nightingale + * Copyright (C) 2019 Oliver Nightingale */ /** @@ -1343,7 +1343,7 @@ lunr.trimmer = function (token) { lunr.Pipeline.registerFunction(lunr.trimmer, 'trimmer') /*! * lunr.TokenSet - * Copyright (C) 2018 Oliver Nightingale + * Copyright (C) 2019 Oliver Nightingale */ /** @@ -1460,50 +1460,58 @@ lunr.TokenSet.fromFuzzyString = function (str, editDistance) { if (frame.str.length == 1) { noEditNode.final = true - } else { - stack.push({ - node: noEditNode, - editsRemaining: frame.editsRemaining, - str: frame.str.slice(1) - }) } + + stack.push({ + node: noEditNode, + editsRemaining: frame.editsRemaining, + str: frame.str.slice(1) + }) + } + + if (frame.editsRemaining == 0) { + continue + } + + // insertion + if ("*" in frame.node.edges) { + var insertionNode = frame.node.edges["*"] + } else { + var insertionNode = new lunr.TokenSet + frame.node.edges["*"] = insertionNode + } + + if (frame.str.length == 0) { + insertionNode.final = true } + stack.push({ + node: insertionNode, + editsRemaining: frame.editsRemaining - 1, + str: frame.str + }) + // deletion // can only do a deletion if we have enough edits remaining // and if there are characters left to delete in the string - if (frame.editsRemaining > 0 && frame.str.length > 1) { - var char = frame.str.charAt(1), - deletionNode - - if (char in frame.node.edges) { - deletionNode = frame.node.edges[char] - } else { - deletionNode = new lunr.TokenSet - frame.node.edges[char] = deletionNode - } - - if (frame.str.length <= 2) { - deletionNode.final = true - } else { - stack.push({ - node: deletionNode, - editsRemaining: frame.editsRemaining - 1, - str: frame.str.slice(2) - }) - } + if (frame.str.length > 1) { + stack.push({ + node: frame.node, + editsRemaining: frame.editsRemaining - 1, + str: frame.str.slice(1) + }) } // deletion // just removing the last character from the str - if (frame.editsRemaining > 0 && frame.str.length == 1) { + if (frame.str.length == 1) { frame.node.final = true } // substitution // can only do a substitution if we have enough edits remaining // and if there are characters left to substitute - if (frame.editsRemaining > 0 && frame.str.length >= 1) { + if (frame.str.length >= 1) { if ("*" in frame.node.edges) { var substitutionNode = frame.node.edges["*"] } else { @@ -1513,40 +1521,19 @@ lunr.TokenSet.fromFuzzyString = function (str, editDistance) { if (frame.str.length == 1) { substitutionNode.final = true - } else { - stack.push({ - node: substitutionNode, - editsRemaining: frame.editsRemaining - 1, - str: frame.str.slice(1) - }) - } - } - - // insertion - // can only do insertion if there are edits remaining - if (frame.editsRemaining > 0) { - if ("*" in frame.node.edges) { - var insertionNode = frame.node.edges["*"] - } else { - var insertionNode = new lunr.TokenSet - frame.node.edges["*"] = insertionNode } - if (frame.str.length == 0) { - insertionNode.final = true - } else { - stack.push({ - node: insertionNode, - editsRemaining: frame.editsRemaining - 1, - str: frame.str - }) - } + stack.push({ + node: substitutionNode, + editsRemaining: frame.editsRemaining - 1, + str: frame.str.slice(1) + }) } // transposition // can only do a transposition if there are edits remaining // and there are enough characters to transpose - if (frame.editsRemaining > 0 && frame.str.length > 1) { + if (frame.str.length > 1) { var charA = frame.str.charAt(0), charB = frame.str.charAt(1), transposeNode @@ -1560,13 +1547,13 @@ lunr.TokenSet.fromFuzzyString = function (str, editDistance) { if (frame.str.length == 1) { transposeNode.final = true - } else { - stack.push({ - node: transposeNode, - editsRemaining: frame.editsRemaining - 1, - str: charA + frame.str.slice(2) - }) } + + stack.push({ + node: transposeNode, + editsRemaining: frame.editsRemaining - 1, + str: charA + frame.str.slice(2) + }) } } @@ -1619,6 +1606,10 @@ lunr.TokenSet.fromString = function (str) { * Converts this TokenSet into an array of strings * contained within the TokenSet. * + * This is not intended to be used on a TokenSet that + * contains wildcards, in these cases the results are + * undefined and are likely to cause an infinite loop. + * * @returns {string[]} */ lunr.TokenSet.prototype.toArray = function () { @@ -1836,7 +1827,7 @@ lunr.TokenSet.Builder.prototype.minimize = function (downTo) { } /*! * lunr.Index - * Copyright (C) 2018 Oliver Nightingale + * Copyright (C) 2019 Oliver Nightingale */ /** @@ -2289,7 +2280,7 @@ lunr.Index.load = function (serializedIndex) { var attrs = {}, fieldVectors = {}, serializedVectors = serializedIndex.fieldVectors, - invertedIndex = {}, + invertedIndex = Object.create(null), serializedInvertedIndex = serializedIndex.invertedIndex, tokenSetBuilder = new lunr.TokenSet.Builder, pipeline = lunr.Pipeline.load(serializedIndex.pipeline) @@ -2328,7 +2319,7 @@ lunr.Index.load = function (serializedIndex) { } /*! * lunr.Builder - * Copyright (C) 2018 Oliver Nightingale + * Copyright (C) 2019 Oliver Nightingale */ /** diff --git a/docs-antora/ui/ui-lunr/js/vendor/search.js b/docs-antora/ui/ui-lunr/js/vendor/search.js index b9f311386c..fcf4046150 100644 --- a/docs-antora/ui/ui-lunr/js/vendor/search.js +++ b/docs-antora/ui/ui-lunr/js/vendor/search.js @@ -112,7 +112,8 @@ window.antoraLunr = (function (lunr) { var documentHit = document.createElement('div') documentHit.classList.add('search-result-document-hit') var documentHitLink = document.createElement('a') - documentHitLink.href = item.ref + var rootPath = window.antora.basePath + documentHitLink.href = rootPath + item.ref documentHit.appendChild(documentHitLink) hits.forEach(function (hit) { documentHitLink.appendChild(hit) @@ -121,6 +122,9 @@ window.antoraLunr = (function (lunr) { searchResultItem.classList.add('search-result-item') searchResultItem.appendChild(documentTitle) searchResultItem.appendChild(documentHit) + searchResultItem.addEventListener('mousedown', function (e) { + e.preventDefault() + }) return searchResultItem } @@ -192,8 +196,14 @@ window.antoraLunr = (function (lunr) { var search = debounce(function () { searchIndex(index.index, index.store, searchInput.value) }, 100) - // TODO listen to blur, focus and input events searchInput.addEventListener('keydown', search) + + // this is prevented in case of mousedown attached to SearchResultItem + searchInput.addEventListener('blur', function (e) { + while (searchResult.firstChild) { + searchResult.removeChild(searchResult.firstChild) + } + }) } return { diff --git a/docs-antora/ui/ui-lunr/partials/footer-scripts.hbs b/docs-antora/ui/ui-lunr/partials/footer-scripts.hbs index 4c010eabdb..7d4519ea08 100644 --- a/docs-antora/ui/ui-lunr/partials/footer-scripts.hbs +++ b/docs-antora/ui/ui-lunr/partials/footer-scripts.hbs @@ -1,4 +1,4 @@ - {{/if}} - - + diff --git a/docs-antora/ui/ui-lunr/partials/header-content.hbs b/docs-antora/ui/ui-lunr/partials/header-content.hbs new file mode 100644 index 0000000000..bdc6271443 --- /dev/null +++ b/docs-antora/ui/ui-lunr/partials/header-content.hbs @@ -0,0 +1,35 @@ +