searchmate-react
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -1,9 +0,9 @@ | ||
import { useEffect as A, useState as T } from "react"; | ||
const q = "https://search-worker.searchmateapp.workers.dev/v1", S = "heading", L = ".searchmate-result-part", m = "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"> | ||
import { useEffect as q, useState as S } from "react"; | ||
const B = "https://search-worker.searchmateapp.workers.dev/v1", I = "heading", C = ".searchmate-result-part", m = "searchmate-result-selected", j = `<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> | ||
`, I = `<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"> | ||
`, 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"> | ||
<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> | ||
`, j = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="searchmate-hash-icon"> | ||
`, _ = `<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" /> | ||
@@ -14,60 +14,71 @@ </svg> | ||
</svg> | ||
`, D = `<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)"> | ||
<rect width="40" height="40" rx="4" fill="#EF4444"/> | ||
<path d="M32 32L25.071 25.071M25.071 25.071C26.9463 23.1956 27.9999 20.6521 27.9999 18C27.9999 15.3478 26.9463 12.8043 25.071 10.9289C23.1956 9.05355 20.6521 8 18 8C15.3478 8 12.8043 9.05355 10.9289 10.9289C9.05355 12.8043 8 15.3478 8 18C8 20.6521 9.05355 23.1956 10.9289 25.071C12.8043 26.9463 15.3478 27.9999 18 27.9999C20.6521 27.9999 23.1956 26.9463 25.071 25.071Z" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/> | ||
</g> | ||
<defs> | ||
<clipPath id="clip0_102_15"> | ||
<rect width="40" height="40" fill="white"/> | ||
</clipPath> | ||
</defs> | ||
</svg> | ||
`; | ||
function g(n, t, e) { | ||
const r = document.createElement(n); | ||
return e.forEach((o) => r.classList.add(o)), t.appendChild(r), r; | ||
function g(e, t, n) { | ||
const r = document.createElement(e); | ||
return n.forEach((o) => r.classList.add(o)), t.appendChild(r), r; | ||
} | ||
function h(n, t) { | ||
const e = document.createElement(n); | ||
return t && t.forEach((r) => e.classList.add(r)), e; | ||
function d(e, t) { | ||
const n = document.createElement(e); | ||
return t && t.forEach((r) => n.classList.add(r)), n; | ||
} | ||
function D(n, t) { | ||
const e = h("a", [ | ||
function O(e, t) { | ||
const n = d("a", [ | ||
"searchmate-result-part", | ||
"searchmate-result-path" | ||
]), r = h("p", ["searchmate-result-path-header"]); | ||
r.innerHTML += I; | ||
const o = h("span"); | ||
o.textContent = `/${n}`, r.appendChild(o), e.appendChild(r); | ||
const c = t ? `${t}/${n}` : `/${n}`; | ||
return e.setAttribute("href", c), e; | ||
]), r = d("p", ["searchmate-result-path-header"]); | ||
r.innerHTML += P; | ||
const o = d("span"); | ||
o.textContent = `/${e}`, r.appendChild(o), n.appendChild(r); | ||
const c = t ? `${t}/${e}` : `/${e}`; | ||
return n.setAttribute("href", c), n; | ||
} | ||
function R(n, t, e, r) { | ||
const o = h("a", [ | ||
function R(e, t, n, r) { | ||
const o = d("a", [ | ||
"searchmate-result-part", | ||
"searchmate-result-heading" | ||
]); | ||
o.innerHTML += j, o.innerHTML += n; | ||
o.innerHTML += _, o.innerHTML += e; | ||
const c = r ? `${r}/${t}` : `/${t}`; | ||
return o.setAttribute("href", `${c}#${e}`), o; | ||
return o.setAttribute("href", `${c}#${n}`), o; | ||
} | ||
function O(n) { | ||
const t = h("div", [ | ||
function U(e) { | ||
const t = d("div", [ | ||
"searchmate-result-other", | ||
"markdown-body" | ||
]); | ||
return t.innerHTML += n, t; | ||
return t.innerHTML += e, t; | ||
} | ||
function P(n, t) { | ||
const e = h("div", ["searchmate-result"]), r = D(n.path, t); | ||
return e.appendChild(r), n.content.forEach((o) => { | ||
if (o.type === S) { | ||
function W(e, t) { | ||
const n = d("div", ["searchmate-result"]), r = O(e.path, t); | ||
return n.appendChild(r), e.content.forEach((o) => { | ||
if (o.type === I) { | ||
const c = R( | ||
o.content, | ||
n.path, | ||
e.path, | ||
o.headingId, | ||
t | ||
); | ||
e.appendChild(c); | ||
n.appendChild(c); | ||
} else { | ||
if (o.type === "yaml") | ||
return; | ||
const c = O(o.content); | ||
const c = U(o.content); | ||
r.appendChild(c); | ||
} | ||
}), e; | ||
}), n; | ||
} | ||
function C(n, t) { | ||
const e = t.querySelectorAll(L)[n]; | ||
return e ? (e.classList.add(m), e.scrollIntoView({ | ||
function y(e, t) { | ||
const n = t.querySelectorAll(C)[e]; | ||
return n ? (n.classList.add(m), n.scrollIntoView({ | ||
behavior: "smooth", | ||
@@ -77,37 +88,49 @@ block: "center" | ||
} | ||
function H(n, t) { | ||
const e = t.querySelectorAll(L)[n]; | ||
e && e.classList.remove(m); | ||
function H(e, t) { | ||
const n = t.querySelectorAll(C)[e]; | ||
n && n.classList.remove(m); | ||
} | ||
function U(n, t) { | ||
const e = n.clientX, r = n.clientY, o = t.querySelectorAll(L); | ||
function X(e, t) { | ||
const n = e.clientX, r = e.clientY, o = t.querySelectorAll(C); | ||
let c = -1; | ||
for (let i = 0; i < o.length; i++) { | ||
const u = o[i], { top: s, bottom: l, left: p, right: f } = u.getBoundingClientRect(); | ||
r >= s && r <= l && e >= p && e <= f ? (c = i, u.classList.add(m)) : o[i].classList.remove(m); | ||
for (let l = 0; l < o.length; l++) { | ||
const u = o[l], { top: s, bottom: f, left: p, right: i } = u.getBoundingClientRect(); | ||
r >= s && r <= f && n >= p && n <= i ? (c = l, u.classList.add(m)) : o[l].classList.remove(m); | ||
} | ||
return c; | ||
} | ||
function Y(n, t) { | ||
const e = n.touches[0].clientX, r = n.touches[0].clientY, o = t.querySelectorAll(L); | ||
function Y(e, t) { | ||
const n = e.touches[0].clientX, r = e.touches[0].clientY, o = t.querySelectorAll(C); | ||
let c = -1; | ||
for (let i = 0; i < o.length; i++) { | ||
const u = o[i], { top: s, bottom: l, left: p, right: f } = u.getBoundingClientRect(); | ||
r >= s && r <= l && e >= p && e <= f ? (c = i, u.classList.add(m)) : o[i].classList.remove(m); | ||
for (let l = 0; l < o.length; l++) { | ||
const u = o[l], { top: s, bottom: f, left: p, right: i } = u.getBoundingClientRect(); | ||
r >= s && r <= f && n >= p && n <= i ? (c = l, u.classList.add(m)) : o[l].classList.remove(m); | ||
} | ||
return c; | ||
} | ||
function W(n) { | ||
const t = h("div", ["searchmate-not-found"]); | ||
function F(e) { | ||
const t = d("div", ["searchmate-not-found"]); | ||
t.innerHTML += z; | ||
const e = h("p", ["searchmate-not-found-text"]); | ||
e.textContent = "No results found for "; | ||
const r = h("span", ["searchmate-not-found-query"]); | ||
return r.textContent = `"${n}"`, e.appendChild(r), t.appendChild(e), t; | ||
const n = d("p", ["searchmate-not-found-text"]); | ||
n.textContent = "No results found for "; | ||
const r = d("span", ["searchmate-not-found-query"]); | ||
return r.textContent = `"${e}"`, n.appendChild(r), t.appendChild(n), t; | ||
} | ||
var X = _; | ||
function _(n, t, e) { | ||
function K() { | ||
const e = d("div", ["searchmate-initial-content"]), t = d("p", [ | ||
"searchmate-initial-content-text" | ||
]); | ||
return t.textContent = "What are you looking for?", e.appendChild(t), e; | ||
} | ||
function N() { | ||
const e = d("div", ["searchmate-footer"]), t = d("p", ["searchmate-footer-text"]); | ||
t.textContent = "Powered by "; | ||
const n = d("a", ["searchmate-footer-link"]); | ||
return n.textContent = "Search Mate", n.setAttribute("href", "https://searchmate.app"), t.appendChild(n), e.appendChild(t), e.innerHTML += D, e; | ||
} | ||
var G = V; | ||
function V(e, t, n) { | ||
var r = null, o = null, c = function() { | ||
r && (clearTimeout(r), o = null, r = null); | ||
}, i = function() { | ||
}, l = function() { | ||
var s = o; | ||
@@ -117,10 +140,10 @@ c(), s && s(); | ||
if (!t) | ||
return n.apply(this, arguments); | ||
var s = this, l = arguments, p = e && !r; | ||
return e.apply(this, arguments); | ||
var s = this, f = arguments, p = n && !r; | ||
if (c(), o = function() { | ||
n.apply(s, l); | ||
e.apply(s, f); | ||
}, r = setTimeout(function() { | ||
if (r = null, !p) { | ||
var f = o; | ||
return o = null, f(); | ||
var i = o; | ||
return o = null, i(); | ||
} | ||
@@ -130,8 +153,8 @@ }, t), p) | ||
}; | ||
return u.cancel = c, u.flush = i, u; | ||
return u.cancel = c, u.flush = l, u; | ||
} | ||
function F({ | ||
appId: n, | ||
function Z({ | ||
appId: e, | ||
urlPrefix: t = void 0, | ||
onClose: e = void 0 | ||
onClose: n = void 0 | ||
}) { | ||
@@ -144,7 +167,7 @@ const r = document.body, o = g("div", r, [ | ||
"searchmate-search-container" | ||
]), i = g("div", c, [ | ||
]), l = g("div", c, [ | ||
"searchmate-input-container" | ||
]); | ||
i.innerHTML += B; | ||
const u = g("input", i, [ | ||
l.innerHTML += j; | ||
const u = g("input", l, [ | ||
"searchmate-search-input" | ||
@@ -155,9 +178,12 @@ ]); | ||
"searchmate-results-container" | ||
]); | ||
let l = 0; | ||
function p({ query: a, appId: d }) { | ||
]), f = N(); | ||
c.appendChild(f); | ||
const p = K(); | ||
s.appendChild(p); | ||
let i = 0; | ||
function A({ query: a, appId: h }) { | ||
if (a.length <= 0) | ||
return; | ||
const k = new URL(q); | ||
k.searchParams.set("query", a), k.searchParams.set("appId", d), fetch(k).then(async (v) => { | ||
const L = new URL(B); | ||
L.searchParams.set("query", a), L.searchParams.set("appId", h), fetch(L).then(async (v) => { | ||
const w = await v.json(); | ||
@@ -168,46 +194,46 @@ if (!v.ok) | ||
}).then((v) => { | ||
s.innerHTML = "", l = 0; | ||
s.innerHTML = "", i = 0; | ||
const w = v.results; | ||
if (w.length <= 0) { | ||
const y = W(a); | ||
s.appendChild(y); | ||
const k = F(a); | ||
s.appendChild(k); | ||
return; | ||
} | ||
w.forEach((y) => { | ||
const $ = P(y, t); | ||
w.forEach((k) => { | ||
const $ = W(k, t); | ||
s.appendChild($); | ||
}), C(l, s); | ||
}), y(i, s); | ||
}).catch((v) => { | ||
}); | ||
} | ||
const f = X(p, 300); | ||
const T = G(A, 300); | ||
u.addEventListener("input", (a) => { | ||
const d = a.target; | ||
f({ appId: n, query: d.value }); | ||
const h = a.target; | ||
T({ appId: e, query: h.value }); | ||
}); | ||
function E(a) { | ||
function x(a) { | ||
if (a.key === "ArrowDown") { | ||
a.preventDefault(); | ||
const { end: d } = C( | ||
l + 1, | ||
const { end: h } = y( | ||
i + 1, | ||
s | ||
); | ||
d || (H(l, s), l += 1); | ||
h || (H(i, s), i += 1); | ||
} | ||
if (a.key === "ArrowUp") { | ||
if (a.preventDefault(), l <= 0) | ||
if (a.preventDefault(), i <= 0) | ||
return; | ||
H(l, s), l -= 1, C(l, s); | ||
H(i, s), i -= 1, y(i, s); | ||
} | ||
if (a.key === "Enter") { | ||
a.preventDefault(); | ||
const d = s.querySelector( | ||
const h = s.querySelector( | ||
`.${m}` | ||
); | ||
if (d) { | ||
if (h) { | ||
if (a.ctrlKey) { | ||
window.open(d.href, "_blank"); | ||
window.open(h.href, "_blank"); | ||
return; | ||
} | ||
d.click(); | ||
h.click(); | ||
} | ||
@@ -217,18 +243,18 @@ } | ||
u.addEventListener("focus", () => { | ||
document.addEventListener("keydown", E); | ||
document.addEventListener("keydown", x); | ||
}), u.addEventListener("blur", () => { | ||
document.removeEventListener("keydown", E); | ||
document.removeEventListener("keydown", x); | ||
}); | ||
function x(a) { | ||
const d = U(a, s); | ||
d >= 0 && (l = d); | ||
function E(a) { | ||
const h = X(a, s); | ||
h >= 0 && (i = h); | ||
} | ||
s.addEventListener("mousemove", x); | ||
s.addEventListener("mousemove", E); | ||
function M(a) { | ||
const d = Y(a, s); | ||
d >= 0 && (l = d); | ||
const h = Y(a, s); | ||
h >= 0 && (i = h); | ||
} | ||
"ontouchstart" in window && s.addEventListener("touchstart", M); | ||
function b() { | ||
s.removeEventListener("mousemove", x), "ontouchstart" in window && s.removeEventListener("touchstart", M), o.remove(), e && e(); | ||
s.removeEventListener("mousemove", E), "ontouchstart" in window && s.removeEventListener("touchstart", M), o.remove(), n && n(); | ||
} | ||
@@ -241,14 +267,14 @@ c.addEventListener("keydown", (a) => { | ||
} | ||
function N({ appId: n, isOpen: t, urlPrefix: e, onClose: r }) { | ||
return A(() => { | ||
t && F({ | ||
appId: n, | ||
urlPrefix: e, | ||
function Q({ appId: e, isOpen: t, urlPrefix: n, onClose: r }) { | ||
return q(() => { | ||
t && Z({ | ||
appId: e, | ||
urlPrefix: n, | ||
onClose: r | ||
}); | ||
}, [t, n, e]), null; | ||
}, [t, e, n]), null; | ||
} | ||
function V() { | ||
const [n, t] = T(!1); | ||
return { isOpen: n, onOpen: () => { | ||
function tt() { | ||
const [e, t] = S(!1); | ||
return { isOpen: e, onOpen: () => { | ||
t(!0); | ||
@@ -260,4 +286,4 @@ }, onClose: () => { | ||
export { | ||
N as Search, | ||
V as useSearch | ||
Q as Search, | ||
tt as useSearch | ||
}; |
@@ -1,2 +0,2 @@ | ||
(function(f,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],w):(f=typeof globalThis<"u"?globalThis:f||self,w(f["searchmate-react"]={},f.React))})(this,function(f,w){"use strict";const $="https://search-worker.searchmateapp.workers.dev/v1",q="heading",k=".searchmate-result-part",m="searchmate-result-selected",A=`<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,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],w):(p=typeof globalThis<"u"?globalThis:p||self,w(p["searchmate-react"]={},p.React))})(this,function(p,w){"use strict";const A="https://search-worker.searchmateapp.workers.dev/v1",$="heading",k=".searchmate-result-part",m="searchmate-result-selected",q=`<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" /> | ||
@@ -13,2 +13,13 @@ </svg> | ||
</svg> | ||
`;function g(n,t,e){const r=document.createElement(n);return e.forEach(o=>r.classList.add(o)),t.appendChild(r),r}function h(n,t){const e=document.createElement(n);return t&&t.forEach(r=>e.classList.add(r)),e}function z(n,t){const e=h("a",["searchmate-result-part","searchmate-result-path"]),r=h("p",["searchmate-result-path-header"]);r.innerHTML+=j;const o=h("span");o.textContent=`/${n}`,r.appendChild(o),e.appendChild(r);const c=t?`${t}/${n}`:`/${n}`;return e.setAttribute("href",c),e}function D(n,t,e,r){const o=h("a",["searchmate-result-part","searchmate-result-heading"]);o.innerHTML+=B,o.innerHTML+=n;const c=r?`${r}/${t}`:`/${t}`;return o.setAttribute("href",`${c}#${e}`),o}function R(n){const t=h("div",["searchmate-result-other","markdown-body"]);return t.innerHTML+=n,t}function O(n,t){const e=h("div",["searchmate-result"]),r=z(n.path,t);return e.appendChild(r),n.content.forEach(o=>{if(o.type===q){const c=D(o.content,n.path,o.headingId,t);e.appendChild(c)}else{if(o.type==="yaml")return;const c=R(o.content);r.appendChild(c)}}),e}function C(n,t){const e=t.querySelectorAll(k)[n];return e?(e.classList.add(m),e.scrollIntoView({behavior:"smooth",block:"center"}),{end:!1}):{end:!0}}function M(n,t){const e=t.querySelectorAll(k)[n];e&&e.classList.remove(m)}function P(n,t){const e=n.clientX,r=n.clientY,o=t.querySelectorAll(k);let c=-1;for(let l=0;l<o.length;l++){const u=o[l],{top:s,bottom:i,left:p,right:v}=u.getBoundingClientRect();r>=s&&r<=i&&e>=p&&e<=v?(c=l,u.classList.add(m)):o[l].classList.remove(m)}return c}function U(n,t){const e=n.touches[0].clientX,r=n.touches[0].clientY,o=t.querySelectorAll(k);let c=-1;for(let l=0;l<o.length;l++){const u=o[l],{top:s,bottom:i,left:p,right:v}=u.getBoundingClientRect();r>=s&&r<=i&&e>=p&&e<=v?(c=l,u.classList.add(m)):o[l].classList.remove(m)}return c}function Y(n){const t=h("div",["searchmate-not-found"]);t.innerHTML+=I;const e=h("p",["searchmate-not-found-text"]);e.textContent="No results found for ";const r=h("span",["searchmate-not-found-query"]);return r.textContent=`"${n}"`,e.appendChild(r),t.appendChild(e),t}var W=X;function X(n,t,e){var r=null,o=null,c=function(){r&&(clearTimeout(r),o=null,r=null)},l=function(){var s=o;c(),s&&s()},u=function(){if(!t)return n.apply(this,arguments);var s=this,i=arguments,p=e&&!r;if(c(),o=function(){n.apply(s,i)},r=setTimeout(function(){if(r=null,!p){var v=o;return o=null,v()}},t),p)return o()};return u.cancel=c,u.flush=l,u}function _({appId:n,urlPrefix:t=void 0,onClose:e=void 0}){const r=document.body,o=g("div",r,["searchmate-container"]);o.id="searchmate-docs-search";const c=g("div",o,["searchmate-search-container"]),l=g("div",c,["searchmate-input-container"]);l.innerHTML+=A;const u=g("input",l,["searchmate-search-input"]);u.setAttribute("placeholder","Type to search...");const s=g("div",c,["searchmate-results-container"]);let i=0;function p({query:a,appId:d}){if(a.length<=0)return;const E=new URL($);E.searchParams.set("query",a),E.searchParams.set("appId",d),fetch(E).then(async L=>{const y=await L.json();if(!L.ok)throw new Error(y.error);return y}).then(L=>{s.innerHTML="",i=0;const y=L.results;if(y.length<=0){const x=Y(a);s.appendChild(x);return}y.forEach(x=>{const N=O(x,t);s.appendChild(N)}),C(i,s)}).catch(L=>{})}const v=W(p,300);u.addEventListener("input",a=>{const d=a.target;v({appId:n,query:d.value})});function b(a){if(a.key==="ArrowDown"){a.preventDefault();const{end:d}=C(i+1,s);d||(M(i,s),i+=1)}if(a.key==="ArrowUp"){if(a.preventDefault(),i<=0)return;M(i,s),i-=1,C(i,s)}if(a.key==="Enter"){a.preventDefault();const d=s.querySelector(`.${m}`);if(d){if(a.ctrlKey){window.open(d.href,"_blank");return}d.click()}}}u.addEventListener("focus",()=>{document.addEventListener("keydown",b)}),u.addEventListener("blur",()=>{document.removeEventListener("keydown",b)});function T(a){const d=P(a,s);d>=0&&(i=d)}s.addEventListener("mousemove",T);function S(a){const d=U(a,s);d>=0&&(i=d)}"ontouchstart"in window&&s.addEventListener("touchstart",S);function H(){s.removeEventListener("mousemove",T),"ontouchstart"in window&&s.removeEventListener("touchstart",S),o.remove(),e&&e()}c.addEventListener("keydown",a=>{a.key==="Escape"&&H()}),o.addEventListener("click",a=>{a.target===o&&H()}),u.focus()}const V="";function F({appId:n,isOpen:t,urlPrefix:e,onClose:r}){return w.useEffect(()=>{t&&_({appId:n,urlPrefix:e,onClose:r})},[t,n,e]),null}function K(){const[n,t]=w.useState(!1);return{isOpen:n,onOpen:()=>{t(!0)},onClose:()=>{t(!1)}}}f.Search=F,f.useSearch=K,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}); | ||
`,P=`<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)"> | ||
<rect width="40" height="40" rx="4" fill="#EF4444"/> | ||
<path d="M32 32L25.071 25.071M25.071 25.071C26.9463 23.1956 27.9999 20.6521 27.9999 18C27.9999 15.3478 26.9463 12.8043 25.071 10.9289C23.1956 9.05355 20.6521 8 18 8C15.3478 8 12.8043 9.05355 10.9289 10.9289C9.05355 12.8043 8 15.3478 8 18C8 20.6521 9.05355 23.1956 10.9289 25.071C12.8043 26.9463 15.3478 27.9999 18 27.9999C20.6521 27.9999 23.1956 26.9463 25.071 25.071Z" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/> | ||
</g> | ||
<defs> | ||
<clipPath id="clip0_102_15"> | ||
<rect width="40" height="40" fill="white"/> | ||
</clipPath> | ||
</defs> | ||
</svg> | ||
`;function g(t,e,n){const r=document.createElement(t);return n.forEach(o=>r.classList.add(o)),e.appendChild(r),r}function h(t,e){const n=document.createElement(t);return e&&e.forEach(r=>n.classList.add(r)),n}function _(t,e){const n=h("a",["searchmate-result-part","searchmate-result-path"]),r=h("p",["searchmate-result-path-header"]);r.innerHTML+=j;const o=h("span");o.textContent=`/${t}`,r.appendChild(o),n.appendChild(r);const c=e?`${e}/${t}`:`/${t}`;return n.setAttribute("href",c),n}function z(t,e,n,r){const o=h("a",["searchmate-result-part","searchmate-result-heading"]);o.innerHTML+=B,o.innerHTML+=t;const c=r?`${r}/${e}`:`/${e}`;return o.setAttribute("href",`${c}#${n}`),o}function D(t){const e=h("div",["searchmate-result-other","markdown-body"]);return e.innerHTML+=t,e}function O(t,e){const n=h("div",["searchmate-result"]),r=_(t.path,e);return n.appendChild(r),t.content.forEach(o=>{if(o.type===$){const c=z(o.content,t.path,o.headingId,e);n.appendChild(c)}else{if(o.type==="yaml")return;const c=D(o.content);r.appendChild(c)}}),n}function y(t,e){const n=e.querySelectorAll(k)[t];return n?(n.classList.add(m),n.scrollIntoView({behavior:"smooth",block:"center"}),{end:!1}):{end:!0}}function M(t,e){const n=e.querySelectorAll(k)[t];n&&n.classList.remove(m)}function R(t,e){const n=t.clientX,r=t.clientY,o=e.querySelectorAll(k);let c=-1;for(let l=0;l<o.length;l++){const u=o[l],{top:s,bottom:v,left:f,right:i}=u.getBoundingClientRect();r>=s&&r<=v&&n>=f&&n<=i?(c=l,u.classList.add(m)):o[l].classList.remove(m)}return c}function U(t,e){const n=t.touches[0].clientX,r=t.touches[0].clientY,o=e.querySelectorAll(k);let c=-1;for(let l=0;l<o.length;l++){const u=o[l],{top:s,bottom:v,left:f,right:i}=u.getBoundingClientRect();r>=s&&r<=v&&n>=f&&n<=i?(c=l,u.classList.add(m)):o[l].classList.remove(m)}return c}function W(t){const e=h("div",["searchmate-not-found"]);e.innerHTML+=I;const n=h("p",["searchmate-not-found-text"]);n.textContent="No results found for ";const r=h("span",["searchmate-not-found-query"]);return r.textContent=`"${t}"`,n.appendChild(r),e.appendChild(n),e}function X(){const t=h("div",["searchmate-initial-content"]),e=h("p",["searchmate-initial-content-text"]);return e.textContent="What are you looking for?",t.appendChild(e),t}function Y(){const t=h("div",["searchmate-footer"]),e=h("p",["searchmate-footer-text"]);e.textContent="Powered by ";const n=h("a",["searchmate-footer-link"]);return n.textContent="Search Mate",n.setAttribute("href","https://searchmate.app"),e.appendChild(n),t.appendChild(e),t.innerHTML+=P,t}var F=K;function K(t,e,n){var r=null,o=null,c=function(){r&&(clearTimeout(r),o=null,r=null)},l=function(){var s=o;c(),s&&s()},u=function(){if(!e)return t.apply(this,arguments);var s=this,v=arguments,f=n&&!r;if(c(),o=function(){t.apply(s,v)},r=setTimeout(function(){if(r=null,!f){var i=o;return o=null,i()}},e),f)return o()};return u.cancel=c,u.flush=l,u}function N({appId:t,urlPrefix:e=void 0,onClose:n=void 0}){const r=document.body,o=g("div",r,["searchmate-container"]);o.id="searchmate-docs-search";const c=g("div",o,["searchmate-search-container"]),l=g("div",c,["searchmate-input-container"]);l.innerHTML+=q;const u=g("input",l,["searchmate-search-input"]);u.setAttribute("placeholder","Type to search...");const s=g("div",c,["searchmate-results-container"]),v=Y();c.appendChild(v);const f=X();s.appendChild(f);let i=0;function Z({query:a,appId:d}){if(a.length<=0)return;const x=new URL(A);x.searchParams.set("query",a),x.searchParams.set("appId",d),fetch(x).then(async C=>{const L=await C.json();if(!C.ok)throw new Error(L.error);return L}).then(C=>{s.innerHTML="",i=0;const L=C.results;if(L.length<=0){const E=W(a);s.appendChild(E);return}L.forEach(E=>{const Q=O(E,e);s.appendChild(Q)}),y(i,s)}).catch(C=>{})}const J=F(Z,300);u.addEventListener("input",a=>{const d=a.target;J({appId:t,query:d.value})});function b(a){if(a.key==="ArrowDown"){a.preventDefault();const{end:d}=y(i+1,s);d||(M(i,s),i+=1)}if(a.key==="ArrowUp"){if(a.preventDefault(),i<=0)return;M(i,s),i-=1,y(i,s)}if(a.key==="Enter"){a.preventDefault();const d=s.querySelector(`.${m}`);if(d){if(a.ctrlKey){window.open(d.href,"_blank");return}d.click()}}}u.addEventListener("focus",()=>{document.addEventListener("keydown",b)}),u.addEventListener("blur",()=>{document.removeEventListener("keydown",b)});function T(a){const d=R(a,s);d>=0&&(i=d)}s.addEventListener("mousemove",T);function S(a){const d=U(a,s);d>=0&&(i=d)}"ontouchstart"in window&&s.addEventListener("touchstart",S);function H(){s.removeEventListener("mousemove",T),"ontouchstart"in window&&s.removeEventListener("touchstart",S),o.remove(),n&&n()}c.addEventListener("keydown",a=>{a.key==="Escape"&&H()}),o.addEventListener("click",a=>{a.target===o&&H()}),u.focus()}const ee="";function G({appId:t,isOpen:e,urlPrefix:n,onClose:r}){return w.useEffect(()=>{e&&N({appId:t,urlPrefix:n,onClose:r})},[e,t,n]),null}function V(){const[t,e]=w.useState(!1);return{isOpen:t,onOpen:()=>{e(!0)},onClose:()=>{e(!1)}}}p.Search=G,p.useSearch=V,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}); |
{ | ||
"name": "searchmate-react", | ||
"private": false, | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"type": "module", | ||
@@ -26,3 +26,3 @@ "files": [ | ||
"react-dom": "^18.2.0", | ||
"searchmate-js": "1.2.0" | ||
"searchmate-js": "1.3.0" | ||
}, | ||
@@ -29,0 +29,0 @@ "devDependencies": { |
@@ -33,3 +33,3 @@ This package is a React client for [Searchmate](https://searchmate.app). | ||
:root { | ||
/* Searchmate */ | ||
/* Searchmate */ | ||
/* container */ | ||
@@ -52,2 +52,5 @@ --searchmate-container-color: rgba(15, 23, 42, 0.1); | ||
--searchmate-selected-color: #f8fafc; | ||
/* footer */ | ||
--searchmate-footer-text-color: #3f3f46; | ||
} | ||
@@ -77,3 +80,3 @@ ``` | ||
/* results */ | ||
--searchmate-result-bg: #030712; | ||
--searchmate-result-bg: #0f172a; | ||
--searchmate-result-text-color: #d1d5db; | ||
@@ -83,3 +86,6 @@ --searchmate-selected-bg: #ef4444; | ||
--searchmate-selected-color: #f8fafc; | ||
/* footer */ | ||
--searchmate-footer-text-color: #d1d5db; | ||
} | ||
``` |
Sorry, the diff of this file is not supported yet
56210
470
88
+ Addedsearchmate-js@1.3.0(transitive)
- Removedsearchmate-js@1.2.0(transitive)
Updatedsearchmate-js@1.3.0