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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@orne/jqueryui-ts-widgets

v0.1.0

Published

JQueryUI widgets typescript types and Widget decorator

Readme

Typescript JQueryUI types and utilities

Provides Typescript types for jQuery UI modules and widgets.

Also provides a decorator for creating new jQuery UI as vanilla TS classes.

Preliminary warning

This package is the result of some unavoidable requirements of a private project.

jQuery UI seems pretty dead and lacks (and have lack for years) support for modern JS development tools including (but not limited to) source maps of minimized files or ESM/CommonJS modules support, witch prevent usage of tools like Vite.

It provided a valuable UI framework for years. Nowadays has been superseeded by more modern tools and approaches.

My opinion right now (2025-01) is this:

Get rid of jQuery UI and/or jQuery and adopt modern tools and frameworks when Web API is not enought.

jQuery UI Typescript types

Add development dependency with @orne/jqueryui-ts-widgets to have typed imports of jQuery UI packages and modules.

jQuery UI widgets as classes

To define new jQuery UI widgets as classes Typescript experimental support for decorators must be enabled:

{
    "compilerOptions": {
      ...
      "experimentalDecorators": true,
      ...
    }
}

Once decorators are enabled jQuery UI widgets can be defined using Typescript classes:

import 'jquery-ui/ui/widget';
import { JQueryWidget } from '@orne/jqueryui-ts-widgets';

/**
 * Interface of widget styling classes.
 */
export type Classes = object & {
    // Extra widget styling classes
    "myns-mywidget-fancyclass"?: string | null;
}
/**
 * Interface of widget options.
 *
 * @typeParam C The widget classes.
 */
export interface Options<C extends Classes = Classes>
extends JQueryUI.Widget.Options<C> {
    // Extra widget options
    myTypedOption: boolean;
}
/**
 * Interface of widget API.
 *
 * @typeParam This The JQuery instance.
 */
export type API<This extends JQuery<any>> =
    JQueryUI.Widget.API<This, MyWidget> &
    JQueryUI.Widget.API.Methods<This, MyWidget> &
    {
      /**
       * Public widget method.
       */
      (methodName: 'myMethod'): This,
    };
/**
 * The widget class.
 * Note the `@JQueryWidget` decorator with namespace and widget name.
 *
 * @typeParam O The widget options.
 */
@JQueryWidget({ namespace: 'myNs', name: "myWidget" })
export class MyWidget<O extends Options<any> = Options>
extends Widget<O> {
    public constructor(options?: Partial<O>, element?: JQuery<any>) {
      super(options, element);
    }
    protected _init(): void {
      super._init();
    }
    /**
     * Public widget method.
     */
    public myMethod(): void {
    }
}
declare global {
  interface JQuery<TElement = HTMLElement> {
    myWidget: API<this>;
  }
  interface JQueryStatic {
    myNs: {
      myWidget: typeof MyWidget;
    };
  }
}

Widget API declaration can be ommited and extracted from widget type declaration, using JQueryUI.Widget.API.From. However, this shortcut losts public method's documentation.

import 'jquery-ui/ui/widget';
import { JQueryWidget } from '@orne/jqueryui-ts-widgets';

/**
 * Interface of widget styling classes.
 */
export type Classes = object & {
    // Extra widget styling classes
    "myns-mywidget-fancyclass"?: string | null;
}
/**
 * Interface of widget options.
 *
 * @typeParam C The widget classes.
 */
export interface Options<C extends Classes = Classes>
extends JQueryUI.Widget.Options<C> {
    // Extra widget options
    myTypedOption: boolean;
}
/**
 * The widget class.
 * Note the `@JQueryWidget` decorator with namespace and widget name.
 *
 * @typeParam O The widget options.
 */
@JQueryWidget({ namespace: 'myNs', name: "myWidget" })
export class MyWidget<O extends Options<any> = Options>
extends Widget<O> {
    public constructor(options?: Partial<O>, element?: JQuery<any>) {
      super(options, element);
    }
    protected _init(): void {
      super._init();
    }
    /**
     * Public widget method.
     */
    public myMethod(): void {
    }
}
declare global {
  interface JQuery<TElement = HTMLElement> {
    myWidget: JQueryUI.Widget.API.From<this, MyWidget>;
  }
  interface JQueryStatic {
    myNs: {
      myWidget: typeof MyWidget;
    };
  }
}

Events

To declare events triggered by widgets define the event type specifying the full event name and add it to the JQueryUI.Widget.Event.Mappings interface. This will automatically add signatures to JQuery.on() and JQuery.one() for the defined event type:

export type MyEvent<TElement = HTMLElement> = JQueryUI.Widget.Event<"myFancyEvent", TElement>;
declare namespace JQueryUI {
    namespace Widget {
        namespace Event {
            interface Mappings<TElement = HTMLElement> {
                'myFancyEvent': MyEvent<TElement>;
            }
        }
    }
}

JQuery UI widgets allow triggering events with data associated to the event. To provide data type information to event consumers add to the JQueryUI.Widget.Event.Mappings interface a definition including event type and event data type:

export type MyEvent<TElement = HTMLElement> = JQueryUI.Widget.Event<"myFancyEvent", TElement>;
export interface MyEventData {
  ...
  test: boolean;
}
interface MyEventDef<TElement = HTMLElement> {
  event: MyEvent<TElement>,
  ui: MyEventData
}
declare namespace JQueryUI {
    namespace Widget {
        namespace Event {
            interface Mappings<TElement = HTMLElement> {
                'myFancyEvent': MyEventDef<TElement>;
            }
        }
    }
}

// Allows typed access to event data:
$('#my-elem').on('myFancyEvent', (event, data) => {
  // Typed data
  data.test == true
});

Existing widgets ambient types

To add typescript types for existing JQuery UI widgets add ambient widget namespace declaration and extend JQueryStatic interface with namespace:

/// <reference types="jquery" />
declare namespace AmbientWidgets {
  interface WidgetsNamespace {
  }
}
declare global {
  interface JQueryStatic {
    ambientNs: WidgetsNamespace;
  }
}

For each widget in the namespace add ambient module declaration for widget module, defining widget classes, options, widget API and, if required, events and extending JQuery interface as previously explained:

/// <reference types="jquery" />
/// <reference types="jquery-ui" />
/// <reference types="./namespace" />
export class AmbientWidget<O extends AmbientWidget.Options<any> = AmbientWidget.Options>
extends jQuery.Widget<O> {
  public someMethod(): void;
}
export namespace AmbientWidget {
  type Classes = object & {
    // Extra widget styling classes
    "myns-mywidget-fancyclass"?: string | null;
  }
  interface Options<C extends Classes = Classes>
  extends JQueryUI.Widget.Options<C> {
      // Extra widget options
      myTypedOption: boolean;
  }
}
declare namespace AmbientWidgets {
  interface WidgetsNamespace {
    ambientWidget: typeof AmbientWidget;
  }
}
interface JQuery<TElement = HTMLElement> {
  ambientwidget: JQueryUI.Widget.API.From<this, AmbientWidget>;
}
declare module 'fancylib/my-ambient-widget' {
  import 'jquery';
  import 'jquery-ui';
  // If module exports widget
  export default jQuery.ambientNs.ambientWidget;
}