diff --git a/CHANGELOG.md b/CHANGELOG.md index fca34c2..de87ba2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to Nova Menu Search will be documented in this file. ## Unreleased +## 1.0.1 - 2026-09-14 + +- Fix internal search results adding Nova's base path twice when navigating. + ## 1.0.0 - 2026-09-12 - Add sidebar search for authorized Nova main-menu links. diff --git a/dist/js/menu-search.js b/dist/js/menu-search.js index 3531e43..d726f60 100644 --- a/dist/js/menu-search.js +++ b/dist/js/menu-search.js @@ -1 +1 @@ -(()=>{"use strict";var e,t={958(){function e(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r1&&void 0!==arguments[1]?arguments[1]:[];return(Array.isArray(t)?t:[]).flatMap(function(t){var o,u,i,l=String(null!==(o=null==t?void 0:t.name)&&void 0!==o?o:"").trim(),c=""===l?r:[].concat(e(r),[l]),s=String(null!==(u=null==t?void 0:t.method)&&void 0!==u?u:"GET").toUpperCase(),f=null!=t&&t.path&&"GET"===s?[{name:l,path:t.path,external:!0===t.external,target:null!==(i=t.target)&&void 0!==i?i:null,trail:c,searchableText:n(c.join(" "))}]:[];return[].concat(f,e(a(null==t?void 0:t.items,c)))})}function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}function u(e){return function(e){if(Array.isArray(e))return i(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return i(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r2&&void 0!==arguments[2]?arguments[2]:10,a=n(t).split(" ").filter(Boolean);if(0===a.length)return[];var o=new Set;return e.filter(function(e){return a.every(function(t){return e.searchableText.includes(t)})}).filter(function(e){var t="".concat(e.path,"\0").concat(e.name);return!o.has(t)&&(o.add(t),!0)}).slice(0,Math.max(1,Number(r)||10))}(l(),t,o.maxResults);if(e.root.dataset.active=""===t.trim()?"false":"true",e.results.replaceChildren(),""!==t.trim()){if(0===r.length){var a=document.createElement("p");return a.className="nova-menu-search__empty",a.textContent=o.noResults,void e.results.append(a)}r.forEach(function(t){var r,n=document.createElement("a"),a=document.createElement("span"),o=document.createElement("span");(n.className="nova-menu-search__result",n.href=t.path,o.className="nova-menu-search__result-name",o.textContent=t.name,n.append(o),t.trail.length>1&&(a.className="nova-menu-search__result-trail",a.textContent=t.trail.slice(0,-1).join(" / "),n.append(a)),t.external)?(n.rel="noreferrer noopener",n.target=null!==(r=t.target)&&void 0!==r?r:"_blank"):n.addEventListener("click",function(r){r.preventDefault(),e.input.value="",s(e),Nova.visit(t.path)});e.results.append(n)})}},f=function(e){if(!i.has(e)){var r=document.createElement("div"),n=document.createElement("div"),a=document.createElement("span"),u=document.createElement("input"),l=document.createElement("kbd"),f=document.createElement("div");r.className="nova-menu-search",r.dataset.active="false",n.className="nova-menu-search__field",a.className="nova-menu-search__icon",a.setAttribute("aria-hidden","true"),a.textContent="⌕",u.className="nova-menu-search__input",u.type="search",u.autocomplete="off",u.spellcheck=!1,u.placeholder=o.placeholder,u.setAttribute("aria-label",o.label),f.className="nova-menu-search__results",f.setAttribute("aria-live","polite"),o.shortcut?(l.className="nova-menu-search__shortcut",l.textContent=o.shortcut.replace("mod",navigator.platform.includes("Mac")?"⌘":"Ctrl").replace("+"," "),n.append(a,u,l)):n.append(a,u),r.append(n,f),e.before(r);var m={root:r,input:u,results:f},p=t.watch(function(){return t.getters.mainMenu},function(){return s(m)},{deep:!0});u.addEventListener("input",function(){return s(m)}),u.addEventListener("keydown",function(e){"Escape"===e.key&&(u.value="",s(m),u.blur())}),i.set(e,c(c({},m),{},{stopWatching:p}))}},m=function(){i.forEach(function(e,t){t.isConnected||(e.stopWatching(),i.delete(t))}),document.querySelectorAll(".sidebar-menu").forEach(f)};new MutationObserver(m).observe(document.body,{childList:!0,subtree:!0}),m(),o.shortcut&&Nova.addShortcut(o.shortcut,function(e){var t=u(i.values()).map(function(e){return e.input}).find(function(e){return null!==e.offsetParent});t&&(null==e||e.preventDefault(),t.focus())})})},86(){}},r={};function n(e){var a=r[e];if(void 0!==a)return a.exports;var o=r[e]={exports:{}};return t[e](o,o.exports,n),o.exports}n.m=t,e=[],n.O=(t,r,a,o)=>{if(!r){var u=1/0;for(s=0;s=o)&&Object.keys(n.O).every(e=>n.O[e](r[l]))?r.splice(l--,1):(i=!1,o0&&e[s-1][2]>o;s--)e[s]=e[s-1];e[s]=[r,a,o]},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={864:0,507:0};n.O.j=t=>0===e[t];var t=(t,r)=>{var a,o,[u,i,l]=r,c=0;if(u.some(t=>0!==e[t])){for(a in i)n.o(i,a)&&(n.m[a]=i[a]);if(l)var s=l(n)}for(t&&t(r);cn(958));var a=n.O(void 0,[507],()=>n(86));a=n.O(a)})(); \ No newline at end of file +(()=>{"use strict";var e,t={856(){function e(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r1&&void 0!==arguments[1]?arguments[1]:[];return(Array.isArray(t)?t:[]).flatMap(function(t){var o,u,i,l=String(null!==(o=null==t?void 0:t.name)&&void 0!==o?o:"").trim(),c=""===l?r:[].concat(e(r),[l]),s=String(null!==(u=null==t?void 0:t.method)&&void 0!==u?u:"GET").toUpperCase(),f=null!=t&&t.path&&"GET"===s?[{name:l,path:t.path,external:!0===t.external,target:null!==(i=t.target)&&void 0!==i?i:null,trail:c,searchableText:n(c.join(" "))}]:[];return[].concat(f,e(a(null==t?void 0:t.items,c)))})}function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}function u(e){return function(e){if(Array.isArray(e))return i(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return i(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r2&&void 0!==arguments[2]?arguments[2]:10,a=n(t).split(" ").filter(Boolean);if(0===a.length)return[];var o=new Set;return e.filter(function(e){return a.every(function(t){return e.searchableText.includes(t)})}).filter(function(e){var t="".concat(e.path,"\0").concat(e.name);return!o.has(t)&&(o.add(t),!0)}).slice(0,Math.max(1,Number(r)||10))}(l(),t,o.maxResults);if(e.root.dataset.active=""===t.trim()?"false":"true",e.results.replaceChildren(),""!==t.trim()){if(0===r.length){var a=document.createElement("p");return a.className="nova-menu-search__empty",a.textContent=o.noResults,void e.results.append(a)}r.forEach(function(t){var r,n=document.createElement("a"),a=document.createElement("span"),o=document.createElement("span");(n.className="nova-menu-search__result",n.href=t.path,o.className="nova-menu-search__result-name",o.textContent=t.name,n.append(o),t.trail.length>1&&(a.className="nova-menu-search__result-trail",a.textContent=t.trail.slice(0,-1).join(" / "),n.append(a)),t.external)?(n.rel="noreferrer noopener",n.target=null!==(r=t.target)&&void 0!==r?r:"_blank"):n.addEventListener("click",function(r){r.preventDefault(),e.input.value="",s(e),Nova.visit({url:t.path,remote:!1})});e.results.append(n)})}},f=function(e){if(!i.has(e)){var r=document.createElement("div"),n=document.createElement("div"),a=document.createElement("span"),u=document.createElement("input"),l=document.createElement("kbd"),f=document.createElement("div");r.className="nova-menu-search",r.dataset.active="false",n.className="nova-menu-search__field",a.className="nova-menu-search__icon",a.setAttribute("aria-hidden","true"),a.textContent="⌕",u.className="nova-menu-search__input",u.type="search",u.autocomplete="off",u.spellcheck=!1,u.placeholder=o.placeholder,u.setAttribute("aria-label",o.label),f.className="nova-menu-search__results",f.setAttribute("aria-live","polite"),o.shortcut?(l.className="nova-menu-search__shortcut",l.textContent=o.shortcut.replace("mod",navigator.platform.includes("Mac")?"⌘":"Ctrl").replace("+"," "),n.append(a,u,l)):n.append(a,u),r.append(n,f),e.before(r);var m={root:r,input:u,results:f},p=t.watch(function(){return t.getters.mainMenu},function(){return s(m)},{deep:!0});u.addEventListener("input",function(){return s(m)}),u.addEventListener("keydown",function(e){"Escape"===e.key&&(u.value="",s(m),u.blur())}),i.set(e,c(c({},m),{},{stopWatching:p}))}},m=function(){i.forEach(function(e,t){t.isConnected||(e.stopWatching(),i.delete(t))}),document.querySelectorAll(".sidebar-menu").forEach(f)};new MutationObserver(m).observe(document.body,{childList:!0,subtree:!0}),m(),o.shortcut&&Nova.addShortcut(o.shortcut,function(e){var t=u(i.values()).map(function(e){return e.input}).find(function(e){return null!==e.offsetParent});t&&(null==e||e.preventDefault(),t.focus())})})},236(){}},r={};function n(e){var a=r[e];if(void 0!==a)return a.exports;var o=r[e]={exports:{}};return t[e](o,o.exports,n),o.exports}n.m=t,e=[],n.O=(t,r,a,o)=>{if(!r){var u=1/0;for(s=0;s=o)&&Object.keys(n.O).every(e=>n.O[e](r[l]))?r.splice(l--,1):(i=!1,o0&&e[s-1][2]>o;s--)e[s]=e[s-1];e[s]=[r,a,o]},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={864:0,507:0};n.O.j=t=>0===e[t];var t=(t,r)=>{var a,o,[u,i,l]=r,c=0;if(u.some(t=>0!==e[t])){for(a in i)n.o(i,a)&&(n.m[a]=i[a]);if(l)var s=l(n)}for(t&&t(r);cn(856));var a=n.O(void 0,[507],()=>n(236));a=n.O(a)})(); \ No newline at end of file diff --git a/dist/mix-manifest.json b/dist/mix-manifest.json index 7c4a06e..e7c5aad 100644 --- a/dist/mix-manifest.json +++ b/dist/mix-manifest.json @@ -1,4 +1,4 @@ { - "/js/menu-search.js": "/js/menu-search.js?id=22f00acce6018c95418055e500df2516", + "/js/menu-search.js": "/js/menu-search.js?id=1caabc2f1cef8661feafc0727b865cb6", "/css/menu-search.css": "/css/menu-search.css?id=e2199a23537a67d51688b00bb51ad949" } diff --git a/resources/js/menu-search.js b/resources/js/menu-search.js index 089c5cf..a40a810 100644 --- a/resources/js/menu-search.js +++ b/resources/js/menu-search.js @@ -1,6 +1,7 @@ import { collectSearchableItems, filterSearchableItems, + internalNavigationTarget, } from './search' Nova.booted((_app, store) => { @@ -65,7 +66,7 @@ Nova.booted((_app, store) => { event.preventDefault() installation.input.value = '' renderResults(installation) - Nova.visit(item.path) + Nova.visit(internalNavigationTarget(item.path)) }) } diff --git a/resources/js/search.js b/resources/js/search.js index 5a8e779..88a4154 100644 --- a/resources/js/search.js +++ b/resources/js/search.js @@ -65,3 +65,7 @@ export function filterSearchableItems(items, query, maximumResults = 10) { }) .slice(0, Math.max(1, Number(maximumResults) || 10)) } + +export function internalNavigationTarget(path) { + return { url: path, remote: false } +} diff --git a/tests-js/search.test.js b/tests-js/search.test.js index 48072f4..c575ee0 100644 --- a/tests-js/search.test.js +++ b/tests-js/search.test.js @@ -4,6 +4,7 @@ import assert from 'node:assert/strict' import { collectSearchableItems, filterSearchableItems, + internalNavigationTarget, normalizeForSearch, } from '../resources/js/search.js' @@ -67,3 +68,10 @@ test('deduplicates links and respects the configured result limit', () => { ['/resources/users'] ) }) + +test('navigates to Nova menu URLs without prefixing the Nova base again', () => { + assert.deepEqual(internalNavigationTarget('/nova/resources/users'), { + url: '/nova/resources/users', + remote: false, + }) +})