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

@vcmap/swipe-tool

v1.0.12

Published

A VC Map plugin to swipe split views.

Downloads

307

Readme

@vcmap/swipe-tool

Part of the VC Map Project

The swipe tool can be used to compare different states within the VC Map. It provides a simple split view with predefined split states or an extended view with a TreeView of SplitLayers. Its activation button is located within the toolbar.

Simple vs. Extended Swipe Tool

Depending on its configuration the behaviour of the swipe tool button differs.

a) Simple Swipe Tool

If showSwipeTree is configured to false, the button shows on activation the Swipe Controller and applies the configured swipeLayerStates. Moving the Swipe Controller a user can interactively compare two predefined states of an object or scene. Clicking the tool button again, hides the Swipe Controller and resets the original state.

b) Extended Swipe Tool with Swipe TreeView Window

Per default, on activation a Window with a swipe tree opens, where the user can interactively apply states on available layers. The swipe tree is derived from the content tree mapping the structure and items to SwipeTreeItems with two actions:

  • split left, to show or hide the layer on the left side
  • split right, to show or hide the layer on the right side

The Swipe Tool window offers additional header actions to hide the Swipe Controller, deactivate and reactivated the Swipe Tool and to view help. Clicking the Swipe Tool button in active state, closes the window. It doesn't deactivate the tool, though!

To make layers accessible within the swipe tree you have to add those layers to the content tree!

Configuration

The SwipeToolConfig contains the following options:

| property | type | default | description | | ------------------ | --------------------------------------------- | --------- | ---------------------------------------------------------------------------------------------------------- | | showSwipeTree | boolean | true | Whether Swipe Tree is shown on tool activation. | | showSwipeElement | boolean | true | Whether to show or hide Swipe Controller on activation. | | splitPosition | number | 0.5 | Default Position of the Swipe Element. A number between 0 and 1, where 0.5 corresponds to center position. | | swipeElementTitles | Object<string,string>|undefined | undefined | An object with keys 'left' and 'right' containing titles. | | swipeLayerStates | Object<string,LayerSwipeState|undefined> | undefined | An object with layer name as key and state of SplitLayers as value. |

A LayerSwipeState can be defined. This state is applied on first activation of the tool. If no values are provided or after deactivation and reactivation the current state of the layers are used.

The configuration is done with the following options:

| property | type | description | | -------------- | ------- | --------------------------------------------------------------------------------------- | | splitDirection | string | The split direction of the layer. Either 'left' or 'right', if omitted none is applied. | | active | boolean | The active state of the layer. Must be true for split direction 'left' or 'right'. |

A config entry could for example look like:

{
  "name": "@vcmap/swipe-tool",
  "showSwipeTree": true,
  "showSwipeElement": true,
  "swipeLayerStates": {
    "Openstreetmap OSM Cache": {
      "active": true,
      "splitDirection": "right"
    }
  },
  "swipeElementTitles": {
    "left": "Left",
    "right": "Right"
  }
}

API

The Swipe Tool plugin can be accessed via the VcsUiApp. It's provided on the plugin by a getter:

const { swipeTool } = vcsUiApp.plugins.getByKey('@vcmap/swipe-tool');

Activation and deactivation

To activate the swipeTool via API call:

swipeTool.activate();

To deactivate the swipeTool via API call:

swipeTool.deactivate();

Change configuration (tree view, titles)

To toggle whether the tree view is shown or not use:

swipeTool.showSwipeTree = true; // or false

The setter will trigger a new setup of the swipe tool actions.

To update the swipeElementTitles use:

swipeTool.swipeElementTitles = {
  left: 'My new left title',
  right: 'My new right title',
};

Adding or removing swipe layers

To add a layer to the swipe tree, you have to add a LayerContentTreeItem to the content tree collection. The swipe tree is automatically derived from the content tree and will be updated each time, the content tree changes.

Swipe Tool State

The swipe tool has to private properties for state:

  • _initialState is cached on activation and applied on deactivation.
  • _cachedState is the tool's internal state. It is updated on deactivation or whenever setState is called.

Methods to work with the state:

getState

const currentState = swipeTool.getState();

Iterates over content tree collection and returns current SwipeLayerState for all layers of LayerContentTreeItem and LayerGroupContentTreeItem.

setState

swipeTool.setState({ layerName: { active: true, splitDirection: -1 } });

Sets a new state and applies it, if the tool is active.

applyState

swipeTool.applyState({ layerName: { active: true, splitDirection: -1 } });

Applies the provided state to all referenced layers, if the tool is active.

clear

swipeTool.clear();

Clearing the swipe tool removes all items from the tree view, if present, and resets the initial swipe state on all swipe layers. It also clears cached states of _cachedState and _initialState.