npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

clickable-detail

v1.0.9

Published

A clickable Detail component for Raycast that renders JSX and HTML as an SVG with per-component click handlers.

Downloads

11

Readme

clickable-detail

A customized Detail component for Raycast that enables interaction via mouse clicks.

ClickableDetail

Installation

npm install clickable-detail

Upon install, the package will automatically add two .scpt scripts to your extension's assets folder, i.e.:

  • DetectMouseClicks - Used to detect mouse clicks on the Raycast window.
  • HTML2b64 - Used to convert HTML and URLs to base64-encoded PNG strings.

These scripts are necessary for the package to work, but you can modify them if you wish (e.g. if you want to customize the SVG that is used to render the clickable content). Use Script Editor on your Mac to view/edit the source code.

Usage

Overview

import {
  ClickableDetail,
  DynamicSVG,
  HTML,
  INPUT,
  Image,
  Polygon,
  Toggle,
  usePreloadedImages,
  useToggleDelegate,
} from "clickable-detail";
import { runAppleScript } from "run-applescript";

export default function Command() {
  // Preload images so they are ready to be used when the SVG is rendered
  const images = usePreloadedImages(["https://placeholder.pics/svg/200x100"]);

  // Delegates are used to keep track of state
  const toggleDelegate = useToggleDelegate(false);

  return (
    <ClickableDetail isLoading={images.length != 1} waitUntilAllLoaded={true}>
      <DynamicSVG>
        {/* High-level, stateful components provided (More to be added soon) */}
        <Toggle
          x={0}
          y={0}
          delegate={toggleDelegate}
          label="Option 1"
          onClick={() => runAppleScript(`display dialog "You toggled Option 1"`)}
        />

        {/* Include external images */}
        <Image x={0} y={50} width={200} height={100} {...images[0]?.image.data} />

        {/* Click handlers can access the (x, y) coordinate of the click */}
        <Polygon points="300,100 350,25 350,75 400,0" fill="red" onClick={(loc) => console.log(`Clicked at (${loc.x}, ${loc.y})`)}/>

        {/* Supports HTML using JSX syntax */}
        <HTML y={200}>
          <head>
            {/* Supports applying styles to HTML elements */}
            <style type="text/css">
              {`
                #paragraph1 {
                  color: red;
                }
              `}
            </style>
          </head>
          <body>
            {/* Use React's built-in HTML components */}
            <p id="paragraph1">Can render arbitrary HTML content</p>

            <form>
              {/* For additional functionality, use package-provided components -- just uppercase the normal tag and add, e.g., a click handler */}
              <INPUT type="submit" value="Submit" onClick={() => console.log("Submitted!")} x={10} y={215} width={55} height={25} />
            </form>
          </body>
        </HTML>
      </DynamicSVG>
    </ClickableDetail>
  );
}

The ClickableDetail component works similarly to the built-in Detail component, but with a few key differences:

  • You do not provide a markdown prop — it will be automatically generated from ClickableDetail's children.
  • As of now, the metadata prop is not supported, but will be in the future.

How does it work?

There two two main aspects to this package:

  1. Rendering clickable content
  2. Listening for mouse clicks

For the first part, the ClickableDetail component uses a dynamically generated SVG to display content beyond what Detail normally supports. The SVG can be sourced from anywhere, but the provided DynamicSVG, built specifically for this package, is highly recommended. It supports not just creating SVGs using JSX syntax, but also embedding HTML content, external URLs, and click handlers for SVG elements.

To enable mouse clicks, the ClickableDetail component uses a JXA child process to monitor mouse clicks on the Raycast window. When a click is detected, ClickableDetail will determine if the click was on an SVG element that has a click handler. If so, the click handler will be called.