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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@itwin/unified-selection

v1.7.1

Published

Package for managing unified selection in iTwin.js applications.

Readme

@itwin/unified-selection

Copyright © Bentley Systems, Incorporated. All rights reserved. See LICENSE.md for license terms and full copyright notice.

The purpose of the @itwin/unified-selection package and unified selection in general is to act as a single source of truth of what is selected in an iTwin.js application.

Concepts

The API consists of a few very basic concepts:

  • A Selectable is something that can be selected and is associated with an EC instance. There are 2 types of selectables:

    • SelectableInstanceKey uniquely identifies a single EC instance through a full class name and ECInstanceId.
    • CustomSelectable is identified by an arbitrary identifier string and knows how to get any number of SelectableInstanceKey associated with it.
  • Selectables is a container for multiple Selectable instances. The container is structured in a way that allows to quickly find specific selectables by their identifier.

  • SelectionStorage is an interface that manages Selectables for different iModels. It allows:

    • Changing the selection (add, remove, replace, clear).
    • Get active selection.
    • Listen to selection changes.

    The package delivers the createStorage() function to create an instance of SelectionStorage. Consumers are also expected to call SelectionStorage.clearStorage whenever an iModel is closed to free up memory.

Usage example

import { IModelConnection } from "@itwin/core-frontend";
import { createIModelKey } from "@itwin/presentation-core-interop";
import { createStorage, Selectables } from "@itwin/unified-selection";

// Create a global selection store (generally, somewhere in main.ts or similar). This store
// must be shared across all the application's components to ensure unified selection experience.
const unifiedSelection = createStorage();

// The store should to be cleaned up when iModels are closed to free up memory, e.g.:
IModelConnection.onClose.addListener((iModelConnection) => {
  unifiedSelection.clearStorage({ imodelKey: createIModelKey(iModelConnection) });
});

// A demo selection listener logs selection changes to the console:
unifiedSelection.selectionChangeEvent.addListener(({ imodelKey, source, changeType, selectables }) => {
  const suffix = `in ${imodelKey} iModel from ${source} component`;
  const numSelectables = Selectables.size(selectables);
  switch (changeType) {
    case "add":
      console.log(`Added ${numSelectables} items to selection ${suffix}.`);
      break;
    case "remove":
      console.log(`Removed ${numSelectables} items from selection ${suffix}.`);
      break;
    case "replace":
      console.log(`Replaced selection with ${numSelectables} items ${suffix}.`);
      break;
    case "clear":
      console.log(`Cleared selection ${suffix}.`);
      break;
  }
});

// An interactive component that allows selecting elements, representing something in an iModel, may want to
// add that something to unified selection. For example:
const elementKey = { className: "BisCore.PhysicalElement", id: "0x1" };
unifiedSelection.addToSelection({
  imodelKey: createIModelKey(imodel),
  source: "MyComponent",
  selectables: [elementKey],
});

Learning

Are you migrating from SelectionManager in @itwin/presentation-frontend? Check out our Migrating from SelectionManager learning page!

Below is a list of learning material related integrating unified selection into your components:

Do you think something is missing in the above list? Let us know by creating an issue!