Files
sweet/www/islands/SearchButton.tsx
Bartek IwańczukandClaude Opus 4.6 220368aa15 chore: migrate docsearch and imagescript to npm/jsr imports (#3732)
## Summary
- **docsearch**: Replaced `esm.sh` URL with `npm:@docsearch/js@^3.5.2`.
Added a type cast workaround in `SearchButton.tsx` since Deno's type
checker treats this npm package as CJS (missing `"type": "module"`).
- **imagescript**: Replaced `deno.land/x` URL with
`jsr:@matmen/imagescript@^1.3.0`. Clean swap, no code changes needed.

These were legacy URL-based imports from before Deno had native `npm:`
and `jsr:` support.

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 11:44:37 +00:00

40 lines
975 B
TypeScript

import { useEffect, useRef } from "preact/hooks";
import docsearchModule from "docsearch";
// Copied from algolia source code
type DocSearchProps = {
appId: string;
apiKey: string;
indexName: string;
container: HTMLElement | string;
};
// Workaround: Deno resolves this npm package as CJS, hiding the callable default export
const docsearch = docsearchModule as unknown as (
props: DocSearchProps,
) => void;
export default function SearchButton(
props: { docsearch?: (args: DocSearchProps) => void; class?: string },
) {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
if (ref.current) {
props.docsearch || docsearch({
appId: "CWUS37S0PK",
apiKey: "caa591b6dcb2c9308551361d954a728b",
indexName: "fresh",
container: ref.current,
});
}
}, [ref.current]);
return (
<div
title="Search Button"
class={"h-9 mb-6 " + (props.class ?? "")}
ref={ref}
>
</div>
);
}