Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

searchmate-react

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

searchmate-react - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

146

dist/searchmate-react.es.js
import { useEffect as q, useState as B } from "react";
const I = "https://search-worker.searchmateapp.workers.dev/v1", j = "heading", k = ".searchmate-result-part", v = "searchmate-result-selected", K = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" class="searchmate-search-icon">
const I = "https://search-worker.searchmateapp.workers.dev/v1", K = "heading", E = ".searchmate-result-part", g = "searchmate-result-selected", _ = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" class="searchmate-search-icon">
<path strokeLinecap="round" class strokeLinejoin="round" d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z" />
</svg>
`, P = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="searchmate-path-icon">
`, j = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="searchmate-path-icon">
<path stroke-linecap="round" stroke-linejoin="round" d="M13.19 8.688a4.5 4.5 0 011.242 7.244l-4.5 4.5a4.5 4.5 0 01-6.364-6.364l1.757-1.757m13.35-.622l1.757-1.757a4.5 4.5 0 00-6.364-6.364l-4.5 4.5a4.5 4.5 0 001.242 7.244" />
</svg>
`, _ = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="searchmate-hash-icon">
`, P = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="searchmate-hash-icon">
<path fill-rule="evenodd" d="M9.493 2.853a.75.75 0 00-1.486-.205L7.545 6H4.198a.75.75 0 000 1.5h3.14l-.69 5H3.302a.75.75 0 000 1.5h3.14l-.435 3.148a.75.75 0 001.486.205L7.955 14h2.986l-.434 3.148a.75.75 0 001.486.205L12.456 14h3.346a.75.75 0 000-1.5h-3.14l.69-5h3.346a.75.75 0 000-1.5h-3.14l.435-3.147a.75.75 0 00-1.486-.205L12.045 6H9.059l.434-3.147zM8.852 7.5l-.69 5h2.986l.69-5H8.852z" clip-rule="evenodd" />

@@ -39,3 +39,3 @@ </svg>

]), r = h("p", ["searchmate-result-path-header"]);
r.innerHTML += P;
r.innerHTML += j;
const o = h("span");

@@ -51,3 +51,3 @@ o.textContent = `/${t}`, r.appendChild(o), n.appendChild(r);

]);
o.innerHTML += _, o.innerHTML += t;
o.innerHTML += P, o.innerHTML += t;
const s = r ? `${r}/${e}` : `/${e}`;

@@ -66,3 +66,3 @@ return o.setAttribute("href", `${s}#${n}`), o;

return n.appendChild(r), t.content.forEach((o) => {
if (o.type === j) {
if (o.type === K) {
const s = U(

@@ -83,5 +83,5 @@ o.content,

}
function x(t, e) {
const n = e.querySelectorAll(k)[t];
return n ? (n.classList.add(v), n.scrollIntoView({
function M(t, e) {
const n = e.querySelectorAll(E)[t];
return n ? (n.classList.add(g), n.scrollIntoView({
behavior: "smooth",

@@ -92,11 +92,11 @@ block: "center"

function T(t, e) {
const n = e.querySelectorAll(k)[t];
n && n.classList.remove(v);
const n = e.querySelectorAll(E)[t];
n && n.classList.remove(g);
}
function Y(t, e) {
const n = t.clientX, r = t.clientY, o = e.querySelectorAll(k);
const n = t.clientX, r = t.clientY, o = e.querySelectorAll(E);
let s = -1;
for (let i = 0; i < o.length; i++) {
const d = o[i], { top: u, bottom: c, left: f, right: m } = d.getBoundingClientRect();
r >= u && r <= c && n >= f && n <= m ? (s = i, d.classList.add(v)) : o[i].classList.remove(v);
const d = o[i], { top: u, bottom: c, left: p, right: w } = d.getBoundingClientRect();
r >= u && r <= c && n >= p && n <= w ? (s = i, d.classList.add(g)) : o[i].classList.remove(g);
}

@@ -106,7 +106,7 @@ return s;

function F(t, e) {
const n = t.touches[0].clientX, r = t.touches[0].clientY, o = e.querySelectorAll(k);
const n = t.touches[0].clientX, r = t.touches[0].clientY, o = e.querySelectorAll(E);
let s = -1;
for (let i = 0; i < o.length; i++) {
const d = o[i], { top: u, bottom: c, left: f, right: m } = d.getBoundingClientRect();
r >= u && r <= c && n >= f && n <= m ? (s = i, d.classList.add(v)) : o[i].classList.remove(v);
const d = o[i], { top: u, bottom: c, left: p, right: w } = d.getBoundingClientRect();
r >= u && r <= c && n >= p && n <= w ? (s = i, d.classList.add(g)) : o[i].classList.remove(g);
}

@@ -145,11 +145,11 @@ return s;

return t.apply(this, arguments);
var u = this, c = arguments, f = n && !r;
var u = this, c = arguments, p = n && !r;
if (s(), o = function() {
t.apply(u, c);
}, r = setTimeout(function() {
if (r = null, !f) {
var m = o;
return o = null, m();
if (r = null, !p) {
var w = o;
return o = null, w();
}
}, e), f)
}, e), p)
return o();

@@ -177,3 +177,3 @@ };

]);
d.innerHTML += K;
d.innerHTML += _;
const u = C("input", d, [

@@ -185,33 +185,41 @@ "searchmate-search-input"

"searchmate-results-container"
]), f = Z();
i.appendChild(f);
const m = V();
c.appendChild(m);
let p = 0;
]), p = Z();
i.appendChild(p);
const w = V();
c.appendChild(w);
let f = 0;
function $({ query: a, appId: l }) {
if (a.length <= 0)
return;
const E = new URL(I);
E.searchParams.set("query", a), E.searchParams.set("appId", l), fetch(E).then(async (g) => {
const y = await g.json();
if (!g.ok)
throw new Error(y.error);
return y;
}).then((g) => {
c.innerHTML = "", p = 0;
const y = g.results;
if (y.length <= 0) {
const w = N(a);
c.appendChild(w);
const x = new URL(I);
x.searchParams.set("query", a), x.searchParams.set("appId", l), fetch(x).then(async (y) => {
const L = await y.json();
if (!y.ok)
throw new Error(L.error);
return L;
}).then((y) => {
c.innerHTML = "", f = 0;
const L = y.results;
if (L.length <= 0) {
const v = N(a);
c.appendChild(v);
return;
}
y.forEach((w) => {
const L = X(w, e);
c.appendChild(L);
}), x(p, c), r && c.querySelectorAll("a").forEach((w) => {
w.addEventListener("click", (L) => {
L.preventDefault(), r(w.href, L.ctrlKey);
L.forEach((v) => {
const k = X(v, e);
c.appendChild(k);
}), M(f, c), c.querySelectorAll("a").forEach((v) => {
v.addEventListener("click", (k) => {
if (k.preventDefault(), r)
r(v.href, k.ctrlKey), m();
else {
if (k.ctrlKey) {
window.open(v.href, "_blank"), m();
return;
}
location.href = v.href, m();
}
});
});
}).catch((g) => {
}).catch((y) => {
});

@@ -224,15 +232,15 @@ }

});
function M(a) {
function b(a) {
if (a.key === "ArrowDown") {
a.preventDefault();
const { end: l } = x(
p + 1,
const { end: l } = M(
f + 1,
c
);
l || (T(p, c), p += 1);
l || (T(f, c), f += 1);
}
if (a.key === "ArrowUp") {
if (a.preventDefault(), p <= 0)
if (a.preventDefault(), f <= 0)
return;
T(p, c), p -= 1, x(p, c);
T(f, c), f -= 1, M(f, c);
}

@@ -242,3 +250,3 @@ if (a.key === "Enter") {

const l = c.querySelector(
`.${v}`
`.${g}`
);

@@ -248,9 +256,9 @@ if (!l)

if (r)
r(l.href, a.ctrlKey);
r(l.href, a.ctrlKey), m();
else {
if (a.ctrlKey) {
window.open(l.href, "_blank");
window.open(l.href, "_blank"), m();
return;
}
l.click();
l.click(), m();
}

@@ -260,24 +268,24 @@ }

u.addEventListener("focus", () => {
document.addEventListener("keydown", M);
document.addEventListener("keydown", b);
}), u.addEventListener("blur", () => {
document.removeEventListener("keydown", M);
document.removeEventListener("keydown", b);
});
function b(a) {
function A(a) {
const l = Y(a, c);
l >= 0 && (p = l);
l >= 0 && (f = l);
}
c.addEventListener("mousemove", b);
function A(a) {
c.addEventListener("mousemove", A);
function H(a) {
const l = F(a, c);
l >= 0 && (p = l);
l >= 0 && (f = l);
}
"ontouchstart" in window && c.addEventListener("touchstart", A);
function H() {
c.removeEventListener("mousemove", b), "ontouchstart" in window && c.removeEventListener("touchstart", A), s.remove(), n && n();
"ontouchstart" in window && c.addEventListener("touchstart", H);
function m() {
c.removeEventListener("mousemove", A), "ontouchstart" in window && c.removeEventListener("touchstart", H), s.remove(), n && n();
}
const S = (a) => {
a.key === "Escape" && (H(), document.removeEventListener("keydown", S));
a.key === "Escape" && (m(), document.removeEventListener("keydown", S));
};
document.addEventListener("keydown", S), s.addEventListener("click", (a) => {
a.target === s && H();
a.target === s && m();
}), u.focus();

@@ -284,0 +292,0 @@ }

@@ -1,2 +0,2 @@

(function(p,v){typeof exports=="object"&&typeof module<"u"?v(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],v):(p=typeof globalThis<"u"?globalThis:p||self,v(p["searchmate-react"]={},p.React))})(this,function(p,v){"use strict";const D="https://search-worker.searchmateapp.workers.dev/v1",j="heading",E=".searchmate-result-part",w="searchmate-result-selected",B=`<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" class="searchmate-search-icon">
(function(p,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],g):(p=typeof globalThis<"u"?globalThis:p||self,g(p["searchmate-react"]={},p.React))})(this,function(p,g){"use strict";const D="https://search-worker.searchmateapp.workers.dev/v1",j="heading",M=".searchmate-result-part",y="searchmate-result-selected",B=`<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" class="searchmate-search-icon">
<path strokeLinecap="round" class strokeLinejoin="round" d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z" />

@@ -7,9 +7,9 @@ </svg>

</svg>
`,P=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="searchmate-hash-icon">
`,K=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="searchmate-hash-icon">
<path fill-rule="evenodd" d="M9.493 2.853a.75.75 0 00-1.486-.205L7.545 6H4.198a.75.75 0 000 1.5h3.14l-.69 5H3.302a.75.75 0 000 1.5h3.14l-.435 3.148a.75.75 0 001.486.205L7.955 14h2.986l-.434 3.148a.75.75 0 001.486.205L12.456 14h3.346a.75.75 0 000-1.5h-3.14l.69-5h3.346a.75.75 0 000-1.5h-3.14l.435-3.147a.75.75 0 00-1.486-.205L12.045 6H9.059l.434-3.147zM8.852 7.5l-.69 5h2.986l.69-5H8.852z" clip-rule="evenodd" />
</svg>
`,K=`<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="searchmate-x-notfound-circle">
`,P=`<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="searchmate-x-notfound-circle">
<path stroke-linecap="round" stroke-linejoin="round" d="M9.75 9.75l4.5 4.5m0-4.5l-4.5 4.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
`,R=`<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg" class="searchmate-logo">
`,_=`<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg" class="searchmate-logo">
<g clip-path="url(#clip0_102_15)">

@@ -25,2 +25,2 @@ <rect width="40" height="40" rx="4" fill="#EF4444"/>

</svg>
`;function C(t,e,n){const r=document.createElement(t);return n.forEach(o=>r.classList.add(o)),e.appendChild(r),r}function u(t,e){const n=document.createElement(t);return e&&e.forEach(r=>n.classList.add(r)),n}function _(t,e){const n=u("a",["searchmate-result-part","searchmate-result-path"]),r=u("p",["searchmate-result-path-header"]);r.innerHTML+=I;const o=u("span");o.textContent=`/${t}`,r.appendChild(o),n.appendChild(r);const s=e?`${e}/${t}`:`/${t}`;return n.setAttribute("href",s),n}function z(t,e,n,r){const o=u("a",["searchmate-result-part","searchmate-result-heading"]);o.innerHTML+=P,o.innerHTML+=t;const s=r?`${r}/${e}`:`/${e}`;return o.setAttribute("href",`${s}#${n}`),o}function O(t){const e=u("div",["searchmate-result-other","markdown-body"]);return e.innerHTML+=t,e}function U(t,e){const n=u("div",["searchmate-result"]),r=_(t.path,e);return n.appendChild(r),t.content.forEach(o=>{if(o.type===j){const s=z(o.content,t.path,o.headingId,e);n.appendChild(s)}else{if(o.type==="yaml")return;const s=O(o.content);r.appendChild(s)}}),n}function M(t,e){const n=e.querySelectorAll(E)[t];return n?(n.classList.add(w),n.scrollIntoView({behavior:"smooth",block:"center"}),{end:!1}):{end:!0}}function T(t,e){const n=e.querySelectorAll(E)[t];n&&n.classList.remove(w)}function W(t,e){const n=t.clientX,r=t.clientY,o=e.querySelectorAll(E);let s=-1;for(let i=0;i<o.length;i++){const h=o[i],{top:d,bottom:c,left:m,right:g}=h.getBoundingClientRect();r>=d&&r<=c&&n>=m&&n<=g?(s=i,h.classList.add(w)):o[i].classList.remove(w)}return s}function X(t,e){const n=t.touches[0].clientX,r=t.touches[0].clientY,o=e.querySelectorAll(E);let s=-1;for(let i=0;i<o.length;i++){const h=o[i],{top:d,bottom:c,left:m,right:g}=h.getBoundingClientRect();r>=d&&r<=c&&n>=m&&n<=g?(s=i,h.classList.add(w)):o[i].classList.remove(w)}return s}function Y(t){const e=u("div",["searchmate-not-found"]);e.innerHTML+=K;const n=u("p",["searchmate-not-found-text"]);n.textContent="No results found for ";const r=u("span",["searchmate-not-found-query"]);return r.textContent=`"${t}"`,n.appendChild(r),e.appendChild(n),e}function F(){const t=u("div",["searchmate-initial-content"]),e=u("p",["searchmate-initial-content-text"]);return e.textContent="What are you looking for?",t.appendChild(e),t}function N(){const t=u("div",["searchmate-footer"]),e=u("p",["searchmate-footer-text"]);e.textContent="Powered by ";const n=u("a",["searchmate-footer-link"]);return n.textContent="Search Mate",n.setAttribute("href","https://searchmate.app"),e.appendChild(n),t.appendChild(e),t.innerHTML+=R,t}var V=Z;function Z(t,e,n){var r=null,o=null,s=function(){r&&(clearTimeout(r),o=null,r=null)},i=function(){var d=o;s(),d&&d()},h=function(){if(!e)return t.apply(this,arguments);var d=this,c=arguments,m=n&&!r;if(s(),o=function(){t.apply(d,c)},r=setTimeout(function(){if(r=null,!m){var g=o;return o=null,g()}},e),m)return o()};return h.cancel=s,h.flush=i,h}function G({appId:t,urlPrefix:e=void 0,onClose:n=void 0,overrideNavigateToResult:r=void 0}){const o=document.body;if(o.querySelector("#searchmate-docs-search"))return;const s=C("div",o,["searchmate-container"]);s.id="searchmate-docs-search";const i=C("div",s,["searchmate-search-container"]),h=C("div",i,["searchmate-input-container"]);h.innerHTML+=B;const d=C("input",h,["searchmate-search-input"]);d.setAttribute("placeholder","Type to search...");const c=C("div",i,["searchmate-results-container"]),m=N();i.appendChild(m);const g=F();c.appendChild(g);let f=0;function te({query:a,appId:l}){if(a.length<=0)return;const S=new URL(D);S.searchParams.set("query",a),S.searchParams.set("appId",l),fetch(S).then(async L=>{const k=await L.json();if(!L.ok)throw new Error(k.error);return k}).then(L=>{c.innerHTML="",f=0;const k=L.results;if(k.length<=0){const y=Y(a);c.appendChild(y);return}k.forEach(y=>{const x=U(y,e);c.appendChild(x)}),M(f,c),r&&c.querySelectorAll("a").forEach(y=>{y.addEventListener("click",x=>{x.preventDefault(),r(y.href,x.ctrlKey)})})}).catch(L=>{})}const ne=V(te,300);d.addEventListener("input",a=>{const l=a.target;ne({appId:t,query:l.value})});function b(a){if(a.key==="ArrowDown"){a.preventDefault();const{end:l}=M(f+1,c);l||(T(f,c),f+=1)}if(a.key==="ArrowUp"){if(a.preventDefault(),f<=0)return;T(f,c),f-=1,M(f,c)}if(a.key==="Enter"){a.preventDefault();const l=c.querySelector(`.${w}`);if(!l)return;if(r)r(l.href,a.ctrlKey);else{if(a.ctrlKey){window.open(l.href,"_blank");return}l.click()}}}d.addEventListener("focus",()=>{document.addEventListener("keydown",b)}),d.addEventListener("blur",()=>{document.removeEventListener("keydown",b)});function q(a){const l=W(a,c);l>=0&&(f=l)}c.addEventListener("mousemove",q);function A(a){const l=X(a,c);l>=0&&(f=l)}"ontouchstart"in window&&c.addEventListener("touchstart",A);function H(){c.removeEventListener("mousemove",q),"ontouchstart"in window&&c.removeEventListener("touchstart",A),s.remove(),n&&n()}const $=a=>{a.key==="Escape"&&(H(),document.removeEventListener("keydown",$))};document.addEventListener("keydown",$),s.addEventListener("click",a=>{a.target===s&&H()}),d.focus()}const re="";function J({appId:t,isOpen:e,urlPrefix:n,onClose:r,overrideNavigateToResult:o=void 0}){return v.useEffect(()=>{e&&G({appId:t,urlPrefix:n,onClose:r,overrideNavigateToResult:o})},[e,t,n]),null}function Q(){const[t,e]=v.useState(!1);return{isOpen:t,onOpen:()=>{e(!0)},onClose:()=>{e(!1)}}}function ee({callback:t,key:e,withCtrl:n=!1,isOpen:r}){v.useEffect(()=>{const o=s=>{r||s.key===e&&(n?(s.preventDefault(),s.ctrlKey&&t()):(s.preventDefault(),t()))};return document.addEventListener("keydown",o),()=>{document.removeEventListener("keydown",o)}},[r])}p.Search=J,p.useSearch=Q,p.useShortcut=ee,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
`;function k(t,e,n){const r=document.createElement(t);return n.forEach(o=>r.classList.add(o)),e.appendChild(r),r}function u(t,e){const n=document.createElement(t);return e&&e.forEach(r=>n.classList.add(r)),n}function R(t,e){const n=u("a",["searchmate-result-part","searchmate-result-path"]),r=u("p",["searchmate-result-path-header"]);r.innerHTML+=I;const o=u("span");o.textContent=`/${t}`,r.appendChild(o),n.appendChild(r);const s=e?`${e}/${t}`:`/${t}`;return n.setAttribute("href",s),n}function z(t,e,n,r){const o=u("a",["searchmate-result-part","searchmate-result-heading"]);o.innerHTML+=K,o.innerHTML+=t;const s=r?`${r}/${e}`:`/${e}`;return o.setAttribute("href",`${s}#${n}`),o}function O(t){const e=u("div",["searchmate-result-other","markdown-body"]);return e.innerHTML+=t,e}function U(t,e){const n=u("div",["searchmate-result"]),r=R(t.path,e);return n.appendChild(r),t.content.forEach(o=>{if(o.type===j){const s=z(o.content,t.path,o.headingId,e);n.appendChild(s)}else{if(o.type==="yaml")return;const s=O(o.content);r.appendChild(s)}}),n}function S(t,e){const n=e.querySelectorAll(M)[t];return n?(n.classList.add(y),n.scrollIntoView({behavior:"smooth",block:"center"}),{end:!1}):{end:!0}}function T(t,e){const n=e.querySelectorAll(M)[t];n&&n.classList.remove(y)}function W(t,e){const n=t.clientX,r=t.clientY,o=e.querySelectorAll(M);let s=-1;for(let i=0;i<o.length;i++){const h=o[i],{top:d,bottom:c,left:m,right:L}=h.getBoundingClientRect();r>=d&&r<=c&&n>=m&&n<=L?(s=i,h.classList.add(y)):o[i].classList.remove(y)}return s}function X(t,e){const n=t.touches[0].clientX,r=t.touches[0].clientY,o=e.querySelectorAll(M);let s=-1;for(let i=0;i<o.length;i++){const h=o[i],{top:d,bottom:c,left:m,right:L}=h.getBoundingClientRect();r>=d&&r<=c&&n>=m&&n<=L?(s=i,h.classList.add(y)):o[i].classList.remove(y)}return s}function Y(t){const e=u("div",["searchmate-not-found"]);e.innerHTML+=P;const n=u("p",["searchmate-not-found-text"]);n.textContent="No results found for ";const r=u("span",["searchmate-not-found-query"]);return r.textContent=`"${t}"`,n.appendChild(r),e.appendChild(n),e}function F(){const t=u("div",["searchmate-initial-content"]),e=u("p",["searchmate-initial-content-text"]);return e.textContent="What are you looking for?",t.appendChild(e),t}function N(){const t=u("div",["searchmate-footer"]),e=u("p",["searchmate-footer-text"]);e.textContent="Powered by ";const n=u("a",["searchmate-footer-link"]);return n.textContent="Search Mate",n.setAttribute("href","https://searchmate.app"),e.appendChild(n),t.appendChild(e),t.innerHTML+=_,t}var V=Z;function Z(t,e,n){var r=null,o=null,s=function(){r&&(clearTimeout(r),o=null,r=null)},i=function(){var d=o;s(),d&&d()},h=function(){if(!e)return t.apply(this,arguments);var d=this,c=arguments,m=n&&!r;if(s(),o=function(){t.apply(d,c)},r=setTimeout(function(){if(r=null,!m){var L=o;return o=null,L()}},e),m)return o()};return h.cancel=s,h.flush=i,h}function G({appId:t,urlPrefix:e=void 0,onClose:n=void 0,overrideNavigateToResult:r=void 0}){const o=document.body;if(o.querySelector("#searchmate-docs-search"))return;const s=k("div",o,["searchmate-container"]);s.id="searchmate-docs-search";const i=k("div",s,["searchmate-search-container"]),h=k("div",i,["searchmate-input-container"]);h.innerHTML+=B;const d=k("input",h,["searchmate-search-input"]);d.setAttribute("placeholder","Type to search...");const c=k("div",i,["searchmate-results-container"]),m=N();i.appendChild(m);const L=F();c.appendChild(L);let f=0;function te({query:a,appId:l}){if(a.length<=0)return;const b=new URL(D);b.searchParams.set("query",a),b.searchParams.set("appId",l),fetch(b).then(async C=>{const E=await C.json();if(!C.ok)throw new Error(E.error);return E}).then(C=>{c.innerHTML="",f=0;const E=C.results;if(E.length<=0){const w=Y(a);c.appendChild(w);return}E.forEach(w=>{const x=U(w,e);c.appendChild(x)}),S(f,c),c.querySelectorAll("a").forEach(w=>{w.addEventListener("click",x=>{if(x.preventDefault(),r)r(w.href,x.ctrlKey),v();else{if(x.ctrlKey){window.open(w.href,"_blank"),v();return}location.href=w.href,v()}})})}).catch(C=>{})}const ne=V(te,300);d.addEventListener("input",a=>{const l=a.target;ne({appId:t,query:l.value})});function q(a){if(a.key==="ArrowDown"){a.preventDefault();const{end:l}=S(f+1,c);l||(T(f,c),f+=1)}if(a.key==="ArrowUp"){if(a.preventDefault(),f<=0)return;T(f,c),f-=1,S(f,c)}if(a.key==="Enter"){a.preventDefault();const l=c.querySelector(`.${y}`);if(!l)return;if(r)r(l.href,a.ctrlKey),v();else{if(a.ctrlKey){window.open(l.href,"_blank"),v();return}l.click(),v()}}}d.addEventListener("focus",()=>{document.addEventListener("keydown",q)}),d.addEventListener("blur",()=>{document.removeEventListener("keydown",q)});function A(a){const l=W(a,c);l>=0&&(f=l)}c.addEventListener("mousemove",A);function H(a){const l=X(a,c);l>=0&&(f=l)}"ontouchstart"in window&&c.addEventListener("touchstart",H);function v(){c.removeEventListener("mousemove",A),"ontouchstart"in window&&c.removeEventListener("touchstart",H),s.remove(),n&&n()}const $=a=>{a.key==="Escape"&&(v(),document.removeEventListener("keydown",$))};document.addEventListener("keydown",$),s.addEventListener("click",a=>{a.target===s&&v()}),d.focus()}const re="";function J({appId:t,isOpen:e,urlPrefix:n,onClose:r,overrideNavigateToResult:o=void 0}){return g.useEffect(()=>{e&&G({appId:t,urlPrefix:n,onClose:r,overrideNavigateToResult:o})},[e,t,n]),null}function Q(){const[t,e]=g.useState(!1);return{isOpen:t,onOpen:()=>{e(!0)},onClose:()=>{e(!1)}}}function ee({callback:t,key:e,withCtrl:n=!1,isOpen:r}){g.useEffect(()=>{const o=s=>{r||s.key===e&&(n?(s.preventDefault(),s.ctrlKey&&t()):(s.preventDefault(),t()))};return document.addEventListener("keydown",o),()=>{document.removeEventListener("keydown",o)}},[r])}p.Search=J,p.useSearch=Q,p.useShortcut=ee,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
{
"name": "searchmate-react",
"private": false,
"version": "2.0.0",
"version": "2.1.0",
"type": "module",

@@ -26,3 +26,3 @@ "files": [

"react-dom": "^18.2.0",
"searchmate-js": "2.0.0"
"searchmate-js": "2.1.0"
},

@@ -29,0 +29,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc