From 2290573124aa5c8a382e2690dd5c02234b2389a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20S=C3=B8derlind?= Date: Wed, 8 Jan 2025 11:00:22 +0100 Subject: [PATCH 1/2] Bump version to 1.7.3 and update changelog for improved search functionality --- .github/workflows/manual-deploy-release.yml | 28 +++++++++ CHANGELOG.md | 9 +++ build/index.asset.php | 2 +- build/index.js | 4 +- composer.json | 2 +- package.json | 2 +- readme.txt | 10 ++- src/modules/search.js | 70 +++++++++++++++++---- super-admin-all-sites-menu.php | 4 +- 9 files changed, 111 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/manual-deploy-release.yml diff --git a/.github/workflows/manual-deploy-release.yml b/.github/workflows/manual-deploy-release.yml new file mode 100644 index 0000000..5d8b9d3 --- /dev/null +++ b/.github/workflows/manual-deploy-release.yml @@ -0,0 +1,28 @@ +name: Manual Deploy Release to WordPress.org +on: + workflow_dispatch: + inputs: + tag: + description: 'Tag to deploy' + required: true + type: string + default: '' +jobs: + tag: + name: New tag + runs-on: ubuntu-latest + steps: + - name: Install Subversion + run: sudo apt-get update && sudo apt-get install -y subversion + + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.tag }} + + - name: WordPress Plugin Deploy + uses: 10up/action-wordpress-plugin-deploy@stable + env: + SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} + SVN_USERNAME: ${{ secrets.SVN_USERNAME }} + SLUG: super-admin-all-sites-menu diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d4616d..a688307 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +### 1.7.3 + +- Fixed search functionality: + - Improved search performance with better indexing + - Added mutation observer to handle dynamically loaded sites + - Fixed event handling for search input + - Added improved error handling for search elements + - Better handling of empty search inputs + ### 1.7.2 - Bump version to trigger a deploy to WordPress.org diff --git a/build/index.asset.php b/build/index.asset.php index 5d07ddd..32f9817 100644 --- a/build/index.asset.php +++ b/build/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-i18n'), 'version' => '598e59804b1aee3f1164'); + array('wp-api-fetch', 'wp-i18n'), 'version' => '9e5c51f6474ac97c1f9d'); diff --git a/build/index.js b/build/index.js index c359452..fd4205b 100644 --- a/build/index.js +++ b/build/index.js @@ -1,7 +1,7 @@ /*! * super-admin-all-sites-menu - * version: 1.7.0 + * version: 1.7.2 * address: https://github.com/soderlind/super-admin-all-sites-menu#readme * author: Per Søderlind * license: GPLv2 - */(()=>{var e={744:function(e,t,n){e.exports=function(){"use strict";var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(t,n)},t=function(){return(t=Object.assign||function(e){for(var t,n=1,r=arguments.length;n.",et="String expected.",tt=[],nt="__dbnames",rt="readonly",it="readwrite";function ot(e,t){return e?t?function(){return e.apply(this,arguments)&&t.apply(this,arguments)}:e:t}var at={type:3,lower:-1/0,lowerOpen:!1,upper:[[]],upperOpen:!1};function ut(e){return"string"!=typeof e||/\./.test(e)?function(e){return e}:function(t){return void 0===t[e]&&e in t&&delete(t=A(t))[e],t}}function st(){throw W.Type()}function ct(e,t){try{var n=lt(e),r=lt(t);if(n!==r)return"Array"===n?1:"Array"===r?-1:"binary"===n?1:"binary"===r?-1:"string"===n?1:"string"===r?-1:"Date"===n?1:"Date"!==r?NaN:-1;switch(n){case"number":case"Date":case"string":return tn+a&&i(n+h)}))}))}var o=mt(n)&&n.limit===1/0&&("function"!=typeof e||e===St)&&{index:n.index,range:n.range};return i(0).then((function(){if(0=i}))).length?(t.forEach((function(e){c.push((function(){var t=l,n=e._cfg.dbschema;hn(r,t,s),hn(r,n,s),l=r._dbSchema=n;var a=un(t,n);a.add.forEach((function(e){sn(s,e[0],e[1].primKey,e[1].indexes)})),a.change.forEach((function(e){if(e.recreate)throw new W.Upgrade("Not yet support for changing primary key");var t=s.objectStore(e.name);e.add.forEach((function(e){return ln(t,e)})),e.change.forEach((function(e){t.deleteIndex(e.name),ln(t,e)})),e.del.forEach((function(e){return t.deleteIndex(e)}))}));var c=e._cfg.contentUpgrade;if(c&&e._cfg.version>i){en(r,s),u._memoizedTables={};var f=k(n);a.del.forEach((function(e){f[e]=t[e]})),nn(r,[r.Transaction.prototype]),tn(r,[r.Transaction.prototype],o(f),f),u.schema=f;var h,d=R(c);return d&&$e(),a=xe.follow((function(){var e;(h=c(u))&&d&&(e=Ue.bind(null,null),h.then(e,e))})),h&&"function"==typeof h.then?xe.resolve(h):a.then((function(){return h}))}})),c.push((function(t){var n,i,o=e._cfg.dbschema;n=o,i=t,[].slice.call(i.db.objectStoreNames).forEach((function(e){return null==n[e]&&i.db.deleteObjectStore(e)})),nn(r,[r.Transaction.prototype]),tn(r,[r.Transaction.prototype],r._storeNames,r._dbSchema),u.schema=r._dbSchema})),c.push((function(t){r.idbdb.objectStoreNames.contains("$meta")&&(Math.ceil(r.idbdb.version/10)===e._cfg.version?(r.idbdb.deleteObjectStore("$meta"),delete r._dbSchema.$meta,r._storeNames=r._storeNames.filter((function(e){return"$meta"!==e}))):t.objectStore("$meta").put(e._cfg.version,"version"))}))})),function e(){return c.length?xe.resolve(c.shift()(u.idbtrans)).then(e):xe.resolve()}().then((function(){cn(l,s)}))):xe.resolve();var r,i,u,s,c,l})).catch(u)):(o(i).forEach((function(e){sn(n,e,i[e].primKey,i[e].indexes)})),en(e,n),void xe.follow((function(){return e.on.populate.fire(a)})).catch(u));var r,c}))}function an(e,t){cn(e._dbSchema,t),t.db.version%10!=0||t.objectStoreNames.contains("$meta")||t.db.createObjectStore("$meta").add(Math.ceil(t.db.version/10-1),"version");var n=fn(0,e.idbdb,t);hn(e,e._dbSchema,t);for(var r=0,i=un(n,e._dbSchema).change;rMath.pow(2,62)?0:r.oldVersion,h=r<1,e.idbdb=d.result,a&&an(e,f),on(e,r/10,f,c))}),c),d.onsuccess=Be((function(){f=null;var n,u,c,p,y,m=e.idbdb=d.result,b=v(m.objectStoreNames);if(0t.limit?n.length=t.limit:e.length===t.limit&&n.length=r.limit&&(!r.values||e.req.values)&&Xn(e.req.query.range,r.query.range)})),!1,i,o];case"count":return a=o.find((function(e){return Hn(e.req.query.range,r.query.range)})),[a,!!a,i,o]}}(n,r,"query",e),s=u[0],c=u[1],l=u[2],f=u[3];return s&&c?s.obsSet=e.obsSet:(c=i.query(e).then((function(e){var n=e.result;if(s&&(s.res=n),t){for(var r=0,i=n.length;r{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";function e(){const e=document.querySelector("#all-sites-search-text");if(!e)return;const t=document.querySelector("#wp-admin-bar-my-sites-list"),n=t?.getElementsByClassName("menupop")||[],r=Array.from(n).map((e=>({element:e,text:e.querySelector(".ab-item")?.textContent?.toUpperCase()||""}))),i=((e,t)=>{let n;return(...r)=>{clearTimeout(n),n=setTimeout((()=>e(...r)),t)}})((e=>{const t=e.toUpperCase();r.forEach((({element:e,text:n})=>{e.style.display=n.includes(t)?"":"none"}))}),150);e.addEventListener("keyup",(e=>{e.preventDefault(),i(e.target.value)}))}var t=n(744);const r=Symbol.for("Dexie"),i=globalThis[r]||(globalThis[r]=t);if(t.semVer!==i.semVer)throw new Error(`Two different versions of Dexie loaded in the same app: ${t.semVer} and ${i.semVer}`);const{liveQuery:o,mergeRanges:a,rangesOverlap:u,RangeSet:s,cmp:c,Entity:l,PropModSymbol:f,PropModification:h,replacePrefix:d,add:p,remove:y}=i;class m{#e;#t;#n;#r;constructor(e,t,n){this.#t=e,this.#n=t,this.#r=n,this.#e=this.#i()}#i(){const e=new i(this.#t);return this.#r.forEach(((t,n)=>{e.version(n+1).stores({[this.#n]:t})})),e}async save(e){try{await this.#e[this.#n].bulkPut(e)}catch(e){throw console.error("IndexedDB save error:",e),e}}async read(e="name"){try{return await this.#e[this.#n].orderBy(e).toArray()}catch(e){throw console.error("IndexedDB read error:",e),e}}async getFirstRow(){try{return await this.#e[this.#n].orderBy(":id").first()}catch(e){throw console.error("IndexedDB getFirstRow error:",e),e}}async delete(){try{await this.#e.delete(),this.#e=this.#i()}catch(e){throw console.error("IndexedDB delete error:",e),e}}async count(){try{return await this.#e[this.#n].count()}catch(e){throw console.error("IndexedDB count error:",e),e}}async getVersion(){try{return await this.#e.open().then((e=>e.verno))}catch(e){throw console.error("IndexedDB getVersion error:",e),e}}}const v=window.wp.apiFetch;var b=n.n(v);async function g(e,{offset:t=0,maxSites:n=1e3,delayMs:r=1e3}={}){try{if(n>0&&t>=n)return;b().use(b().createNonceMiddleware(pluginAllSitesMenu.nonce)),t>0&&await(i=r,new Promise((e=>setTimeout(e,i))));const o=await b()({url:pluginAllSitesMenu.restURL,method:"POST",data:{offset:t}});if(!o||"string"!=typeof o.response)throw new Error("Invalid response format");if("success"===o.response&&Array.isArray(o.data)){await e.save(o.data);return g(e,{offset:t+pluginAllSitesMenu.loadincrements,maxSites:n,delayMs:r})}}catch(e){throw console.error("Error in loadSites:",e.message),e}var i}function w(e,t){if(!e)return;e.classList&&e.classList.add?e.classList.add(t):x(e,t)||(e.className&&(e.className+=" "),e.className+=t);let n=e.getBoundingClientRect().top,r=e.querySelector(".ab-submenu");r.style.top=n-6+"px",r.getBoundingClientRect().bottom>window.innerHeight&&(r.style.top="auto",r.style.bottom="0")}function _(e,t){let n,r;if(e||x(e,t))if(e.classList&&e.classList.remove)e.classList.remove(t);else{for(n=` ${t} `,r=` ${e.className} `;r.indexOf(n)>-1;)r=r.replace(n,"");e.className=r.replace(/^[\s]+|[\s]+$/g,"")}}function x(e,t){let n;return!!e&&(e.classList&&e.classList.contains?e.classList.contains(t):!!e.className&&(n=e.className.split(" "),n.indexOf(t)>-1))}const k=window.wp.i18n;const O="allsites",P="sites",E=["id,name,url","id,name,url,timestamp"];document.addEventListener("DOMContentLoaded",(async function(){if(!document.getElementById("wpadminbar"))return;const t={load:document.querySelector("#wp-admin-bar-load-more"),menu:document.querySelector("#wp-admin-bar-my-sites-list"),timestamp:document.querySelector("#load-more-timestamp")};if(t.load&&t.menu)try{const n=new m(O,P,E);pluginAllSitesMenu.displaySearch&&e(),function(e){if(!e)return;const t=Array.from({length:11},((e,t)=>t/10)),n=e=>{if(!window.matchMedia("(min-width: 783px)").matches)return;const t=document.querySelector("#wp-admin-bar-my-sites>.ab-sub-wrapper"),n=t?.querySelector("ul#wp-admin-bar-my-sites-list");if(!t||!n)return;const r=e.boundingClientRect.bottome.forEach(n)),{threshold:t});r.observe(e)}(t.menu),await async function(e){const t=await e.getFirstRow();void 0!==t&&void 0!==t.timestamp&&pluginAllSitesMenu.timestamp>t.timestamp&&await e.delete();0===await e.count()&&g(e,{offset:0,delayMs:200})}(n),function(e,t){const n=function(e,t){if(!e||!t||!("IntersectionObserver"in window))return console.error("Invalid parameters or IntersectionObserver not supported"),null;const n=new IntersectionObserver((e=>{e.forEach((e=>e.isIntersecting&&t()))}),{threshold:.1});return n.observe(e),n}(e,(async()=>{const r=(await t.read(pluginAllSitesMenu.orderBy)).reduce(((e,t)=>e+function(e){return`\n\t\t\t\t\n\t\t`}(t)),"");e.insertAdjacentHTML("beforeBegin",r),function(){const e=document.getElementById("wp-admin-bar-my-sites-list");e&&(e.addEventListener("mouseenter",(e=>{e.stopPropagation(),e.target.classList.contains("menupop")&&w(e.target,"hover")}),{capture:!0}),e.addEventListener("mouseleave",(e=>{e.stopPropagation(),e.target.classList.contains("menupop")&&_(e.target,"hover")}),{capture:!0}),e.addEventListener("keydown",(e=>{"Tab"===e.key&&(e.preventDefault(),e.target.classList.contains("menupop")&&toggleClass(e.target,"hover"))}),{capture:!0}))}(),e.style.display="none",n.unobserve(e)}))}(t.load,n)}catch(e){console.error("Initialization failed:",e)}}))})()})(); \ No newline at end of file + */(()=>{var e={744:function(e,t,n){e.exports=function(){"use strict";var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(t,n)},t=function(){return(t=Object.assign||function(e){for(var t,n=1,r=arguments.length;n.",et="String expected.",tt=[],nt="__dbnames",rt="readonly",it="readwrite";function ot(e,t){return e?t?function(){return e.apply(this,arguments)&&t.apply(this,arguments)}:e:t}var at={type:3,lower:-1/0,lowerOpen:!1,upper:[[]],upperOpen:!1};function ut(e){return"string"!=typeof e||/\./.test(e)?function(e){return e}:function(t){return void 0===t[e]&&e in t&&delete(t=A(t))[e],t}}function st(){throw W.Type()}function ct(e,t){try{var n=lt(e),r=lt(t);if(n!==r)return"Array"===n?1:"Array"===r?-1:"binary"===n?1:"binary"===r?-1:"string"===n?1:"string"===r?-1:"Date"===n?1:"Date"!==r?NaN:-1;switch(n){case"number":case"Date":case"string":return tn+a&&i(n+h)}))}))}var o=mt(n)&&n.limit===1/0&&("function"!=typeof e||e===St)&&{index:n.index,range:n.range};return i(0).then((function(){if(0=i}))).length?(t.forEach((function(e){c.push((function(){var t=l,n=e._cfg.dbschema;hn(r,t,s),hn(r,n,s),l=r._dbSchema=n;var a=un(t,n);a.add.forEach((function(e){sn(s,e[0],e[1].primKey,e[1].indexes)})),a.change.forEach((function(e){if(e.recreate)throw new W.Upgrade("Not yet support for changing primary key");var t=s.objectStore(e.name);e.add.forEach((function(e){return ln(t,e)})),e.change.forEach((function(e){t.deleteIndex(e.name),ln(t,e)})),e.del.forEach((function(e){return t.deleteIndex(e)}))}));var c=e._cfg.contentUpgrade;if(c&&e._cfg.version>i){en(r,s),u._memoizedTables={};var f=k(n);a.del.forEach((function(e){f[e]=t[e]})),nn(r,[r.Transaction.prototype]),tn(r,[r.Transaction.prototype],o(f),f),u.schema=f;var h,d=R(c);return d&&$e(),a=xe.follow((function(){var e;(h=c(u))&&d&&(e=Ue.bind(null,null),h.then(e,e))})),h&&"function"==typeof h.then?xe.resolve(h):a.then((function(){return h}))}})),c.push((function(t){var n,i,o=e._cfg.dbschema;n=o,i=t,[].slice.call(i.db.objectStoreNames).forEach((function(e){return null==n[e]&&i.db.deleteObjectStore(e)})),nn(r,[r.Transaction.prototype]),tn(r,[r.Transaction.prototype],r._storeNames,r._dbSchema),u.schema=r._dbSchema})),c.push((function(t){r.idbdb.objectStoreNames.contains("$meta")&&(Math.ceil(r.idbdb.version/10)===e._cfg.version?(r.idbdb.deleteObjectStore("$meta"),delete r._dbSchema.$meta,r._storeNames=r._storeNames.filter((function(e){return"$meta"!==e}))):t.objectStore("$meta").put(e._cfg.version,"version"))}))})),function e(){return c.length?xe.resolve(c.shift()(u.idbtrans)).then(e):xe.resolve()}().then((function(){cn(l,s)}))):xe.resolve();var r,i,u,s,c,l})).catch(u)):(o(i).forEach((function(e){sn(n,e,i[e].primKey,i[e].indexes)})),en(e,n),void xe.follow((function(){return e.on.populate.fire(a)})).catch(u));var r,c}))}function an(e,t){cn(e._dbSchema,t),t.db.version%10!=0||t.objectStoreNames.contains("$meta")||t.db.createObjectStore("$meta").add(Math.ceil(t.db.version/10-1),"version");var n=fn(0,e.idbdb,t);hn(e,e._dbSchema,t);for(var r=0,i=un(n,e._dbSchema).change;rMath.pow(2,62)?0:r.oldVersion,h=r<1,e.idbdb=d.result,a&&an(e,f),on(e,r/10,f,c))}),c),d.onsuccess=Be((function(){f=null;var n,u,c,p,y,m=e.idbdb=d.result,b=v(m.objectStoreNames);if(0t.limit?n.length=t.limit:e.length===t.limit&&n.length=r.limit&&(!r.values||e.req.values)&&Xn(e.req.query.range,r.query.range)})),!1,i,o];case"count":return a=o.find((function(e){return Hn(e.req.query.range,r.query.range)})),[a,!!a,i,o]}}(n,r,"query",e),s=u[0],c=u[1],l=u[2],f=u[3];return s&&c?s.obsSet=e.obsSet:(c=i.query(e).then((function(e){var n=e.result;if(s&&(s.res=n),t){for(var r=0,i=n.length;r{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";function e(){const e=document.querySelector("#all-sites-search-text");if(!e)return void console.warn("Search input not found");const t=document.querySelector("#wp-admin-bar-my-sites-list");if(!t)return void console.warn("Sites container not found");const n=()=>{const e=t.getElementsByClassName("menupop")||[];return Array.from(e).map((e=>({element:e,text:e.querySelector(".ab-item")?.textContent?.toLowerCase().trim()||""})))};let r=n();const i=((e,t)=>{let n;return(...r)=>{clearTimeout(n),n=setTimeout((()=>e(...r)),t)}})((e=>{const t=e.toLowerCase().trim();t?r.forEach((({element:e,text:n})=>{e.style.display=n.includes(t)?"":"none"})):r.forEach((({element:e})=>{e.style.display=""}))}),150);e.addEventListener("input",(e=>{e.preventDefault(),i(e.target.value)}));new MutationObserver((()=>{r=n()})).observe(t,{childList:!0,subtree:!0})}var t=n(744);const r=Symbol.for("Dexie"),i=globalThis[r]||(globalThis[r]=t);if(t.semVer!==i.semVer)throw new Error(`Two different versions of Dexie loaded in the same app: ${t.semVer} and ${i.semVer}`);const{liveQuery:o,mergeRanges:a,rangesOverlap:u,RangeSet:s,cmp:c,Entity:l,PropModSymbol:f,PropModification:h,replacePrefix:d,add:p,remove:y}=i;class m{#e;#t;#n;#r;constructor(e,t,n){this.#t=e,this.#n=t,this.#r=n,this.#e=this.#i()}#i(){const e=new i(this.#t);return this.#r.forEach(((t,n)=>{e.version(n+1).stores({[this.#n]:t})})),e}async save(e){try{await this.#e[this.#n].bulkPut(e)}catch(e){throw console.error("IndexedDB save error:",e),e}}async read(e="name"){try{return await this.#e[this.#n].orderBy(e).toArray()}catch(e){throw console.error("IndexedDB read error:",e),e}}async getFirstRow(){try{return await this.#e[this.#n].orderBy(":id").first()}catch(e){throw console.error("IndexedDB getFirstRow error:",e),e}}async delete(){try{await this.#e.delete(),this.#e=this.#i()}catch(e){throw console.error("IndexedDB delete error:",e),e}}async count(){try{return await this.#e[this.#n].count()}catch(e){throw console.error("IndexedDB count error:",e),e}}async getVersion(){try{return await this.#e.open().then((e=>e.verno))}catch(e){throw console.error("IndexedDB getVersion error:",e),e}}}const v=window.wp.apiFetch;var b=n.n(v);async function g(e,{offset:t=0,maxSites:n=1e3,delayMs:r=1e3}={}){try{if(n>0&&t>=n)return;b().use(b().createNonceMiddleware(pluginAllSitesMenu.nonce)),t>0&&await(i=r,new Promise((e=>setTimeout(e,i))));const o=await b()({url:pluginAllSitesMenu.restURL,method:"POST",data:{offset:t}});if(!o||"string"!=typeof o.response)throw new Error("Invalid response format");if("success"===o.response&&Array.isArray(o.data)){await e.save(o.data);return g(e,{offset:t+pluginAllSitesMenu.loadincrements,maxSites:n,delayMs:r})}}catch(e){throw console.error("Error in loadSites:",e.message),e}var i}function w(e,t){if(!e)return;e.classList&&e.classList.add?e.classList.add(t):x(e,t)||(e.className&&(e.className+=" "),e.className+=t);let n=e.getBoundingClientRect().top,r=e.querySelector(".ab-submenu");r.style.top=n-6+"px",r.getBoundingClientRect().bottom>window.innerHeight&&(r.style.top="auto",r.style.bottom="0")}function _(e,t){let n,r;if(e||x(e,t))if(e.classList&&e.classList.remove)e.classList.remove(t);else{for(n=` ${t} `,r=` ${e.className} `;r.indexOf(n)>-1;)r=r.replace(n,"");e.className=r.replace(/^[\s]+|[\s]+$/g,"")}}function x(e,t){let n;return!!e&&(e.classList&&e.classList.contains?e.classList.contains(t):!!e.className&&(n=e.className.split(" "),n.indexOf(t)>-1))}const k=window.wp.i18n;const O="allsites",P="sites",E=["id,name,url","id,name,url,timestamp"];document.addEventListener("DOMContentLoaded",(async function(){if(!document.getElementById("wpadminbar"))return;const t={load:document.querySelector("#wp-admin-bar-load-more"),menu:document.querySelector("#wp-admin-bar-my-sites-list"),timestamp:document.querySelector("#load-more-timestamp")};if(t.load&&t.menu)try{const n=new m(O,P,E);pluginAllSitesMenu.displaySearch&&e(),function(e){if(!e)return;const t=Array.from({length:11},((e,t)=>t/10)),n=e=>{if(!window.matchMedia("(min-width: 783px)").matches)return;const t=document.querySelector("#wp-admin-bar-my-sites>.ab-sub-wrapper"),n=t?.querySelector("ul#wp-admin-bar-my-sites-list");if(!t||!n)return;const r=e.boundingClientRect.bottome.forEach(n)),{threshold:t});r.observe(e)}(t.menu),await async function(e){const t=await e.getFirstRow();void 0!==t&&void 0!==t.timestamp&&pluginAllSitesMenu.timestamp>t.timestamp&&await e.delete();0===await e.count()&&g(e,{offset:0,delayMs:200})}(n),function(e,t){const n=function(e,t){if(!e||!t||!("IntersectionObserver"in window))return console.error("Invalid parameters or IntersectionObserver not supported"),null;const n=new IntersectionObserver((e=>{e.forEach((e=>e.isIntersecting&&t()))}),{threshold:.1});return n.observe(e),n}(e,(async()=>{const r=(await t.read(pluginAllSitesMenu.orderBy)).reduce(((e,t)=>e+function(e){return`\n\t\t\t\t\n\t\t`}(t)),"");e.insertAdjacentHTML("beforeBegin",r),function(){const e=document.getElementById("wp-admin-bar-my-sites-list");e&&(e.addEventListener("mouseenter",(e=>{e.stopPropagation(),e.target.classList.contains("menupop")&&w(e.target,"hover")}),{capture:!0}),e.addEventListener("mouseleave",(e=>{e.stopPropagation(),e.target.classList.contains("menupop")&&_(e.target,"hover")}),{capture:!0}),e.addEventListener("keydown",(e=>{"Tab"===e.key&&(e.preventDefault(),e.target.classList.contains("menupop")&&toggleClass(e.target,"hover"))}),{capture:!0}))}(),e.style.display="none",n.unobserve(e)}))}(t.load,n)}catch(e){console.error("Initialization failed:",e)}}))})()})(); \ No newline at end of file diff --git a/composer.json b/composer.json index 497c2c8..50de33b 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "soderlind/super-admin-all-sites-menu", "description": "For the super admin, replace WP Admin Bar My Sites menu with an All Sites menu.", - "version": "1.7.1", + "version": "1.7.3", "keywords": [ "wordpress", "multisite", diff --git a/package.json b/package.json index 601e020..4998d09 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "super-admin-all-sites-menu", - "version": "1.7.2", + "version": "1.7.3", "description": "For the super admin, replace WP Admin Bar My Sites menu with an All Sites menu.", "main": "index.js", "scripts": { diff --git a/readme.txt b/readme.txt index f02fad2..5b2734c 100644 --- a/readme.txt +++ b/readme.txt @@ -1,5 +1,5 @@ === Super Admin All Sites Menu === -Stable tag: 1.7.2 +Stable tag: 1.7.3 Requires at least: 5.6 Tested up to: 6.7 Requires PHP: 7.3 @@ -108,6 +108,14 @@ You can use the following filters to override the defaults: == Changelog == += 1.7.3 = +* Fixed search functionality: + * Improved search performance with better indexing + * Added mutation observer to handle dynamically loaded sites + * Fixed event handling for search input + * Added improved error handling for search elements + * Better handling of empty search inputs + = 1.7.2 = - Bump version to trigger a deploy to WordPress.org diff --git a/src/modules/search.js b/src/modules/search.js index b4638a5..644a9d1 100644 --- a/src/modules/search.js +++ b/src/modules/search.js @@ -11,28 +11,74 @@ const debounce = ( fn, delay ) => { }; }; +/** + * Add search functionality to the sites menu + * @returns {void} + */ export function addSearch() { + // Use more specific selector and verify element exists const search = document.querySelector( '#all-sites-search-text' ); - if ( ! search ) return; + if ( ! search ) { + console.warn( 'Search input not found' ); + return; + } + + // Get the sites list container + const sitesContainer = document.querySelector( + '#wp-admin-bar-my-sites-list' + ); + if ( ! sitesContainer ) { + console.warn( 'Sites container not found' ); + return; + } + + // Create search index on first load + const createSearchIndex = () => { + const menuItems = + sitesContainer.getElementsByClassName( 'menupop' ) || []; + return Array.from( menuItems ).map( ( li ) => ( { + element: li, + text: + li + .querySelector( '.ab-item' ) + ?.textContent?.toLowerCase() + .trim() || '', + } ) ); + }; - const ul = document.querySelector( '#wp-admin-bar-my-sites-list' ); - const menuItems = ul?.getElementsByClassName( 'menupop' ) || []; + let searchIndex = createSearchIndex(); - // Create index for faster searching - const searchIndex = Array.from( menuItems ).map( ( li ) => ( { - element: li, - text: li.querySelector( '.ab-item' )?.textContent?.toUpperCase() || '', - } ) ); + // Perform search with improved filtering + const performSearch = debounce( ( searchTerm ) => { + const filter = searchTerm.toLowerCase().trim(); - const performSearch = debounce( ( filter ) => { - const upperFilter = filter.toUpperCase(); + // Show all items if search is empty + if ( ! filter ) { + searchIndex.forEach( ( { element } ) => { + element.style.display = ''; + } ); + return; + } + + // Filter items searchIndex.forEach( ( { element, text } ) => { - element.style.display = text.includes( upperFilter ) ? '' : 'none'; + element.style.display = text.includes( filter ) ? '' : 'none'; } ); }, 150 ); - search.addEventListener( 'keyup', ( e ) => { + // Add input event listener (catches all input changes) + search.addEventListener( 'input', ( e ) => { e.preventDefault(); performSearch( e.target.value ); } ); + + // Re-index when new sites are loaded + const observer = new MutationObserver( () => { + searchIndex = createSearchIndex(); + } ); + + observer.observe( sitesContainer, { + childList: true, + subtree: true, + } ); } diff --git a/super-admin-all-sites-menu.php b/super-admin-all-sites-menu.php index d9f76cd..5144a21 100644 --- a/super-admin-all-sites-menu.php +++ b/super-admin-all-sites-menu.php @@ -12,7 +12,7 @@ * Plugin URI: https://github.com/soderlind/super-admin-all-sites-menu * GitHub Plugin URI: https://github.com/soderlind/super-admin-all-sites-menu * Description: For the super admin, replace WP Admin Bar My Sites menu with an All Sites menu. - * Version: 1.7.2 + * Version: 1.7.3 * Author: Per Soderlind * Network: true * Author URI: https://soderlind.no @@ -31,7 +31,7 @@ * Default values for the plugin. */ const LOADINCREMENTS = 100; // Number of sites to load at a time. -const SEARCHTHRESHOLD = 20; // Number of sites before showing the search box. +const SEARCHTHRESHOLD = 2; // Number of sites before showing the search box. const CACHE_EXPIRATION = DAY_IN_SECONDS; // Time to cache the site list. const ORDERBY = 'name'; // Order by name. const PLUGINS = [ 'restricted-site-access/restricted_site_access.php' ]; // Plugins triggering update local storages. From 86f4eabe992541978613320ee28a01a63df810c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20S=C3=B8derlind?= Date: Wed, 8 Jan 2025 11:02:58 +0100 Subject: [PATCH 2/2] Bump version to 1.7.3 in asset files and update version in index.js --- build/index.asset.php | 2 +- build/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/index.asset.php b/build/index.asset.php index 32f9817..1c41809 100644 --- a/build/index.asset.php +++ b/build/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-i18n'), 'version' => '9e5c51f6474ac97c1f9d'); + array('wp-api-fetch', 'wp-i18n'), 'version' => '6df7975b628e4eda2261'); diff --git a/build/index.js b/build/index.js index fd4205b..68ae8ae 100644 --- a/build/index.js +++ b/build/index.js @@ -1,6 +1,6 @@ /*! * super-admin-all-sites-menu - * version: 1.7.2 + * version: 1.7.3 * address: https://github.com/soderlind/super-admin-all-sites-menu#readme * author: Per Søderlind * license: GPLv2