Bolt UXP

repository·master·Indexed 41 days ago

https://github.com/hyperbrew/bolt-uxp

A high-performance boilerplate for building Adobe UXP plugins using modern web technologies like Svelte, React, or Vue, powered by Vite, TypeScript, and Sass. It includes bolt-uxp-utils for Premiere Pro (26.3.0+) and Photoshop, supports Webview UI for full CSS/HTML/JS DOM support, and provides tools for multi-window panel configuration and CCX packaging.

Tokens
17.9K
Snippets
61
Records
83
Agent score
52%

What's inside Bolt UXP

  1. Understand the Bolt UXP ecosystem components

    master

    Bolt UXP is composed of three primary packages that work together to facilitate UXP plugin development:

    • bolt-uxp: The core package and template source used by the CLI tool.
    • create-bolt-uxp: A CLI tool used to scaffold new projects based on the bolt-uxp templates.
    • vite-uxp-plugin: A Vite plugin that provides the necessary build features and environment for developing UXP plugins.
  2. How Bolt UXP templating works

    master

    The project uses a templating system to generate framework-specific (React, Vue, Svelte) and app-specific (Photoshop, InDesign, etc.) projects.

    Package Generation: For a selected framework, the file package.framework.jsonc is copied and renamed to package.json in the project root (e.g., package.react.json becomes package.json).

    Code Stripping via Comments: The templating engine removes code blocks based on specific comment markers if the selected framework, app, or feature does not match.

    Marker Types:

    • Variable Blocks (Included/Excluded): Content between // BOLT_VARIABLE_START and // BOLT_VARIABLE_END (or HTML/JSX equivalents) is removed if the variable doesn't match.
    • Conditional Only (Removed): Code following // BOLT_VARIABLE_ONLY is removed if the variable doesn't match.

    Note: Replace VARIABLE with the specific identifier, such as // BOLT_REACT_ONLY or // BOLT_PHXS_ONLY.

  3. Use the Webview UI option

    master

    The Webview UI option allows you to build your user interface using full CSS/HTML/JS DOM support (Edge on Windows, Safari on MacOS).

    Important Requirements:

    • The Webview UI option must be enabled during the create bolt-uxp project setup.
    • Enabling this creates two separate contexts:
      • UI Context: Located in webview-ui/*
      • UXP Backend Context: Located in src/*

    Communication Rules:

    • Because the contexts are separate, you can only return primitive types (strings, numbers, booleans, arrays, static objects) across the bridge. Returning object instances or references will fail.
    • All exported functions in your uxp and app files are automatically exposed to the Webview.

    Debugging:

    • UXP Context: Use Adobe UXP Developer Tools.
    • Webview UI Context: Use webview devtools (Right-click > "Inspect" on the UI).
  4. Use a Webview to get full browser UI in UXP

    master

    You can build a UXP panel where the entire UI is contained within a Webview. This approach creates two separate contexts:

    1. Webview Frontend: Uses standard CSS/HTML/JS features available in the host OS browser (Edge on Windows, Safari on MacOS).
    2. UXP Backend: The standard UXP environment.

    Requirements:

    • Requires a separate build system for the frontend.
    • If you are not hosting the backend with a Hybrid Plugin, you must build the frontend to a single HTML file.
  5. Use Spectrum components in Bolt UXP

    master

    Bolt UXP does not come with a pre-configured Spectrum integration, but you can add it manually.

    Spectrum UXP (Native Widgets)

    You can use native Spectrum UXP widgets directly. To avoid TypeScript errors when using custom elements, add declarations to your globals.d.ts file.

    Example for React:

    declare global {
      namespace JSX {
        interface IntrinsicElements {
          "sp-heading": React.DetailedHTMLProps<
            React.HTMLAttributes<HTMLElement>,
            HTMLElement
          >;
        }
      }
    }

    Spectrum Web Components

    To use Spectrum Web Components, install the package from npm and import the components as needed: npm install @spectrum-web-components/bundle

  6. Handle global errors in UXP with Bolt UXP polyfills

    master

    Since Adobe UXP lacks a global error handler, Bolt UXP provides polyfills to catch and track unhandled errors, which is useful for integrating services like Sentry.

    1. Initialize the Global Error Handler

    Use polyFillGlobalErrorHandler() to intercept errors. This should be called once during initialization.

    import { polyFillGlobalErrorHandler } from 'src/api/errors';
    
    export const initUXP = () => {
      polyFillGlobalErrorHandler((error: Error) => {
        // Example: sendToSentry(error);
      });
    };

    2. Use Safe Wrappers

    To handle errors locally while still reporting them to the global handler, use safe() for synchronous code and safeAsync() for asynchronous code. These return the result or an Error instance.

    Synchronous:

    const res = safe(() => window.notExist());
    if (res instanceof Error) {
      // handle error in-context
    }

    Asynchronous:

    const res = await safeAsync(async () => window.notExist());
    if (res instanceof Error) {
      // handle error in-context
    }
    // Sync Example
    const res = safe(() => window.notExist()); // error is sent to global error handler
    if (res instanceof Error) {
      return console.log("there was an error"); // also handle error in-context
    }
    console.log("all good");
    
    // Async Example
    const res = await safeAsync(async () => window.notExist()); // error is sent to global error handler
    if (res instanceof Error) {
      return console.log("there was an error"); // also handle error in-context
    }
    console.log("all good");
  7. Configure Webview UI for Multi-Panel plugins

    master

    When using Webview mode with multiple panels:

    1. Follow the standard multi-window setup in uxp.config.ts and add <uxp-panel /> elements.
    2. Ensure webviewInitHost({ multi: true }) is enabled in your UXP code.
    3. Accessing specific panel APIs: Deconstruct the webviewAPIs array in the order the panels are listed in uxp.config.ts.
    4. Conditional Rendering: In your Webview UI code, use the page variable from initWebview() to determine which panel is currently rendering (e.g., 'main' or 'settings').
    // Accessing specific APIs in UXP
    const [mainWebviewAPI, settingsWebviewAPI] = webviewAPIs;
    mainWebviewAPI.doThisFunction();
    settingsWebviewAPI.doThatFunction();
    
    // Conditional rendering in Webview UI
    import { initWebview } from "./webview-setup";
    const { api, page } = initWebview(webviewAPI);
    // page will be e.g. 'main' | 'settings'
  8. Configure and use Adobe UXP Developer Tools (UDT) for development

    master

    Bolt UXP is designed to work with the Adobe UXP Developer Tool (UDT).

    1. Setup UDT

    • Ensure Developer Mode is enabled in your host app (e.g., Photoshop) via Preferences > Plugins > Enable Developer Mode.
    • Open UDT (version 2.0 or later).
    • Click Add Plugin and select the manifest.json file located in your project's dist folder.

    2. Load and Debug

    • Do not use the 'Load and Watch' feature in UDT. Bolt UXP uses its own built-in WebSocket system for more reliable hot reloading.
    • Click the Load button on your plugin item in UDT.
    • Click the Debug button to open the Dev Tools.

    3. Troubleshooting

    If you switch debuggers (e.g., from UDT to VS Code), you must unload the plugin from UDT and re-run your build command before starting the new debugger.

  9. Quick Start with Bolt UXP

    master

    To create and run a new Adobe UXP plugin using Bolt UXP, follow these steps using your preferred package manager (npm, yarn, or pnpm):

    1. Create the project: Run the creation command and follow the CLI prompts.
    2. Navigate to the project: cd <project-name>
    3. Install dependencies: Run the install command for your package manager.
    4. Install Webview dependencies (Required if using Webview UI only):
      • cd webview-ui && <install-command> && cd ..
    5. Build the plugin: You must run a build before running in development mode.
    6. Run in hot reload mode: Use the dev command to start development with UDT.
    7. Package for distribution: Use the ccx command to generate CCX files for different hosts.
    8. Zip assets: Use the zip command to bundle CCX files and specified assets into a ./zip folder.
    # Using npm
    npx create-bolt-uxp
    cd project
    npm i
    cd webview-ui && npm i && cd ..
    npm run build
    npm run dev
    npm run ccx
    npm run zip
    
    # Using yarn
    yarn create bolt-uxp
    cd project
    yarn
    cd webview-ui && yarn && cd ..
    yarn build
    yarn dev
    yarn ccx
    yarn zip
    
    # Using pnpm
    pnpm create bolt-uxp
    cd project
    pnpm i
    cd webview-ui && pnpm i && cd ..
    pnpm build
    pnpm dev
    pnpm ccx
    pnpm zip
  10. Install bolt-uxp-utils with a bundler (Path A)

    master

    If your project uses a bundler like Bolt UXP, Vite, Webpack, or esbuild, install the package via npm.

    If you are starting a project from scratch (not using Bolt UXP), you must also manually install the required Adobe UXP type packages to ensure proper type checking and autocomplete.

    Note: If you encounter installation issues with yarn due to the @adobe/premierepro engine constraints, use yarn install --ignore-engines. npm handles this automatically.

    # For projects with a bundler
    npm install bolt-uxp-utils
    
    # For projects starting from scratch
    npm install --save-dev @adobe/cc-ext-uxp-types @adobe/premierepro @types/photoshop
  11. Develop core Bolt UXP templates

    master

    If you are contributing to the core templates of Bolt UXP, follow these steps to set up your local development environment:

    1. Clone the repository.
    2. Install dependencies using yarn:
      yarn
    3. Start the development server:
       ```bash
    yarn dev

    To test support for different frameworks (React, Vue, Svelte), modify index.html by enabling the corresponding <script /> tag and disabling the others.

    yarn
    yarn dev
  12. Build and debug Hybrid Plugins on macOS

    master

    Hybrid Plugins require platform-specific compilation. For macOS, use Xcode to build universal binaries (arm64 and x64).

    Build Commands

    • yarn mac-build: Build the hybrid plugin in standard release mode.
    • yarn mac-build-debug: Build the hybrid plugin in debug mode.
    • yarn mac-sign: Sign and notarize the hybrid plugin.
    • yarn build: Build the full project, including copying hybrid files to the distribution folders.

    Debugging in Xcode

    To debug a Photoshop Hybrid Plugin, you must create a developer version of Photoshop with specific entitlements:

    1. Copy the Photoshop application to a -dev.app name.
    2. Extract entitlements using codesign -d --entitlements :- '/Applications/Adobe Photoshop 2026/Adobe Photoshop 2026.app' > entitlements.xml.
    3. Add <key>com.apple.security.get-task-allow</key> <true/> to the XML.
    4. Re-sign the dev app using sudo codesign --force --deep --options runtime --entitlements '/Applications/Adobe Photoshop 2026/entitlements.xml' --sign "Developer ID Application: NAME_OF_COMPANY_CERT" "/Applications/Adobe Photoshop 2026/Adobe Photoshop 2026-dev.app".
    5. In Xcode, use Debug > Attach to Process > Adobe Photoshop 2026.

    Note: Always use yarn mac-build for final release binaries.