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

extendscript-ui

v0.0.5

Published

JSX templating for Adobe ExtendScript

Downloads

336

Readme

extendscript-ui

JSX templating for ScriptUI/ExtendScript

Have you ever wanted to compose ScriptUI with JSX-like syntax, like so:

<dialog text="Neat!" properties={{ closeButton: true }}>
  <button text="Click me!" size={[100, 200]} onClick={() => alert("Doink!")} />
</dialog>

Well, now you can! Plus, TypeScript will guide you through each prop with auto completions!

You can even create functional components:

const Header = ({ text }: { text: string }) => (
  <group orientation={"row"} alignChildren={"fill"}>
    <static-text text={text}></static-text>
  </group>
);

const ui = (
  <dialog text="Could it be?!" properties={{ resizeable: true }}>
    <Header text="Neat!" />
  </dialog>
);

Try it

[!TIP] For a super basic example, check out /examples/basic!

Prerequisites

You'll need TypeScript and a bundler for your code. Here are some ExtendScript starters with TypeScript support to check out:

Installation

npm i extendscript-ui

Configuration

Update your tsconfig.json:

{
  "compilerOptions": {
    // ...your other config options, then:
    // tell TypeScript how to find extendscript-ui's jsx.d.ts declarations:
    "typeRoots": ["./node_modules/extendscript-ui/dist"],
    "types": ["types/jsx.d.ts"],
    // tell TypeScript how to transform your JSX code and the name of the jsxFactory fn to use when doing so:
    "jsx": "react",
    "jsxFactory": "jsx" // this is the fn that extendscript-ui exports!
  }
  // ...any other options
}

Usage

Be sure to use .tsx files for JSX syntax highlighting. Import jsx to satisfy TypeScript and for code completion:

// index.tsx
import { jsx } from "extendscript-ui";

export const ui = (
  <dialog text="Neat!" properties={{ closeButton: true }}>
    <button text="Click me!" onClick={() => alert("Doink!")} />
  </dialog>
);

Use renderSpec to render your template. This will create a Window and wire up your onClick events. It will then return an object with your Window as well as a cleanup fn:

import { renderSpec } from "extendscript-ui";

const { window, destroy } = renderSpec(ui);
window.show();

[!WARNING] The renderSpec API might evolve, but it's functional for now...

How?

extendscript-ui uses a custom jsxFactory to transform JSX into a ScriptUI Resource Specifications-compliant string. This string is passed to new Window(specString) to build the UI. Once the UI is built, renderSpec adds any event handlers to the created UI elements.

TODO

  • [ ] Test/add more ScriptUI functionality beyond onClick...
  • [ ] More type safety:
    • [ ] renderSpec should only accept specString with a root of type Window
    • [ ] remove type attribute since it's defined by tag (generally, make sure all attrs are cleaned up)
  • [ ] Figure out TreeView | ListBox | DropDownList rendering
  • [ ] Default text nodes to <static-text/>? e.g <button>hello!</button> === <button text="hello!"/>
  • [ ] ProgressBar helpers, etc?
  • [ ] Look up how to auto import jsx, though this may just be documentation/guidance rather than a feature as it will probably depend on user's build setup?
  • [ ] Likely other things I've not thought of...